Install PHP
PHP we can go to the official website to download, www.php.net.
The current mainstream version is 5.6 or 7.1, most companies still use 5.x. 7 is the last few years, the change is larger, the old version of the compatibility of 7 poor.
The
Php installation method is similar to MySQL and Apache.
First enter cd/usr/local/src/and download the PHP package.
[[email protected] src]# cd/usr/local/src
Then we download the package
[[email protected] Src]wget/HTTP/ Cn2.php.net/distributions/php-5.6.30.tar.gz
Then unzip the package just under
[[email protected] Src]tar zxf php-5.6.30.tar.gz
then we go into the php-5.6.30 directory and compile
[[email protected] SRC]CD php-5.6.30
Start compiling
./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
1.prefix=/usr/local/php is the installation directory of the software
2.--with-apxs2=/usr/local/apache2.4/bin/apxs This is an Apache tool, so that we do not have to manually interfere with him, he will automatically put the extension module in the Apache directory, and in his configuration file add a line, This will load it up when we apache-m, which is why we need to install Apache and then install PHP first. Here we will specify the path to the Apache tool.
3.--with-config-file-path=/usr/local/php/etc specifying the path to the configuration file
- --with-mysql=/usr/local/mysql specifying the path to MySQL
- --with-mysql=/usr/local/mysql
--with-pdo-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config
The above three types are MySQL drivers, because if you want PHP and MySQL to communicate with each other, then the first to compile a support for his module. The old version is--with-mysql=/usr/local/mysql. And the new version of 7 is used
--with-mysqli=/usr/local/mysql/bin/mysql_config
There may be some errors at compile time, we should carefully observe, if the hint is missing those libraries, we can go with yum install.
There is an error here, which is a hint that we are missing LIBXML2.
Configure:error:xml2-config not found. Please check your LIBXML2 installation.
Then we use Yum to install it.
Yum Install-y libxml2-devel
After the installation we continue to compile it, and then there is an error
Configure:error:Cannot find OpenSSL ' s <evp.h>
There will be a lot of errors in the future, we can install Libxx-devel directly yum.
A new error has occurred.
Configure:error:mcrypt.h not found. Please reinstall Libmcrypt.
When this error occurs, we need to install an extension source if we have not previously installed an extension source.
Yum Install-y epel-release
And then install Libmcrypt-devel.
Yum Install-y libmcrypt-devel
+--------------------------------------------------------------------+
| License: |
| This software was subject to the PHP License, available in this |
| Distribution in the file LICENSE. By continuing this installation |
| Process, you is bound by the terms of this License agreement. |
| If you don't agree with the terms of this license, you must abort |
| The installation process at this point. |
+--------------------------------------------------------------------+
Thank for using PHP.
Config.status:creating Php5.spec
Config.status:creating Main/build-defs.h
Config.status:creating scripts/phpize
Config.status:creating scripts/man1/phpize.1
Config.status:creating Scripts/php-config
Config.status:creating Scripts/man1/php-config.1
Config.status:creating SAPI/CLI/PHP.1
Config.status:creating SAPI/CGI/PHP-CGI.1
Config.status:creating Ext/phar/phar.1
Config.status:creating Ext/phar/phar.phar.1
Config.status:creating main/php_config.h
config.status:executing default Commands
When we see this, it means that our compilation is complete.
And then we take the next step
Make && make install
Then let's look at the PHP directory
[Email protected] php-5.6.30]# ls/usr/local/php
Bin etc include Lib Php
Its core binary files are in/usr/local/php/bin
[Email protected] php-5.6.30]# Ls/usr/local/php/bin
Pear peardev pecl Phar Phar.phar php php-cgi php-config phpize
PHP and Apache are connected to each other by libphp5.so. And the directory where he resides is
/usr/local/apache2.4/modules/libphp5.so This is the expansion module we want.
We can also list which modules are loaded by PHP
[Email protected] php-5.6.30]#/usr/local/php/bin/php-m
[PHP Modules]
bz2
Core
CType
Date
Dom
Ereg
Exif
FileInfo
Filter
Gd
Hash
Iconv (omitted below)
These are static.
We also check the module under Apache
[Email protected] php-5.6.30]#/usr/local/apache2.4/bin/httpd-m
Php5_module (Shared)
Found in the last line more than a php5_module, this means that PHP is a module in APACEH exist, and this module is very important, if not, then our Apache will not support PHP.
Then we copy the php.ini-production under the directory of the source bundle.
First go to the source package directory, and then find it in the directory Php.ini-production (used in the production environment), in this directory there is a file, php.ini-development (used in the development environment), we have to choose according to different needs of him, here we choose Php.ini-production
[email protected] php-5.6.30]# CP Php.ini-production/usr/local/php/etc/php.ini
Installing PHP7
Download PHP7
First go to the/USR/LOCAL/SRC directory
and download PHP7
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
Unzip after download
Tar zxf php-7.1.6.tar.bz2
Then go to CD php-7.1.6 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
Here we need to note that unlike PHP5, the path we define here is--prefix= /USR/LOCAL/PHP7/ETC, the configuration file is defined as--WITH-CONFIG-FILE-PATH=/USR/LOCAL/PHP7/ETC, and without the
--with-mysql=/usr/local/mysql, Because of the PHP7 in the paper.
What we need to note here is that a machine can install two PHP, but you have to specify it when Apache calls.
And then we'll take a look
[Email protected] php-7.1.6]# ls/usr/local/apache2.4/modules/
Libphp7.so libphp5.so
There's a libphp7.so in the catalogue.
And then I'm looking at Apache loaded modules
[Email protected] php-7.1.6]#/usr/local/apache2.4/bin/apachectl-m
Php5_module (Shared)
Php7_module (Shared)
In the last two lines, there is a php7_module (shared) module in addition to Php5_module (shared).
If you want to change the Apache call, simply modify the configuration file to
[Email protected] php-7.1.6]# vim/usr/local/apache2.4/conf/httpd.conf
And find these two files.
LoadModule Php5_module modules/libphp5.so
LoadModule Php7_module modules/libphp7.so
We choose what we want to use, and use the # number to comment out the other.
Finally in the copy file CP Php.ini-production/usr/local/php7/etc/php.ini can be
April 11 task, install PHP5, PHP7