目前使用的阿里云服务器是通过阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS升级上来的,升级之后,一直没有开启PHP 7.0
的OpCache
。以前感觉性能还够用,最近发现有些卡顿现象,因此想到开启OpCache
。
开启命令如下(PHP-FPM
模式):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
$ sudo apt install php7.0-opcache $ sudo phpenmod opcache # PHP-FPM模式的配置文件 $ FILEPATH="/etc/php/7.0/fpm/php.ini" # Enable the opcache. $ SEARCH=";opcache.enable=0" $ REPLACE="opcache.enable=1" $ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH # Set the amount of memory we can use for caching. # The production server has oooooodles of RAM. $ SEARCH=";opcache.memory_consumption=64" $ REPLACE="opcache.memory_consumption=256" $ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH # increase the number of files to cache $ SEARCH=";opcache.max_accelerated_files=2000" $ REPLACE="opcache.max_accelerated_files=1000000" $ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH # Don't bother revalidating files for a long time because # they should never change. # Obviously you need to undo this in dev. $ SEARCH=";opcache.validate_timestamps=1" $ REPLACE="opcache.validate_timestamps=3000" $ sudo sed -i "s:$SEARCH:$REPLACE:" $FILEPATH #重启服务 $ sudo service php7.0-fpm restart |
网站响应速度有明显的飞跃。