安装步骤
0、准备安装包
在PHP官网下载页面选择一个最新的稳定版,进入镜像地址列表页,选择服务器所在地域的镜像下载
cd /home wget http://am1.php.net/get/php-7.2.8.tar.gz/from/this/mirror -O ./php-7.2.8.tar.gz # 如果在境内建议使用wget http://cn2.php.net/get/php-7.2.8.tar.gz/from/this/mirror -O ./php-7.2.8.tar.gz tar -zxvf php-7.2.8.tar.gz
1、安装扩展包
yum install epel-release -y
2、更新系统内核
yum update
3、安装依赖组件
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
4、创建用户和组
/usr/sbin/groupadd www /usr/sbin/useradd www
5、设置变量
cp -frp /usr/lib64/libldap* /usr/lib/
6、生成编译文件
./configure --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-mysqlnd \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-mysqlnd-compression-support \ --with-iconv-dir \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-mbstring \ --enable-intl \ --with-mcrypt \ --with-libmbfl \ --enable-ftp \ --with-gd \ --enable-gd-jis-conv \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-zip \ --enable-soap \ --with-gettext \ --disable-fileinfo \ --enable-opcache \ --with-pear \ --enable-maintainer-zts \ --with-ldap=shared \ --without-gdbm \
7、编译并安装
make -j 4 && make install
# 有报错可以根据提示排查,一般是缺少依赖组件
8、创建配置文件
cd /home/php-7.2.8 cp php.ini-development /usr/local/php/etc/php.ini cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
9、创建初始化脚本
cp /home/php-7.2.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chown +x /etc/init.d/php-fpm
10、php-fpm服务管理
/etc/init.d/php-fpm status /etc/init.d/php-fpm start /etc/init.d/php-fpm reload /etc/init.d/php-fpm restart /etc/init.d/php-fpm stop
如果/etc/init.d/php-fpm start启动正常,通过ps -ef | grep php-fpm能看到运行中的进程,这表示php-fpm安装成功
11、加入开机自启动
chkconfig –add php-fpm
12、通过service服务来管理
service php-fpm status
service php-fpm start
service php-fpm reload
service php-fpm restart
service php-fpm stop
当然要让Nginx 和 PHP通信,还需要做一个参数配置和优化,参考下一篇文章。
另外针对Centos7.4php-fpm服务可以通过systemd来管理(可以事后在添加),配置如下:
0、新建php-fpm.service文件
touch /usr/lib/systemd/system/php-fpm.service
1、添加以下内容
[Unit] Description=The PHP FastCGI Process Manager After=syslog.target network.target [Service] Type=simple PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target
3、通过systemd来管理php-fpm服务
systemctl status php-fpm.service systemctl start php-fpm.service systemctl reload php-fpm.service systemctl restart php-fpm.service systemctl stop php-fpm.service
4、加入开机自启动
systemctl enable php-fpm.service