在Ubuntu上提升PHP運行效率可以通過多種方法實現,以下是一些關鍵的優化步驟:
sudo apt update
sudo apt install php-opcache
/etc/php/7.4/fpm/php.ini 文件(具體路徑可能因PHP版本而異),添加或修改以下配置:zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
sudo systemctl restart php7.4-fpm
sudo apt install php8.3-fpm
/etc/php/8.3/fpm/pool.d/www.conf 文件,調整以下參數:pm.max_children = 5
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 500
sudo systemctl restart php8.3-fpm
/etc/apache2/apache2.conf 或 /etc/httpd/conf/httpd.conf):KeepAlive On
MaxClients 500
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 500
/etc/nginx/nginx.conf 或 /etc/nginx/sites-available/default):worker_processes auto;
worker_connections 1024;
keepalive_timeout 65;
client_max_body_size 100m;
/etc/mysql/my.cnf 或 /etc/my.cnf):innodb_buffer_pool_size = 1G
max_connections = 500
query_cache_size = 64M
query_cache_type = 1
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
通過上述步驟,可以顯著提升PHP在Ubuntu上的運行效率。每個應用程序都有其特點,因此在進行優化時,請根據具體情況進行調整。