さくらVPSにNginxとかPHPとか入れた

契約したさくらVPSが無事SSHログインできるようになったので、NginxでPHP動かす設定をする。

さくらのVPS借りた | Border/memo

Nginxインストールする

リポジトリ登録する

2014年9月12日時点の最新のリポジトリURLはこれ。

http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

ちなみにここから見られる。さくらVPSだとCentOS6なので、「CentOS 6」のURLをコピーする。

サーバにSSHログインして、下記コマンド入力。

$ rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

Nginxリポジトリが追加された。$ yum info nginxとしてみて、追加前よりバージョンが新しくなってればいい。

インストールする

$ yum -y install nginx

PHPインストールする

どうせなら新しい方がいいので、PHP 5.5入れる。

リポジトリ登録する

epelリポジトリ登録する。

$ rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

remiリポジトリ追加する。

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

インストールする

$ yum -y install --enablerepo=remi --enablerepo=remi-php55 php-cli php-mbstring php-gd php-mysql php-fpm

なんやかんやインストールされる。

MySQLインストールする

$ yum -y install mysql-server

php-fpmの設定する

設定ファイルいじる。

$ vi /etc/php-fpm.d/www.conf

ユーザーとグループをapacheからnginxに変更する。

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

Nginxの設定する

default.conf編集する

設定ファイルいじる。

$ vi /etc/nginx/conf.d/default.conf

ルートディレクトリ設定したりする。/var/www/htmlをルートにする。

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /var/www/html;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

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

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

nginx.conf編集する

設定ファイルいじる。こっちはNginx本体、共通の設定っぽい。上で編集したdefault.confとかは設置するサイトによって複数作れるっぽい。

$ vi /etc/nginx/nginx.conf

httpのディレクティブ?にgzipの設定追加した。

http {
    gzip  on;
    gzip_http_version 1.0;
    gzip_types text/plain text/xml text/css application/xml application/xhtml+xml application/rss+xml application/atom_xml application/javascript application/x-javascript application/x-httpd-php;
    gzip_disable “MSIE [1-6]\.”;
    gzip_disable “Mozilla/4″;
    gzip_comp_level 1;
    gzip_proxied any;
    gzip_vary on;
    gzip_buffers 4 8k;
    gzip_min_length 1100;
}

gzip圧縮されてるか確認したい場合は下記サイトが便利。

GIDZipTest: Web Page Compression (Deflate / Gzip) Test - GIDNetwork

php.ini編集する

$ vi /etc/php.ini

ファイルのアップロードサイズの制限などを変える。設定ファイル長くて見づらいですが、viのショートカットを覚えるなどして頑張る。

default_charset = UTF-8
short_open_tag = On
upload_max_filesize = 30M
post_max_size = 30M
memory_limit = 128M
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
date.timezone = Asia/Tokyo

サービスの自動起動設定する

サービス起動して、ついでに自動起動も設定する。

Nginx

$ service nginx start
$ chkconfig nginx on

php-fpm

$ service php-fpm start
$ chkconfig php-fpm on

MySQL

$ service mysqld start
$ chkconfig mysqld on

MySQLの初期設定やる

$ /usr/bin/mysql_secure_installation

なんかいろいろ出てくるので、いい感じにやる。基本はEnter(Yes)でいいと思う。rootパスワードはちゃんと設定してどっかにメモっとく。


多分この流れでWordPress用のデータベース作ればいいんだけど、今回はここまで。次はデータベース作って、WP-CLIとかインストールして、WordPress入れます(多分)

参考にしたサイト

どうもありがとうございます

Recent Posts

Loading...

1 Notes

  1. atm09td reblogged this from brdr-mmrndm
  2. brdr-mmrndm posted this