Home >Backend Development >PHP Problem >How to build php5.6 on centos7
How to build php5.6 on centos7: 1. Obtain the PHP download address; 2. Configure the installation directory to /usr/local/php/; 3. Configure the php.ini file; 4. Copy php- Just modify the fpm configuration file and start it.
The operating environment of this article: centos7 system, PHP5.6 version, DELL G3 computer
How to build php5.6 on centos7?
Detailed tutorial on installing PHP5.6.30 service under CentOS7.0
About php-fpm
nginx itself It cannot handle PHP. It is just a web server. When a request is received, if it is a PHP request, it will be sent to the PHP interpreter for processing and the result will be returned to the client.
nginx generally sends the request to the fastcgi management process for processing. The fascgi management process selects the cgi sub-process processing result and returns it to nginx.
PHP-FPM is a PHP FastCGI manager, only for PHP.
PHP has written php-fpm into the PHP source code core after 5.3.3. So there is no need to download it separately.
Get the PHP download address
Why choose version 5.6.30? Because it is learning, not research. It is true that 7.0 has added many new features of PHP, and the performance has also been improved. If you are doing research, you can do some research. I will talk about the 7.0 version and how to switch between various PHP versions later.
Open the official website of php: http://php.net/, view the version list of php
Right-click, copy the link address, and run it on the remote host Log in and download the software (I chose Australia’s host mirror to download)
# wget http://au1.php.net/get/php-5.6.30.tar.gz/from/this/mirror
What is downloaded is a mirror file, change it to the file name we need
#mv mirror php-5.6.30.tar.gz#tar zxvf php-5.6.30.tar.gz#cd php-5.6.30
Configure installation
Enter the directory, we need to configure the installation directory to /usr/local/php/ during installation
#./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-MySQL --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
During the configuration process The following error may be reported
Error 1:
xml2-config not found. Please check your libxml2 installation.
Solution
Install libxml2 related components
#yum install libxml2#yum install libxml2-devel -y
Error 2:
Please reinstall the libcurl distribution - easy.h should be in <curl-dir>/include/curl/
Install curl related components
#yum install curl curl-devel
Error 3:
configure: error: png.h not found.
Install libpng related components
#yum install libpng#yum install libpng-devel
Error 4:
freetype-config not found.
Install freetype related components
#yum install freetype-devel
Error 5:
xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
Install libxslt related components
#yum install libxslt-devel
Okay, when we see the following sentence, it means that your php has been configured!
Next we only need to compile and install to complete the installation of php
#make && make install
Seeing this sentence indicates that the installation is complete!
To be on the safe side, let’s make a test to see if it is really successful.
Configure related php.ini configuration
First we need to configure the php.ini file
The installation directory has 2 files: php.ini-development and php.ini-production
php.ini-production Use the online version
php.ini-development Use the development version
We choose development for configuration
# cp php.ini-development /usr/local/php/lib/php.ini
php-fpm configuration
Copy the php-fpm configuration file
#cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
Copy the enable file
#cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm(已弃用,详细的见注1)
Start
#/etc/init.d/php-fpm
Check whether php is started successfully
#ps aux | grep php
Seeing these indicates that your php It has been started successfully!
Restart and shut down
#kill -9 进程号 #/etc/init.d/php-fpm
Configure Nginx to support PHP
Enter the nginx main directory, /usr/local/nginx;
#cd /usr/local/nginx
Enter the configuration directory
#cd conf
Nginx supports PHP. You need to modify nginx.conf
#vim nginx.conf
and open the following code to let Nginx support PHP in the server code segment.
After modification, this code changes to the red part indicating that our host directory is /usr/www. You need to modify fastcgi_param SCRIPT_FILENAME to point to the corresponding directory:
Set the home directory to /usr/www.
Comment out the root line and add a new line: root /usr/www;
Save and exit.
According to the explanation in the Nginx chapter, we restart the Nginx service.
#/etc/init.d/nginx restart
If you have not configured it according to our method in Nginx, you can restart the Nginx service as follows
# /usr/local/nginx/sbin/nginx -s reload
Restart successfully! Next we add a new file in the /usr/www directory.
#vim /usr/www/phpinfo.php
Insert the following content
<?php phpinfo(); ?>
Open http://remoteip/phpinfo.php
in the browser看到这个页面,恭喜你,你的PHP已经安装配置完成。你可以在这个页面看到所有php依赖的组件,下一节我将和大家详细讲解一下这个页面,如果对本节有什么疑问的,欢迎在评论区和我交流讨论,有留言必回。^_^
注
设置php开机自启动与开启php服务便捷方式
上面的方法中,我在拷贝php-fpm的服务时出了问题,不应该直接将php-fpm的可执行文件拷贝到/etc/init.d/目录下去,应该将php给我们准备好的init.d.php-fpm。
#cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
将php-fpm服务添加到chkconfig列表
#chkconfig --add php-fpm
设置开机自启动
#chkconfig php-fpm on
以后重启和停止php的方式为
#service php-fpm start #service php-fpm stop #service php-fpm restart #service php-fpm reload
上面是我的问题,请大家及时更正。
推荐学习:《PHP视频教程》
The above is the detailed content of How to build php5.6 on centos7. For more information, please follow other related articles on the PHP Chinese website!