LoginSignup
0
1

More than 5 years have passed since last update.

PHP7とNginxで開発環境を整える

Last updated at Posted at 2017-10-08

PHP7とNginxをインストールして開発環境を整える。

wordpress4.8系の推奨環境が、PHP7系ということでPHP7とNginxで環境を構築する方法をメモします。
ここでは、wordpressインストールまではやりません。

NginxとPHP7のインストール

ここでハマったのは、FTPのポートを開けてなくて、1つ目のインストールができなかったことです。
なので手元のMacでダウンロードして、SCPしました。ダサすぎるw

scl-utilsのインストール

手元のMacのブラウザで以下にアクセスし、ダウンロード
ftp://ftp.scientificlinux.org/linux/scientific/6.4/x86_64/updates/fastbugs/scl-utils-20120927-8.el6.x86_64.rpm

EC2にアップロード
scp scl-utils-20120927-8.el6.x86_64.rpm ec2-user@xxx.xxx.xxx.xxx:/home/ec2-user

インストール
sudo rpm -Uvh scl-utils-20120927-8.el6.x86_64.rpm

remiレポジトリのインストール

sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

NginxとPHPのインストール

sudo yum install nginx php70 php70-php-fpm

NginxとPHP-fpmの自動起動

sudo chkconfig php70-php-fpm on
sudo chkconfig nginx on

Nginxの設定

SCRIPT_FILENAMEのところを$document_rootとしているところがうまく動かなかったので今回は直書き。
動くのが正義。孫正義

    server {
        listen       80;
        server_name  localhost;
        root         /var/www/html;
        index        index.php index.html;
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
            fastcgi_param  PATH_INFO $fastcgi_script_name;
            include        fastcgi_params;
        }
    }

PHPとNginxの再起動


sudo service nginx restart
sudo service php70-php-fpm restart

PHPのファイルを作って動作確認

cd /var/www/
sudo mkdir html
sudo vi html/index.php

index.phpの内容

<?php phpinfo(); ?>

sudo chmod -R 755 html/

ブラウザでEC2のIPアドレスにアクセスするっす!!
image.png

0
1
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
1