PHP on CentOS 7 (安装PHP-FPM)
上一篇介绍了CentOS7安装Nginx,这次再来介绍CentOS7配置PHP环境(即安装PHP-FPM)。
目标:在centos7上安装配置PHP 5.6。
第一步、安装php5.6前的环境准备
1、让系统获取更新,到最新的版本。(这不仅更新package,而且获取最新存储库,确保任何package都可以正确安装)
yum update
2、安装含有各种版本PHP的仓库
To add his PHP repository, run the following command:
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
This pulls in the package and adds the repository to YUM. It is being added disabled, though, so we have to enable that manually. So, open the repository file:
vi /etc/yum.repos.d/remi.repo
然后找到下面2个地方:
[remi]
name=Remi’s RPM repository for Enterprise Linux 7 – $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi…
[remi-php56]
name=Remi’s PHP 5.6 RPM repository for Enterprise Linux 7 – $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php56/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/php56/mirror
# WARNING: If you enable this repository, you must also enable “remi”
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
I’ve cut out the ‘remi-php55’ block as we want PHP 5.6 and not PHP 5.5. Now, in order to enable this repository, you have to change ‘enabled=0’ into ‘enabled=1’. This means that after the change the blocks look like this,修改为:
[remi]
name=Remi’s RPM repository for Enterprise Linux 7 – $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi…
[remi-php56]
name=Remi’s PHP 5.6 RPM repository for Enterprise Linux 7 – $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php56/$basearch/
mirrorlist=http://rpms.remirepo.net/enterprise/7/php56/mirror
# WARNING: If you enable this repository, you must also enable “remi”
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
保存修改。
二、开始安装
yum install php-fpm
安装完毕后,运行php-fpm:
systemctl start php-fpm
让php-fpm开机自动运行:
systemctl enable php-fpm
Now we need to ensure that NGINX knows to send PHP-requests to PHP-FPM. For this to work we need to add a configuration block to the default host. For reasons beyond my understanding this was set up a bit “different” on CentOS, so if you’re looking for logic stop trying. In any case, fire up a new file:
vi /etc/nginx/default.d/php-fpm.conf
添加以下代码:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
This block tells NGINX to pass on any request going to a file ending with .php to 127.0.0.1 port 9000, which is where PHP-FPM runs. NGINX does this using FastCGI. The configuration block includes default configuration we won’t touch for now.
With these contents in the file, save the file, and restart NGINX:
systemctl restart nginx.service
查看nginx启动状态
systemctl status nginx.service -l
到此安装完毕,用phpinfo测试:
vi /usr/share/nginx/html/info.php
<?php phpinfo();
1 条留言 访客:0 条 博主:0 条 引用: 1 条
来自外部的引用: 1 条