在 Linux 中部署 PHP 命令主要有兩種方法:通過包管理器(如 apt 或 yum)或從源代碼編譯
sudo apt-get update
sudo apt-get install php
php -v
sudo apt-get install php-fpm
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
配置 Web 服務器以使用 PHP-FPM。這里以 Nginx 為例:
a. 安裝 Nginx:
sudo apt-get install nginx
b. 創建一個新的 Nginx 配置文件,例如 /etc/nginx/sites-available/yourdomain
,并添加以下內容:
server {
listen 80;
server_name yourdomain;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
}
c. 創建一個符號鏈接,將配置文件鏈接到 sites-enabled
目錄:
sudo ln -s /etc/nginx/sites-available/yourdomain /etc/nginx/sites-enabled/
d. 檢查 Nginx 配置文件的語法是否正確:
sudo nginx -t
e. 重啟 Nginx 服務以應用更改:
sudo systemctl restart nginx
現在,您已經在 Linux 中成功部署了 PHP 命令。您可以開始創建和運行 PHP 腳本了。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。