在Ubuntu系统中配置PHP-FPM(FastCGI Process Manager)通常涉及以下几个步骤:
-
安装PHP-FPM: 首先,确保你的系统已经安装了PHP和PHP-FPM。你可以使用以下命令来安装它们:
sudo apt update sudo apt install php-fpm这将安装PHP以及PHP-FPM。
-
配置PHP-FPM: PHP-FPM的配置文件通常位于
/etc/php/{version}/fpm/目录下,其中{version}是你的PHP版本号。例如,如果你的PHP版本是7.4,配置文件将位于/etc/php/7.4/fpm/。主要的配置文件包括:
php-fpm.conf:主配置文件。www.conf:包含PHP-FPM与Web服务器通信的配置。
你可以编辑
www.conf文件来配置PHP-FPM监听的地址和端口。例如:sudo nano /etc/php/7.4/fpm/pool.d/www.conf找到
listen指令并修改为你想要的地址和端口。例如,如果你想让PHP-FPM监听Unix套接字,可以这样设置:listen = /run/php/php7.4-fpm.sock如果你想让PHP-FPM监听TCP端口,可以这样设置:
listen = 127.0.0.1:9000 -
配置Nginx或Apache: 根据你使用的Web服务器,你需要相应地配置它以使用PHP-FPM。
-
Nginx: 编辑Nginx的站点配置文件(通常位于
/etc/nginx/sites-available/目录下),添加或修改以下内容:server { listen 80; server_name example.com; 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:/run/php/php7.4-fpm.sock; # 或者使用127.0.0.1:9000 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }然后,重新加载Nginx配置:
sudo nginx -t sudo systemctl reload nginx -
Apache: 确保启用了
proxy_fcgi和setenvif模块:sudo a2enmod proxy_fcgi setenvif编辑Apache的站点配置文件(通常位于
/etc/apache2/sites-available/目录下),添加或修改以下内容::80 > ServerName example.com DocumentRoot /var/www/htmlOptions Indexes FollowSymLinks AllowOverride All Require all granted SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost" ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined 然后,重新加载Apache配置:
sudo systemctl reload apache2
-
-
启动和启用PHP-FPM服务: 确保PHP-FPM服务正在运行并设置为开机自启动:
sudo systemctl start php7.4-fpm sudo systemctl enable php7.4-fpm
通过以上步骤,你应该能够在Ubuntu系统中成功配置PHP-FPM。根据你的具体需求,可能还需要进行其他配置调整。
以上就是关于“Ubuntu中PHP-FPM如何配置”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm