Skip to main content

centos7安装php运行环境:nginx+php+redis+ImageMagick

更新centos 7 yum源

yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

1.安装nginx服务

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install nginx

更改nginx用户与用户组

创建www系统用户

useradd www -s /sbin/nologin -M
vi /etc/nginx/nginx.conf

修改为:

user www www;

开机启动

systemctl enable nginx

重启服务

systemctl restart nginx

2.安装redis服务

yum install redis

systemctl enable redis
systemctl restart redis

3.安装ImageMagick服务

yum install ImageMagick ImageMagick-devel

4.安装php

yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

检查可安装的php版本

yum list | grep php-devel
yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

yum list --enablerepo=remi --enablerepo=remi-php73 | grep php

安装php5.6

yum install --enablerepo=remi --enablerepo=remi-php56 php php-devel php-fpm php-opcache php-pecl-apcu php-mbstring php-mcrypt php-pdo php-mysqlnd php-pecl-xhprof  php-pear php-xml php-bcmath php-process php-gd php-gd php-exif php-openssl php-pecl-xdebug

yum install --enablerepo=remi --enablerepo=remi-php56 php-redis
yum install --enablerepo=remi --enablerepo=remi-php56 php-imagick

安装php7.3

yum install --enablerepo=remi --enablerepo=remi-php73 php php-devel php-fpm php-opcache php-pecl-apcu php-mbstring php-mcrypt php-pdo php-mysqlnd php-pecl-xhprof  php-pear php-xml php-bcmath php-process php-gd php-gd php-exif php-openssl php-pecl-xdebug

yum install --enablerepo=remi --enablerepo=remi-php73 php-redis
yum install --enablerepo=remi --enablerepo=remi-php73 php-imagick

yum install --enablerepo=remi --enablerepo=remi-php73 php-zip

修改php执行用户

vi /etc/php-fpm.d/www.conf

修改为:

user = www
group = www

重启php-fpm

systemctl enable php-fpm
systemctl restart php-fpm