Installing PHP5
Download the source Package
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
Unzip the source package
tar -zxvf php-5.6.30.tar.gz
To compile (enter the directory after PHP decompression)
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
The following parameter meanings are:
--prefix Specifying the installation directory
--WITH-APXS2 is a tool for Apache automatic installation of expansion modules
--yith-config specify the path where the configuration file is located, PHP configuration file is called PHP.ini and MySQL is not the same
--with-mysql specifying the path to MySQL
The following pdo-mysql and Mysqli and MySQL are all MySQL drivers or specify its library, if you want to PHP and MySQL communication first to compile a module to support it,
Then there are some modules that are required to specify PHP.
--with-libxml-dir \
--WITH-GD \
--with-jpeg-dir \
--with-png-dir\
--with-freetype-dir\
--with-iconv-dir \
--with-zlib-dir \
--WITH-BZ2 \
--with-openss\
--with-mcrypt \
--ENABLE-SOAP \
--ENABLE-GD-NATIVE-TTF \
--enable-mbstring\
--enable-sockets\
--enable-exif\
Because our server is the first time to install PHP initialization process may encounter errors, is generally missing some libraries, the following error is missing XML2 related packages
Let's start with yum list |grep xml2
a look at the packages we need to install.
Here we need to install the Libxml2-devel package, yum installation (if you do not know which package to install a test, and then write down, this is the experience of judgment)
yum install -y libxml2-devel
After installation, then configure initialization.
The following error is missing OPENSSL-DEVL
yum inatall -y openssl-devel
Installing the Openssl-devel Package
The following error is missing Bzip2-devel package
yum install -y bzip2-devel
Installing the Bzip2-devel Package
The following error is missing Libjpeg-devel package
yum install -y libjpeg-devel
Installing the Libjpeg-devel Package
The following error is missing Libpng-devel package
yum install -y libpng-devel
Installing the Libpng-devel Package
The following error is missing Freetype-devel package
yum install -y freetype-devel
Installing the Freetype-devel Package
The following error is missing Libmcrypt-devel package
If Epel is not installed, we need to install the Epel extension source first
yum install -y epel-release
yum install -y libmcrypt-devel
Installing the Libmcrypt-devel Package
After installation, we will compile and install PHP
If you see the content, it proves that configure is a successful step.
Then make, finish and make install. or use it directly (make && make install)
make && make install
Then put the configuration file in the/usr/local/php/etc/directory renamed php.ini to complete the
cp php.ini-production /usr/local/php/etc/php.ini
Then we can take a look at its directory
ls /usr/local/php/
Where its core files are: Bin and bin/php
There are also the following files, he is a combination of Apache and PHP extension module
du -sh /usr/local/php/bin/php
View PHP-loaded modules (all static modules)
/usr/local/php/bin/php -m
View PHP Information
/usr/local/php/bin/php -i
PHP is an extension module that exists as a httpd and does not need to be started.
Installing PHP7
Download PHP7 's source package (enter SRC directory)
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
Unzip the source package
tar jxvf php-7.1.6.tar.bz2
PHP7 and PHP5.6 installation is basically the same, the only difference is that the parameters behind the Configure initialization are slightly different
Enter the extracted source package to compile
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
Nextmake && make install
Copy configuration file
cp php.ini-production /usr/local/php7/etc/php.ini
One machine installed PHP5 and PHP7 so which one to use?
You can edit the Apache configuration file to make a selection
vim /usr/local/apache2.4/conf/httpd.conf
Find the following line without commenting out which one
Installing PHP5 and PHP7