LoginSignup
5
14

More than 5 years have passed since last update.

5分で構築、AmazonLinux+PHP7+Nginx+Wordpress

Last updated at Posted at 2018-01-30

使用した環境

以下環境のバージョンなど
AMIは、amzn-ami-hvm-2017.09.1.20171120-x86_64-gp2
Nginxは、version1.12.1
Wordpressは、version4.9.2日本語版

php70.x86_64                         7.0.25-1.26.amzn1             @amzn-updates
php70-cli.x86_64                     7.0.25-1.26.amzn1             @amzn-updates
php70-common.x86_64                  7.0.25-1.26.amzn1             @amzn-updates
php70-fpm.x86_64                     7.0.25-1.26.amzn1             @amzn-updates
php70-json.x86_64                    7.0.25-1.26.amzn1             @amzn-updates
php70-mbstring.x86_64                7.0.25-1.26.amzn1             @amzn-updates
php70-mysqlnd.x86_64                 7.0.25-1.26.amzn1             @amzn-updates
php70-pdo.x86_64                     7.0.25-1.26.amzn1             @amzn-updates
php70-process.x86_64                 7.0.25-1.26.amzn1             @amzn-updates
php70-xml.x86_64                     7.0.25-1.26.amzn1             @amzn-updates

インストール

yumのアップデート

sudo yum -y update

yumで必要なものを入れる

sudo yum -y install php70
sudo yum -y install php70-mbstring
sudo yum -y install php70-pdo
sudo yum -y install php70-fpm
sudo yum -y install php70-mysqlnd

設定

apacheのユーザから、nginxに置き換える

/etc/php-fpm.d/www.conf
user = nginx
group = nginx

Nginxの設定

nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    include /etc/nginx/conf.d/*.conf;

    index   index.php index.html index.htm;

}

作成するサイトのドメインをsample.comとする

/etc/nginx/conf.d/sample.conf
server {
    listen       80;
    client_max_body_size 20M;
    server_name  sample.com;
    root         /var/www/html/sample;
    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/sample$fastcgi_script_name;
        #fastcgi_param  PATH_INFO $fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_read_timeout 180;
    }


    include /etc/nginx/default.d/*.conf;

    location / {
    }

    # redirect server error pages to the static page /40x.html
    #
    error_page 404 /404.html;
        location = /40x.html {
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

}

以下のコマンドを打って、/var/www/html以下に、wordpressを配置

cd /var/www/html
sudo wget https://ja.wordpress.org/wordpress-4.9.2-ja.zip
sudo unzip wordpress-4.9.2-ja.zip
sudo mv wordpress sample
sudo chown -R nginx:nginx sample

起動時にNginxとPHPが立ち上がるようにする

sudo chkconfig nginx on
sudo chkconfig php-fpm-7.0 on

起動

sudo service nginx start
sudo service php-fpm-7.0 start

アクセスしてWordpressをインストール

サーバのIPアドレスにアクセス
DBなどの初期設定をして終わりですね。
DBにRDSを指定したい人はこちら
1つのサーバで複数ドメインをNginxに指定したい人はこちら

おまけ

お使いのサーバーの PHP では WordPress に必要な MySQL 拡張を利用できないようです。

このエラーが出るときは、mysqlの拡張が入っていないことが原因です。
php70-mysqlndがちゃんと入っているか確認しましょう。

5
14
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
5
14