要优化Ubuntu上的PHP运行速度,可以采取以下几种方法:
sudo apt-get install php-fpm命令安装PHP-FPM。/etc/php/7.x/fpm/pool.d/www.conf文件,调整以下参数以优化性能: pm.max_children:设置最大子进程数。pm.start_servers:设置启动时的服务器进程数。pm.min_spare_servers和pm.max_spare_servers:设置空闲服务器进程的最小和最大数量。pm.max_requests:设置每个子进程在重启前处理的请求数。sudo apt-get install php-opcache命令安装OPcache。php.ini文件中启用OPcache,并进行相应的设置,如:zend_extension=opcache.so opcache.enable=1 opcache.memory_consumption=64M opcache.max_accelerated_files=4000 opcache.revalidate_freq=2 重启PHP-FPM服务以使更改生效。memory_limit参数。max_execution_time参数以适应脚本运行需求。post_max_size、upload_max_filesize、max_input_vars、max_input_time等参数。php.ini中设置mysqli.allow_persistent = On和mysqli.max_persistent = 100(对于MySQLi)或pdo_mysql.default_socket(对于PDO)。/etc/apache2/apache2.conf或/etc/httpd/conf/httpd.conf文件,调整KeepAlive、MaxClients、StartServers、MinSpareServers、MaxSpareServers、MaxRequestWorkers等参数。/etc/nginx/nginx.conf或/etc/nginx/sites-available/default文件,调整worker_processes、worker_connections、keepalive_timeout、client_max_body_size等参数。通过上述方法,可以显著提高Ubuntu上PHP的运行速度。请根据您的具体需求和资源调整这些优化措施,并定期监控性能以确保优化效果。