配置 nginx 運(yùn)行 php 的步驟包括:安裝 PHP、安裝 Nginx、編輯 Nginx 主配置文件添加 PHP 配置、創(chuàng)建 PHP 文件、重啟 Nginx、測試 PHP,成功后會顯示 “PHP is working!” 消息。
如何配置 Nginx 以運(yùn)行 PHP
步驟 1:安裝 PHP
在你的服務(wù)器上安裝 PHP,命令如下:
sudo apt-get install php7.4-fpm
步驟 2:安裝 Nginx
立即學(xué)習(xí)“PHP免費學(xué)習(xí)筆記(深入)”;
如果尚未安裝 Nginx,請使用以下命令:
sudo apt-get install nginx
步驟 3:配置 Nginx
編輯 Nginx 的主配置文件 /etc/nginx/nginx.conf,添加以下配置塊:
server { listen 80; server_name example.com; root /var/www/html; location ~ .php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
步驟 4:創(chuàng)建 PHP 文件
在 Nginx 的根目錄 (/var/www/html) 中,創(chuàng)建一個 PHP 文件,例如 index.php:
<?php echo "PHP is working!"; ?>
步驟 5:重啟 Nginx
重啟 Nginx 以應(yīng)用更改:
sudo systemctl restart nginx
步驟 6:測試 PHP
訪問你的網(wǎng)站(http://example.com),你應(yīng)該看到 “PHP is working!” 消息,表明 PHP 已成功與 Nginx 集成。
? 版權(quán)聲明
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載。
THE END
喜歡就支持一下吧
相關(guān)推薦