Previous: Build Lnamp Environment (iii)-source installation Apache2.4
first, Install the PHP7
1.yum Install the packages needed to compile PHP
Yum-y install libxml2 libxml2-devel curl-devel libpng-devel freetype-devel libmcrypt-devel libjpeg-devel
2. Create a PHP user group and user
Groupadd phpuseradd-r-g php-s/sbin/nologin-m PHP
3. Download the PHP source package and put the source package into The/usr/local/src/directory
Download Page: http://www.php.net/downloads.php
Php-7.0.13.tar.gz is used Here.
: http://cn2.php.net/distributions/php-7.0.13.tar.gz
4. Enter the Src/directory
cd/usr/local/src/
5. Unzip the source package
TAR-ZXF php-7.0.13.tar.gz
6. Enter the PHP source directory, compile and install (configuration parameters: http://php.net/manual/zh/configure.about.php)
CD php-7.0.13/./configure--prefix=/usr/local/php--with-mcrypt=/usr/include--with-apxs2=/usr/local/apache/bin/ apxs--with-config-file-path=/usr/local/php/etc--with-mysql-sock=/var/lib/mysql/mysql.sock--enable-fpm-- enable-ftp--enable-xml--enable-zip--enable-soap--enable-pcntl--enable-shmop--enable-bcmath--enable-shared-- enable-mysqlnd--enable-opcache--enable-session--enable-sockets--enable-sysvsem--enable-mbregex-- enable-mbstring--enable-gd-native-ttf--enable-inline-optimization--with-gd--with-curl--with-zlib--with-mhash-- with-iconv--with-xmlrpc--with-gettext--with-jpeg-dir--with-freetype-dir--with-fpm-user=nginx--with-fpm-group= nginx--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-openssl--without-gdbm--without-pear--disable-debug-- Disable-rpath--disable-fileinfomake && make Install
7. The source installation package has two php.ini-xxx files, one is the product mode, the other is the development mode. Select a change name to php.ini in the php/etc/directory, depending on your needs
Cp/usr/local/src/php-7.0.13/php.ini-development/usr/local/php/etc/php.ini
8. Modify PHP Directory permissions
Chown-r php:php/usr/local/php
9. Add the PHP command to the Environment variable, modify the profile file
Vim/etc/profile
10. Change to the following, save exit
Path=/usr/local/mysql/bin:/usr/local/php/bin: $PATH
11. Make the configuration in/etc/profile effective immediately
Source/etc/profile
second, Configure Apache Support PHP7
1. Modify the Apache configuration file httpd.conf
Vim/usr/local/apache/conf/httpd.conf
2. Locate the location below, add the red flag section, and save the exit
DirectoryIndex index.html index.php AddType application/x-compress. Zaddtype application/x-gzip. gz. tgzaddtype application/x-httpd-php. php. phtml
3. Restart Apache
Service httpd Restart
4. Add PHP files to the Apache web directory, such as/usr/local/apache/htdocs/phpinfo.php
<?phpphpinfo ();
Access urls, such as: http://192.168.8.9:8088/phpinfo.php
The page is displayed correctly, the configuration is successful
third, Configure Nginx Support PHP7
1. Configure PHP-FPM
Php-fpm.conf is the configuration file for the PHP-FPM process service
Www.conf This is an extended configuration file for the PHP-FPM process service
CD/USR/LOCAL/PHP/ETCMV Php-fpm.conf.default PHP-FPM.CONFMV Php-fpm.d/www.conf.default php-fpm.d/www.conf
2. Add the PHP-FPM service script to the Init.d/directory
cp/usr/local/src/php-7.0.13/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm
3. Add executable permissions for PHP-FPM
chmod +x/etc/init.d/php-fpm
4. Adding PHP-FPM to System services
Chkconfig--add PHP-FPM
5. Modify the default boot level for the service
Chkconfig PHP-FPM on
6. Start PHP-FPM
Service PHP-FPM Start
7. Modify Nginx configuration file nginx.conf
Vim/usr/local/nginx/conf/nginx.conf
8. Remove the previous # comment symbol, change the/script to $document_root, Save the exit
Location ~ \.php$ { root html; Fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include fastcgi_params;}
9. Restart Nginx
Service Nginx Restart
10. Add php files to the Nginx Web directory, such as/usr/local/nginx/html/phpinfo.php
<?phpphpinfo ();
Access urls, such as: http://192.168.8.9/phpinfo.php
The page is displayed correctly, the configuration is successful
Iv. Test PHP7 Operation MySQL
Add php files to the web directory, such as/usr/local/apache/htdocs/mysql.php or/usr/local/nginx/html/mysql.php
<?php$host = ' localhost '; $user = ' root '; $pass = ' root123 '; $database = ' mysql '; $sql = ' SELECT * from user LIMIT 1 ';/* connection M Ysqli*/try { $con = mysqli_connect ($host, $user, $pass, $database); $result = mysqli_query ($con, $sql); Get data $data = Mysqli_fetch_all ($result, mysqli_assoc); Print_r ($data); Release result set mysqli_free_result ($result); Mysqli_close ($con);} Catch (Exception $e) { print "mysqli Error:". $e->getmessage (). "<br/>";} echo "
Access urls, such as: http://192.168.8.9/mysql.php
The page is displayed correctly, the configuration is successful
PHP7 installation is complete!
Next: Build Lnamp Environment (v)-PHP7 source installation Redis and Redis expansion
Build Lnamp Environment (iv)-source installation PHP7