在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上的运行效率。每个应用程序都有其特点,因此在进行优化时,请根据具体情况进行调整。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: Ubuntu Swagger支持哪些API类型