LoginSignup
54
57

More than 5 years have passed since last update.

CentOS7でnginxをyumでインストール(phpのおまけ付き)

Posted at

nginxリポジトリの登録(作成)。

※まだmainlaineにしかない模様。2014/07/15時点の最新版である1.7.3が入る

bash
[root@centos7 ~]# vi /etc/yum.repos.d/nginx.repo
/etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
#baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=0

nginxをインストール & 実行 & 登録

bash
[root@centos7 ~]# yum --enablerepo=nginx install nginx
[root@centos7 ~]# systemctl start nginx
[root@centos7 ~]# systemctl enable nginx

php-fpmをインストール

bash
[root@centos7 ~]# yum install php-fpm php-mbstring

nginxの設定でphp-fpmが動くように変更する

bash
[root@centos7 ~]# vi /etc/nginx/conf.d/default.conf
/etc/nginx/conf.d/default.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;
    }
bash
[root@centos7 ~]# systemctl restart nginx
[root@centos7 ~]# echo '<?php phpinfo();' > /usr/share/nginx/html/info.php
[root@centos7 ~]# systemctl start php-fpm
[root@centos7 ~]# systemctl enable php-fpm
[root@centos7 ~]# curl 'http://localhost/info.php'

外部からアクセスする時のおまけ(CentOS7からfirewalldに変わった)

bash
[root@centos7 ~]# systemctl stop firewalld
54
57
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
54
57