Centos7搭建PHP环境

2018-02-27 11:03:09来源:http://www.crocutax.com/2018/02/25/Centos7搭建PHP环境/作者:Crocutax's Blog人点击

分享

PHP官网下载链接:



/2014th7cj/d/file/p/20180227/manual-lookup.php zxvf php-7.2.2.tar.gz
编译

进入php7文件夹


cd php-7.2.2

输入命令:


./configure --enable-fpm --enable-mbstring

自己在安装的过程中出现了如下异常:


configure: error: xml2-config not found. Please check your libxml2 installation.


提示找不到xml2-config
文件,让检查libxml2
的安装情况。



检测libxml2
是否安装,显示已安装


[root@nginx php-7.2.2]# rpm -qa|grep libxml2
libxml2-2.9.1-6.el7_2.3.x86_64

重复安装无效


[root@nginx php-7.2.2]# yum install libxml2
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package libxml2-2.9.1-6.el7_2.3.x86_64 already installed and latest version
Nothing to do


但查找xml2-config
文件,还是提示没有


[root@nginx php-7.2.2]# find/-name "xml2-config"
-bash: find/-name: No such file or directory


通过搜索引擎找到解决方案:检测libxml2-devel
的安装情况,通过rpm -qa |grep libxml2-devel
命令发现没有安装,于是开始安装。


[root@nginx php-7.2.2]# yum install libxml2-devel -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package libxml2-devel.x86_64 0:2.9.1-6.el7_2.3 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
========================================================================================================================================================
PackageArchVersionRepositorySize
========================================================================================================================================================
Installing:
libxml2-develx86_642.9.1-6.el7_2.3base1.0 M
Transaction Summary
========================================================================================================================================================
Install1 Package
Total download size: 1.0 M
Installed size: 8.8 M
Downloading packages:
libxml2-devel-2.9.1-6.el7_2.3.x86_64.rpm| 1.0 MB00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libxml2-devel-2.9.1-6.el7_2.3.x86_641/1
Verifying: libxml2-devel-2.9.1-6.el7_2.3.x86_641/1
Installed:
libxml2-devel.x86_64 0:2.9.1-6.el7_2.3
Complete!


此时再次检测libxml2
安装情况和xml2-config
文件,发现都没问题了:


[root@nginx php-7.2.2]# rpm -qa |greplibxml2
libxml2-2.9.1-6.el7_2.3.x86_64
libxml2-devel-2.9.1-6.el7_2.3.x86_64
[root@nginx php-7.2.2]# find / -name "xml2-config"
/usr/bin/xml2-config

于是重新


./configure --enable-fpm --enable-mbstring

成功:


Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:|
| This software is subject to the PHP License, available in this|
| distribution in the file LICENSE.By continuing this installation |
| process, you are bound by the terms of this license agreement.|
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.|
+--------------------------------------------------------------------+
Thank you for using PHP.
安装
make
make install

测试安装结果:


[root@nginx web]# php -v
PHP 7.2.2 (cli) (built: Feb 24 2018 15:17:15) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
配置FPM

只安装了PHP还不能直接访问PHP文件,需要配置PHP-FPM,并启动FPM服务。


按照PHP官网的配置说明,创建配置文件


cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
cp sapi/fpm/php-fpm /usr/local/bin

然后启动 php-fpm 服务:


/usr/local/bin/php-fpm

报如下异常:


ERROR: Unable to globalize ‘/usr/local/NONE/etc/php-fpm.d/*.conf’ (ret=2) from /usr/local/etc/php-fpm.conf

编辑php-fpm.conf配置文件


vim /usr/local/etc/php-fpm.conf


将最后一行include=NONE/etc/php-fpm.d/*.conf
修改为include=etc/php.fpm.d/*.conf


include=NONE/etc/php-fpm.d/*.conf #修改前
include=etc/php.fpm.d/*.conf#修改后

继续启动php-fpm 服务:


/usr/local/bin/php-fpm

报如下异常:


[root@nginx php]# /usr/local/bin/php-fpm [24-Feb-2018 16:04:17] WARNING: Nothing matches the include pattern ‘/usr/local/etc/php-fpm.d/*.conf’ from /usr/local/etc/php-fpm.conf at line 125. [24-Feb-2018 16:04:17] ERROR: No pool defined. at least one pool section must be specified in config file [24-Feb-2018 16:04:17] ERROR: failed to post process the configuration [24-Feb-2018 16:04:17] ERROR: FPM initialization failed


进入目录进入目录/usr/local/etc/php-fpm.d
,执行


cp www.conf.default www.conf


再起启动php-fpm服务,通过netstat -tunlp |grep 9000
命令,发现启动成功了:


[root@nginx sbin]# netstat -tunlp |grep 9000
tcp00 127.0.0.1:90000.0.0.0:*LISTEN118470/php-fpm: mas
配置Nginx

这里直接记录已经正常运行phpMyAdmin的Nginx配置,此时phpMyAdmin放在了Nginx的html目录下。


server {
listen 8081;
server_name localhost;
location /phpmyadmin {
root html;
index index.php index.html;
}
location ~* /.php$ {
fastcgi_index index.php;
fastcgi_pass127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME$fastcgi_script_name;
}
}

配置完成以后,记得:


service nginx restart


输入:http://yourIpAddress:8081/phpmyadmin
可直接访问phpMyAdmin登录页面。


(完)


参考链接:



http://blog.csdn.net/etwo123/article/details/54582088
(重点感谢)



http://php.net/manual/zh/install.unix.nginx.php



http://blog.csdn.net/u010647316/article/details/56489795


http://blog.csdn.net/dabao1989/article/details/22898857

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台