2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7にnginx+PHP環境を導入するメモ

2
Posted at

Azure仮想マシンに作ったCentOS7にnginx+PHPの環境を作る。

nginxのインストール

/etc/yum.repos.d/nginx.repoを新規作成、以下のように記述。

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

ファイルを保存後、

# yum install nginx

インストールできたら、

# systemctl start nginx

ブラウザからサーバにアクセス、テストページが表示されるか確認。
ファイアウォールなどの設定は割愛してますが、お忘れなく。

phpのインストール

nginxでPHPを使うため、PHP-FPMを利用する。

# yum install php-fpm

/etc/php-fpm.d/www.conf を編集。

…
user = nginx
…
group = nginx
…

nginxの設定変更

nginxにphpファイル関連の設定を記述。
ついでにドキュメントルートとかを変更してもいい。

location ~ \.php$ {
#    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /home/***/www/html$fastcgi_script_name;
    include        fastcgi_params;
}

fastcgi_paramのパスは適宜変更。

以上の設定が終わったら、

# systemctl start php-fpm
# systemctl restart nginx

で動作確認。ドキュメントルートにphpinfoでも置いておく。

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?