Centos7源码安装php7

php7

php编译安装

yum -y install epel-release
yum -y install gcc gcc-c++ make ncurses curl argon2 openssl openssl-devel openldap openldap-devel bzip2 bzip2-devel zlib zlib-devel libxml2 libxml2-devel libcurl libcurl-devel libargon2 libargon2-devel libjpeg libjpeg-devel libpng libpng-devel libxslt libxslt-devel libicu libicu-devel libmemcached libmemcached-devel freetype freetype-devel gmp gmp-devel readline readline-devel glibc glibc-devel glib2 glib2-devel pcre pcre-devel xmlrpc-c xmlrpc-c-devel gdbm gdbm-devel db4 db4-devel libXpm libXpm-devel libX11 libX11-devel gd gd-devel expat expat-devel oniguruma oniguruma-devel libsodium libsodium-devel
useradd -s /sbin/nologin www
cd /usr/local/src
wget "https://www.php.net/distributions/php-7.4.2.tar.gz"
tar -zxvf php-7.4.2.tar.gz
cd php-7.4.2
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-libdir=lib64 --with-zlib-dir --with-zlib --with-iconv-dir --with-jpeg --with-freetype --with-curl --with-gettext --with-xsl --with-libxml --with-xmlrpc --with-ldap-sasl --with-kerberos --with-openssl --with-password-argon2 --with-pear --with-bz2 --with-mhash --with-sodium --without-sqlite3 --without-pdo-sqlite --enable-mysqlnd --enable-fpm --enable-gd --enable-ctype --enable-bcmath --enable-exif --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-ftp --enable-intl --disable-rpath --disable-fileinfo --disable-debug
make && make install
cp php.ini-production /usr/local/php/etc/php.ini

启动php-fpm

  1. 环境变量:
echo "export PATH=\$PATH:/usr/local/php/sbin:/usr/local/php/bin" >>/etc/profile && source /etc/profile
  1. 使用默认配置文件:
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
mv /usr/local/php/etc/php-fpm.d/www.conf.default  /usr/local/php/etc/php-fpm.d/www.conf
  1. 检查配置文件:php-fpm -t
  2. 使用systemctl管理php-fpm
cat >/usr/lib/systemd/system/php-fpm.service <<EOF
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm -R
[Install]
WantedBy=multi-user.target
EOF
systemctl enable php-fpm
systemctl start php-fpm
systemctl status php-fpm

"-R" 代表root用户启动,可以不加。如果加则需要把 /usr/local/php/etc/php-fpm.d/www.conf文件中的user和group均改为root(或者在主配置文件/usr/local/php/etc/php-fpm.conf中加入user=root和group=root这两行)

验证php-fpm的启动

  1. 进程 ps auxf | grep php-fpm
  2. 端口 netstat -tulnp | grep php-fpm