LoginSignup
0
0

More than 5 years have passed since last update.

PHPインストール

Last updated at Posted at 2019-03-13

前置き

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登録

sudo service nginx reload/restart
やり方は サービス再起動とchkconfig登録 へご参照ください

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0