Environment description
- CentOS 7 x64 4-core 2G memory built in VMware 12
- The http://blog.csdn.net/u014595668/article/details/50166277 installed MySQL5.7.9 is already installed in the environment
Tools download
Compilation environment: libmcrypt2.5.7 download, mhash-0.9.9.9 download, mcrypt-2.6.8 download
PHP installation package: PHP 7 Download
Use Xftp to upload all the tools to the/root/directory.
Create PHP users and user groups
Start by creating a user named PHP with no login rights and a user group named PHP
#######新建php用户和php组[root@localhost ~]# groupadd -r php && useradd -r -g php -s /bin/false -d /usr/local/php7 -M php
Compile the dependencies required to install PHP 7
Compile and install Libmcrypt, Mhash, mcrypt binary source package
The reason for compiling and installing libmcrypt here is that Yum installation looks like an error
##### #编译安装libmcrypt -2.5.7[root @localhost ~]# tar zxvf libmcrypt-2.5.7.tar.gz[root @localhost ~] # cd libmcrypt-2.5.7[root @localhost libmcrypt-2.5. 7] #./configure--prefix=/usr/local/related/libmcrypt[root@ localhost libmcrypt-2.5. 7]# make && make Install[root @localhost libmcrypt-< Span class= "Hljs-number" >2.5. 7] # cd ~[root @localhost ~]# RM-RF libmcrypt-2.5.7*
##### #编译安装mhash -0.9.9.9[root@localhost ~]# tar zxf mhash-0.9.9.9.tar.gz [root @localhost ~]# cd mhash-0.9.9.9[root @localhost mhash-0.< Span class= "Hljs-number" >9.9. 9] #./configure--prefix=/usr/local/related/mhash[root@ localhost mhash-0. 9.9.9]# make && make Install[root @localhost mhash-0. 9.9.9]# cd ~[root @localhost ~]< Span class= "hljs-comment" ># rm-rf mhash-0.9.9.9*
##### #编译安装mcrypt -2.6.8[root@localhost ~]# tar zxf mcrypt-2.6.8.tar.gz && CD mcrypt-2.6.8[root@localhost mcrypt-2.6.8]# Export Ld_library_path=/usr/local/related/libmcrypt/lib:/usr/local/related/mhash/lib[root@localhost mcrypt-2.6.8]# export ldflags= "-l/usr/local/related/mhash/lib-i/usr/local/related/mhash/include/" [Root @localhost mcrypt-2.6. 8]# export cflags= "-i/usr/local/related/mhash/include/" [Root @localhost mcrypt-2.6. 8]#./configure--prefix=/usr/local/related/mcrypt--with-libmcrypt-prefix=/usr/local/ Related/libmcrypt[root @localhost mcrypt-2.6.8]# make && make Install[root@ localhost mcrypt-2.6. 8]# cd ~[root @localhost ~]# RM- RF mcrypt-2.6.8*
######其他依赖yum安装[root@localhost ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel
Configuration of PHP 7 compilation parameters
Note that you must first remove the following backslash "\" After the comment text added!!!
##### #生成配置文件 [[email protected] ~]# TAR-ZXF php-7.0.0.tar.gz && cd php-7.0.0[[email protected] php-7.0.0]#./buil dconf--forceforcing buildconfremoving Configure cachesbuildconf:checking installation...buildconf:autoconf version 2.69 (OK) rebuilding configurerebuilding main/php_config.h.in##### #开始配置 [[email protected] php-7.0.0]#./configure--prefix=/usr/local/PHP7 \ [PHP7 installation root directory]--exec-prefix=/usr/local/PHP7--bindir=/usr/local/php7/bin--sbindir=/usr/local/php7/sbin--includedir=/usr/local/php7/include--libdir=/usr/local/php7/lib/php--mandir=/usr/local/php7/php/man--with-config-file-path=/usr/local/PHP7/ETC \ [PHP7 Configuration Directory---with-mysql-sock=/var/run/mysql/mysql.sock \ [PHP7 'sUnix socket Communication FILE---with-mcrypt=/usr/include--with-mhash--with-openssl--WITH-MYSQL=SHARED,MYSQLND \ [PHP7 dependent MySQL Library]--WITH-MYSQLI=SHARED,MYSQLND \ [PHP7 relies on MySQL library--WITH-PDO-MYSQL=SHARED,MYSQLND \ [PHP7 relies on MySQL library--WITH-GD--with-iconv--with-zlib--enable-zip--enable-inline-optimization--disable-debug--disable-rpath--enable-shared--enable-xml--enable-bcmath--ENABLE-SHMOP--enable-sysvsem--enable-mbregex--enable-mbstring--ENABLE-FTP--enable-gd-native-ttf--enable-pcntl--enable-sockets-< Span class= "Ruby" >-with-xmlrpc--enable-soap--without-pear- -with-gettext--enable-session \ [Allow PHP session Session]-- With-curl \ [Allow curl to extend]--with-jpeg-dir--with-freetype-dir- -enable-opcache \ [use Opcache cache]--enable-fpm-- enable-fastcgi--with-fpm-user=nginx \ [php-fpm user]--with-fpm-group=nginx \ [ PHP-FPM user group]--without-gdbm--with-mcrypt=/usr/ Local/related/libmcrypt \ [Specify Libmcrypt location]--disable-fileinfo
1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- Ten
- one
-
- 2
- (
- )
- +
- +
- /
- 0
-
- +
-
- all
- +
- +
- +
- -
- 29
-
- +
- +
- all
-
- +
- +
- PNS
- up
i>39
-
- 48
- all
-
-
- /
- /
- /
- /li>
-
-
- ,
- ,
- ,
- up-
- -
- +
- -
- +
- $
- [
]
- +
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21st
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
The result of executing the above configuration command is as follows:
Start compiling and installing PHP 7
[[email protected] php-7.0.0]# make clean && make && make install
PHP 7 compiled and installed successfully
Select step: Execute the Make Test command to test
This is a non-essential operation step that executes the make Test command
To view the PHP7 installation directory after a successful compilation
Due to the need to communicate with MySQL, you need to view the PHP7 installed Lib Extension library directory (/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/) in particular. You need to make sure that there are at least mysqli.so, pdo_mysql.so two dynamic library files, as shown in.
[root@localhost php-7.0.0]# ls -lrt /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
Start setting PHP7 configuration Files php.ini, php-fpm.conf, www.conf, and PHP-FPM scripts
You can use the compiled configuration file to copy to the PHP7 configuration directory (/usr/local/php7/etc/), which is recommended in GitHub. This configuration comes from the configuration of PHP.ini, PHP-FPM, and www.conf in the PHP7
#######方法一: Directly using a configuration that was not optimized for post-compilation [root@localhost php-7.0.0]# CP Php.ini-production/usr/local/php7/etc/php.ini[root@localhost php-7.0.0]# Cp/root/php-7.0.0/sapi/fpm/init.d.php-fpm/etc/init.d/php-fpm[root@localhost php-7.0.0]# Cp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf[root @localhost php-7.0.0]# Cp/usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/www.conf###### #方法二: Using https://github.com/lizer2014/mylnmp/tree/master/ Configuration in PHP [Root @localhost php-7.0 .0]# mv ~/php.ini/usr/local/php7/etc/php.ini && MV ~/php-fpm/etc/init.d/php-fpm[ Root @localhost php-7.0.0]# mv ~/php-fpm.conf/usr/local/php7/etc/php-fpm.conf && MV ~/www.conf/usr/local/php7/ etc/php-fpm.d/www.conf
Note: You need to modify the parameters in the php.ini configuration, Extension_dir change to your own
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
Where the/etc/init.d/php-fpm in the start function before the daemon must have the MAKE/VAR/RUN/PHP-FPM command, or restart the server will lead to failure, nginx configuration also has this problem
Add environment Variables for PHP
[root@localhost php-7.0.0]# echo -e ‘\nexport PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH\n‘ >> /etc/profile && source /etc/profile
Set the PHP log directory and the PHP-FPM process files (php-fpm.sock) directory
Where the user and user groups that set the PHP-FPM process directory are Nginx, and the Session Directory of PHP sessions is created
###### #设置PHP日志目录和php-FPM running process ID file (php-fpm.sock) directory [root< Span class= "Hljs-property" > @localhost php-7.0.0]# groupadd-r nginx && useradd-r-G nginx-s/bin/false-m nginx[root@l Ocalhost php-7.0.0]# mkdir-p/var/ log/php-fpm/&& mkdir-p/var/run/php-fpm && cd/var/run/&& chown-r nginx:nginx php-fpm###### #修改session的目录配置 [Root @localhost Run]# mkdir-p/var/lib/php/session[root @localhost run]< Span class= "hljs-comment" ># chown-r nginx:nginx/var/lib/php
Set PHP boot up and test configuration files correctly
##### #配置开机自启动, added to host SysV service [[email protected] run]< Span class= "hljs-comment" ># chmod +x/etc/init.d/php-fpm[[email protected] run]< Span class= "hljs-comment" ># chkconfig--add php-fpm[[email protected] run]# chkconfig php-fpm on##### #测试PHP的配置文件是否正确合法 [[email Protected] run]# php-fpm-t[05- Dec-2015 17: 33: 03] notice:configuration file/usr/ local/php7/etc/php-fpm.conf test is successful
Start PHP Service
After you have done this, you can formally use PHP services. The command to start the PHP process service is as follows:
[[email protected] init.d]# service php-fpm startStarting php-fpm done
You can then use the command ps-aux|grep PHP to see if the success (the number of php-fpm processes in the figure and the process user Nginx are determined by the values of Pm.start_servers and users in www.conf):
View PHP7 Version Information
Finally, you can view the current PHP version information by command php-v, and you can see that the current PHP7 also uses the Zend Opcache cache because php.ini configuration was added to the zend_extension=opcache.so file.
CentOS Compiler Installation PHP7