ubuntu 16.04系统上开启PHP7的OpCache

目前使用的阿里云服务器是通过阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS升级上来的,升级之后,一直没有开启PHP 7.0OpCache。以前感觉性能还够用,最近发现有些卡顿现象,因此想到开启OpCache

开启命令如下(PHP-FPM模式):

$ 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

网站响应速度有明显的飞跃。

参考链接