要提升Ubuntu上php-fpm的性能,可以采取以下措施:
sudo apt-get install php-fpm
/etc/php/{version}/fpm/php.ini
,根据需要进行配置,如内存限制和上传文件大小限制。pool.d/www.conf
文件中,可以调整以下参数来优化性能:
pm.max_children
:设置最大的子进程数量。pm.start_servers
:设置启动时的进程数量。pm.min_spare_servers
和 pm.max_spare_servers
:设置空闲进程的最小和最大数量。pm.max_requests
:设置每个子进程在被重新生成之前可以处理的请求数。php.ini
文件中启用并配置OPcache。zend_extension /usr/lib/php/{version}/extensions/no-debug-non-zts-{version}-opcache.so
opcache.enable 1
opcache.memory_consumption 64
opcache.max_accelerated_files 4000
opcache.revalidate_freq 2
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/{version}-fpm.sock;
}
}
systemctl status php{version}-fpm
命令检查PHP-FPM的状态。pm.max_children
、pm.start_servers
等。通过上述步骤,可以有效地提升Ubuntu上php-fpm的性能。根据具体需求和环境,可能还需要进行其他配置操作,如调整PHP-FPM的进程管理方式、设置PHP-FPM的资源限制等。