Yum Install wget
Download PHP source package in/usr/local/src directory
wget http://cn2.php.net/distributions/php-7.2.4.tar.gz
Unzip the source package
Tar zxvf php-7.2.1.tar.gz
Install the dependent packages needed to compile PHP:
Yum Install gcc autoconf gcc-c++
Yum install libxml2 libxml2-devel OpenSSL openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel LIBP ng libpng-devel freetype freetype-devel GMP gmp-devel readline readline-devel libxslt libxslt-devel
Yum Install Systemd-devel
Yum Install Openjpeg-devel
Add PHP-FPM User
Create a group
Groupadd PHP-FPM
Create a user, do not allow login and do not create home directory
Useradd-s/sbin/nologin-g php-fpm-m php-fpm
Compile parameters:
- Development environment:
- --enable-phpdbg\
- --enable-dtrace\
- Production environment:
- --disable-phpdbg\
- --disable-dtrace\
- ./configure \
- --prefix=/usr/local/php \
- --with-config-file-path=/usr/local/php/etc \
- --with-zlib-dir \
- --with-freetype-dir \
- --enable-mbstring \
- --with-libxml-dir=/usr \
- --enable-xmlreader \
- --enable-xmlwriter \
- --enable-soap \
- --enable-calendar \
- --with-curl \
- --with-zlib \
- --with-gd \
- --with-pdo-sqlite \
- --with-pdo-mysql \
- --with-mysqli \
- --with-mysql-sock \
- --enable-mysqlnd \
- --disable-rpath \
- --enable-inline-optimization \
- --with-bz2 \
- --with-zlib \
- --enable-sockets \
- --enable-sysvsem \
- --ENABLE-SYSVSHM \
- --enable-pcntl \
- --enable-mbregex \
- --enable-exif \
- --enable-bcmath \
- --with-mhash \
- --enable-zip \
- --with-pcre-regex \
- --with-jpeg-dir=/usr \
- --with-png-dir=/usr \
- --with-openssl \
- --enable-ftp \
- --with-kerberos \
- --with-gettext \
- --with-xmlrpc \
- --with-xsl \
- --enable-fpm \
- --with-fpm-user=php-fpm \
- --with-fpm-group=php-fpm \
- --with-fpm-systemd \
- --disable-fileinfo
To perform the compilation:
Make && make install
Php-ini:
There are configuration files in the source package:
Php.ini-development Test Development environment
Php.ini-production production Environment
Copy one to the specified directory (depending on your situation, you can compare the differences between the two files):
CP Php.ini-production/usr/local/php/etc/php.ini
PHP-FPM copy a new PHP-FPM configuration file:
Cd/usr/local/php/etc
CP Php-fpm.conf.default php-fpm.conf
Vim php-fpm.conf
Configuration error log:
Error_log =/usr/local/php/var/php-fpm.log
To configure the PID file:
PID =/usr/local/php/var/run/php-fpm.pid
Save exit
Cd/usr/local/php/etc/php-fpm.d
CP Www.conf.default www.conf
Manage PHP-FPM configuration:
cd/usr/local/src/php-7.2.4
CP./sapi/fpm/php-fpm.service to/usr/lib/systemd/system/
Configure Boot PHP-FPM:
Systemctl Enable PHP-FPM
Start PHP-FPM:
Systemctl Start PHP-FPM
View Status:
Systemctl Status PHP-FPM
To add an environment variable:
Vim/etc/profile
Append at end:
Export path= $PATH: '/usr/local/php/bin/'
Save exit.
Source/etc/profile
Test:
Php-v
See the following to show that it has been successful.
If you need to differentiate between the web and CLI environments, you can copy the/usr/local/php/etc/php.ini and rename it to Php-cli.ini
Cp/usr/local/php/etc/php.ini/usr/local/php/etc/php-cli.ini
You need to adjust the configuration to make adjustments in the respective configuration files.
Centos7 Compiling and installing PHP7.2