要提升Ubuntu上PHP的运行速度,可以采取以下几种方法:
sudo apt-get install php-opcache
/etc/php/7.x/fpm/php.ini
文件(根据你的PHP版本调整路径),取消以下行的注释或添加这些行:zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=64
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
opcache.validate_timestamps=0
opcache.fast_shutdown=1
sudo systemctl restart php7.x-fpm
sudo apt-get install 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
:设置空闲服务器进程的最小和最大数量。sudo systemctl start php7.x-fpm
sudo systemctl enable php7.x-fpm
eval()
函数、全局变量和多层循环。extension=apcu.so
apc.enable_cli=1
apc.shm_size=64
通过以上方法,你可以在Ubuntu上显著提升PHP的运行速度。每个应用程序都有其特点,因此在进行优化时,请根据你的具体情况进行调整。