CentOS7.4 编译安装 php7

阿里云 CentOS7.4 编译安装 PHP7.1.11

下载并解压源码包

tar zxf php-7.1.11.tar.gz
cd php-7.1.11
  1. 安装编译php所需的依赖包
yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu  libxslt libxslt-devel php-devel
  1. 进去源码目录配置 ./configure 信息
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql-sock --with-mysqli --with-libxml-dir --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-zlib --with-iconv --with-bz2 --with-curl --with-cdb --with-pcre-dir --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --with-gettext --with-gmp --with-mhash --with-libmbfl --with-onig --with-pdo-mysql --with-zlib-dir --with-readline --with-libxml-dir --with-xsl --with-pear --enable-fpm --enable-soap --enable-bcmath --enable-calendar --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-gd-native-ttf --enable-gd-jis-conv --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --enable-pdo --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --enable-mysqlnd-compression-support
  1. 编译 安装
make && make install
  1. 启动php-fpm
/usr/local/php/sbin/php-fpm

如果不知道启动命令在哪可以

find / -name php-fpm 
启动提示错误:
[09-Nov-2017 08:49:40] ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory (2)
[09-Nov-2017 08:49:40] ERROR: failed to load configuration file '/usr/local/php/etc/php-fpm.conf'
[09-Nov-2017 08:49:40] ERROR: FPM initialization failed

意思是 提示找不到 php-fpm.conf
到/usr/local/php/etc目录下 将php-fpm.conf.default 复制一份出来

cp php-fpm.conf.default php-fpm.conf

php-fpm.conf只是php的主配置文件 还要到php-fpm.d目录下将默认的www.conf.default也复制一份为www.conf

  1. 再次启动
/usr/local/php/sbin/php-fpm

无任何提示输出
查看是否运行成功

pstree -p | grep php
  1. 将php-fpm加入到system中管理
# 所有system的启动脚本都在此目录下
/usr/lib/systemd/system

创建php-fpm.service文件
文件内容如下

[Unit]
Description=php-fpm
After=network.target

[Service]
Type=forking
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/usr/bin/pkill -9 php-fpm
PrivateTmp=true

[Install]
WantedBy=multi-user.target

重载systemctl配置

systemctl daemon-reload

这样就可以使用systemctl命令管理php-fpm了
systemctl start php-fpm.service
systemctl stop php-fpm.service

你可能感兴趣的:(CentOS7.4 编译安装 php7)