Compile and install php 5.6 and centos5.6 in centos 7
1. Download the PHP installation package
wget http://php.net/distributions/php-5.6.31.tar.gz
By default, Nginx and PHP do not feel anything at all. After Apache + PHP is compiled, module files are generated, while Nginx + PHP requires PHP to generate executable files. Therefore, fastcgi technology must be used to integrate Nginx with PHP, you only need to enable FastCGI during installation. This time we install PHP not only use FastCGI, but also use the PHP-FPM such a stuff, PHP-FPM said White is a management FastCGI a manager, it exists as a PHP plug-in, to use PHP-FPM when installing PHP, you need to install the PHP-FPM in the form of a patch to PHP, and PHP to be consistent with the PHP-FPM version, this is necessary, remember!
2. Unzip and install
tar -zxvf php-5.6.31.tar.gzcd php-5.6.3./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-zlib-dir=/usr/local/zlib --with-mcrypt=/usr/local/libmcrypt --with-libxml-dir=/usr/local/libxml2/ --with-iconv-dir=/usr/local/libiconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring=all --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype --enable-shared --with-gd
The following error is reported during installation:
The gcc plug-in was not installed.
Continue installation:
yum install gcc
After the plug-in is installed, we will continue to install PHP
Finally, the following error is reported:
Libxml2 plug-in is not installed. Because my new centos system is installed, various dependent packages will be missing. Continue to install the libxml2 plug-in:
yum install libxml2
Tip:
Libxml2 already exists, possible libxml2-dev not installed, we install libxml2-devel
yum install libxml2-devel
After the installation, we continue to install PHP, and the prompt is:
We
We have installed the openssl plug-in.
yum install openssl openssl-devel
After the installation is complete, we will continue to execute the PHP installation and report the plug-in liburl.
Install liburl
yum -y install curl-devel
After installation, continue to execute PHP installation, and report that the GD library is not installed. We will continue to install the GD library.
yum install libjpeg libpng freetype libjpeg-devel libpng-devel freetype-devel -y
Continue to install PHP and report the missing plug-in libmcrypt
Centos fails to use yum to install libmcrypt. It can only be compiled and installed:
# Use wget to download wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz # unzip tar-zxvf libmcrypt-2.5.7.tar.gz # Enter directory cd libmcrypt-2.5.7 # compile (installed to/usr/local/lib/by default /). /configure -- prefix =/usr/local/libmcrypt # Run make & make install
After the installation is complete, continue to execute PHP installation. This time the installation is successful:
Compile and install:
make && make install
3. Configuration
Copy the php. ini-development in the source code to the PHP Directory and change it to PHP. ini.
cp php.ini-development /usr/local/php/etc/php.ini
Copy a php-fpm configuration file named php-fpm.conf (/usr/local/php/etc path)
cp php-fpm.conf.default php-fpm.conf
Start php-fpm
/usr/local/php/sbin/php-fpm
If it is too difficult to create a directory, you can set the php-fpm STARTUP script.
cp php-5.6.31/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
At startup, you only need to enter
# Start service php-fpm start # stop service php-fpm stop # Restart service php-fpm reload
4. Summary
It is not easy to compile and install a PHP file. Here is a summary:
To install PHP, you must install the following dependent packages in advance: gcc, libxml2, openssl, curl, and libmcrypt. But different environments may lead to different plug-ins missing, you can install them one by one as prompted.