安装PHP
引言
我想在Centos上安装Nginx,并希望能够运行PHP。
Centos安装Nginx的步骤如下:
-
- phpインストール用のremiレポジトリを用意する
-
- phpをインストールする
-
- 設定ファイルを変更する
- nginx再起動、php-fpmスタートとchkconfig登録
操作步骤
准备用于安装PHP的Remi仓库。
[user@localhost yum.repos.d]$ sudo yum -y install http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
[user@localhost yum.repos.d]$ ls -l
-rw-r--r-- 1 root root 456 12月 22 02:50 2018 remi-php54.repo
-rw-r--r-- 1 root root 1314 12月 22 02:50 2018 remi-php70.repo
-rw-r--r-- 1 root root 1314 12月 22 02:50 2018 remi-php71.repo
-rw-r--r-- 1 root root 1314 12月 22 02:50 2018 remi-php72.repo
-rw-r--r-- 1 root root 1314 12月 22 02:50 2018 remi-php73.repo
安装PHP
在安装之前,最好先做好以下事情。
-
- php関連のインストールがあったら
php.iniのバックアップ
インストールしたものを削除する
yum更新する
足りないパッケージインストール(なぜか自分の環境でlibargon2がインストールされていない(Conohaさん)
如果有缺少的软件包,可以在软件包搜索中进行确认
https://centos.pkgs.org/6/remi-x86_64/libargon2-20161029-2.el6.remi.x86_64.rpm.html
[user@localhost yum.repos.d]$ sudo yum list installed php*
[user@localhost yum.repos.d]$ sudo find / -name "php.ini" -ls
[user@localhost yum.repos.d]$ sudo yum remove php*
[user@localhost yum.repos.d]$ sudo yum -y update
[user@localhost yum.repos.d]$ sudo yum -y --enablerepo=remi install libargon2
[user@localhost yum.repos.d]$ sudo yum -y install --enablerepo=remi-php71 php php-cli php-common php-devel php-fpm php-gd php-mbstring php-mysqlnd php-pdo php-pear php-pecl-apcu php-soap php-xml php-xmlrpc
修改设置文件
- php-fpmの設定ファイル変更(userとgroup)
[user@localhost yum.repos.d]$ sudo sed -i 's/user\ \=\ apache/user\ \=\ nginx/g' /etc/php-fpm.d/www.conf
[user@localhost yum.repos.d]$ sudo sed -i 's/group\ \=\ apache/group\ \=\ nginx/g' /etc/php-fpm.d/www.conf
- nginxのconfファイル追加する(wordpressサイト作成)
server {
listen 80;
server_name test.domain.com;
#access_log /var/log/nginx/host.access.log main;
location / {
root /project_dir;
index index.html index.htm index.php;
#include /etc/nginx/conf.d/rewrite/wordpress.conf;
}
location ~ \.php$ {
root /project_dir;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /project_dir$fastcgi_script_name;
include fastcgi_params;
}
}
重新启动nginx,启动php-fpm并将其注册到chkconfig。
请参考以下两种方式来重新加载/重启nginx:
1. 使用命令 “sudo service nginx reload/restart”。
2. 参考命令 “サービス再起動とchkconfig登録”。