Home >Backend Development >PHP Tutorial >Detailed introduction to the sample code for compiling and installing PHP7 on CentOS7 (picture)
First create a user named php without login permission 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 and install libmcrypt, mhash, mcrypt binary source package
The reason why libmcrypt is compiled and installed here is because the yum installation seems to report 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-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.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 ~]# 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
Note that during operation, you must first remove the comment text added after the backslash "\" below! ! !
######生成配置文件 [root@localhost ~]# tar -zxf php-7.0.0.tar.gz && cd php-7.0.0 [root@localhost php-7.0.0]# ./buildconf --force Forcing buildconf Removing configure caches buildconf: checking installation... buildconf: autoconf version 2.69 (ok) rebuilding configure rebuilding main/php_config.h.in ######开始配置 [root@localhost php-7.0.0]# ./configure \ --prefix=/usr/local/php7 \ [PHP7安装的根目录] --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的配置目录] --with-mysql-sock=/var/run/mysql/mysql.sock \ [PHP7的Unix socket通信文件] --with-mcrypt=/usr/include \ --with-mhash \ --with-openssl \ --with-mysql=shared,mysqlnd \ [PHP7依赖mysql库] --with-mysqli=shared,mysqlnd \ [PHP7依赖mysql库] --with-pdo-mysql=shared,mysqlnd \ [PHP7依赖mysql库] --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 \ --with-xmlrpc \ --enable-soap \ --without-pear \ --with-gettext \ --enable-session \ [允许php会话session] --with-curl \ [允许curl扩展] --with-jpeg-dir \ --with-freetype-dir \ --enable-opcache \ [使用opcache缓存] --enable-fpm \ --enable-fastcgi \ --with-fpm-user=nginx \ [php-fpm的用户] --with-fpm-group=nginx \ [php-fpm的用户组] --without-gdbm \ --with-mcrypt=/usr/local/related/libmcrypt \ [指定libmcrypt位置] --disable-fileinfo
The results of executing the above configuration command are as follows:
[root@localhost php-7.0.0]# make clean && make && make install
PHP 7 was compiled and installed successfully
This is an optional step, execute the make test command
Since you need to communicate with MySQL, you need to specifically check the lib extension library directory after PHP7 is installed (/usr/local/php7/lib/php/ extensions/no-debug-non-zts-20151012/). You need to ensure that at least two dynamic library files mysqli.so and pdo_mysql.so exist, as shown in the figure below.
[root@localhost php-7.0.0]# ls -lrt /usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/
can be compiled with Copy the configuration file to the PHP7 configuration directory (/usr/local/php7/etc/). It is recommended to use the configuration in github. This configuration comes from "Configuration of php.ini, php-fpm and www.conf in PHP7"
#######方法一:直接使用编译后未经优化处理的配置 [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 #######方法二:使用https://github.com/lizer2014/mylnmp/tree/master/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 and change extension_dir to your own
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"
In /etc/init.d/php-fpm, there must be a make /var/run/php-fpm command before the daemon process of the start function. Otherwise, restarting the server will cause the startup to fail. In nginx Configuration also has this problem
[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
Among them, set php -The user and user group of the fpm process directory are nginx, and create a php session session directory
#######设置PHP日志目录和php-fpm的运行进程ID文件(php-fpm.sock)目录 [root@localhost php-7.0.0] # groupadd -r nginx && useradd -r -g nginx -s /bin/false -M nginx [root@localhost 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] # chown -R nginx:nginx /var/lib/php
######配置开机自启动,增加到主机sysV服务 [root@localhost run]# chmod +x /etc/init.d/php-fpm [root@localhost run]# chkconfig --add php-fpm [root@localhost run]# chkconfig php-fpm on ######测试PHP的配置文件是否正确合法 [root@localhost run]# php-fpm -t [05-Dec-2015 17:33:03] NOTICE: configuration file /usr/local/php7/etc/php-fpm.conf test is successful
After completing the above operations, you can officially use the php service. The command to start the php process service is as follows:
[root@localhost init.d]# service php-fpm startStarting php-fpm done
Then you can check whether it is successful through the command ps -aux|grep php (the number of php-fpm processes and the process user nginx in the picture are both determined by pm in www.conf. The values of start_servers and user are determined respectively):
Finally, you can view the current PHP version information through the command php -v, as shown in Figure You can see that currently PHP7 also uses Zend OPcache cache because the zend_extension=opcache.so configuration was added to the php.ini file.
Related articles:
Mac uses the php installed by itself by default
centos6.7 installation Detailed introduction to php7
The above is the detailed content of Detailed introduction to the sample code for compiling and installing PHP7 on CentOS7 (picture). For more information, please follow other related articles on the PHP Chinese website!