LoginSignup
13
13

More than 5 years have passed since last update.

Concrete5 with Nginx + php-fpm

Posted at

要件

  • Concrete5.7をNginxで動かす
  • Nginxはソースインストール
  • PHPはCGIモード(PHP-FPM)
  • DBはMySQL
  • ドメイン名:hogehoge.com
  • ドキュメントルート:/var/www/vhosts/hogehoge.com
  • DB名:concrete_db
  • DBユーザ名:concrete5

※できるだけ汎用的に書いてますが、一部バージョンなどによりコマンド、パッケージ名などが変わります。

インストールの下準備

Kernelなどインストール済みのミドルウェアを最新に。

全てのミドルウェアをアップデート

コマンド
yum update -y

一旦、再起動

コマンド
reboot

あると便利なYUMリポジトリを追加

※不要なら飛ばしても可能

  • epelの追加
コマンド
rpm -Uvh http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm && sed -i -e "s/enabled *= *1/enabled=0/g" /etc/yum.repos.d/epel.repo
  • rpm-forgeの追加
コマンド
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm && sed -i -e "s/enabled *= *1/enabled=0/g" /etc/yum.repos.d/rpmforge.repo
  • remiの追加
コマンド
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm && sed -i -e "s/enabled *= *1/enabled=0/g" /etc/yum.repos.d/remi.repo

Ctl-Alt-Delの停止

※不慮の事故を避けるために

/etc/init/control-alt-delete.conf
#下記の行をコメントアウト
exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

あると便利なツールのインストール

コマンド
yum install telnet sysstat nmap gcc make git subversion subversion-tools subversion-libs subversion-devel openssl-devel -y

Postfixのインストール

※Sendmailは落ち着かないので。不要なら飛ばしても可能
インストール

コマンド
yum install postfix.x86_64 postfix-perl-scripts.x86_64 -y

ディフォルトMTAの切り替え

コマンド
alternatives --config mta

Sendmailの停止とPostfixの起動

コマンド
/etc/init.d/sendmail stop && /etc/init.d/postfix start

Nginx

Nginxのインストール(ソースから)

ソースの取得⇒解凍

コマンド
#ソースディレクトリに移動
cd /usr/local/src/

#最新のNginxのダウンロード
wget http://nginx.org/download/nginx-1.6.2.tar.gz

#解凍
tar zxvf nginx-1.6.2.tar.gz

#解凍されたNginxディレクトリに移動
cd nginx-1.6.2

Nginxユーザの追加

コマンド
useradd -s/sbin/nologin -d/usr/local/nginx -M nginx

configure → make → install

configure

コマンド
./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module

makeとinstall

コマンド
make && make install

※[/usr/local/nginx] 以下にファイルが生成されていれば成功です。

ログ設定

Logrotateの設定

/etc/logrotated/nginx
/var/log/nginx/*log {
    missingok
    notifempty
    sharedscripts
    rotate 12
    weekly
    compress
    postrotate
        kill -USR1 `cat /var/run/nginx.pid`
    endscript
}

ログディレクトリの作成

コマンド
mkdir /var/log/nginx

コンテンツディレクトリの作成

コマンド
mkdir -p /var/www/vhosts/

起動スクリプト

/etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -z "`grep $user /etc/passwd`" ]; then
       useradd -M -s /bin/nologin $user
   fi
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo $opt | cut -d "=" -f 2`
           if [ ! -d "$value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

起動スクリプトの権限設定

コマンド
chmod 755 /etc/init.d/nginx

自動起動の設定

コマンド
chkconfig nginx on

Nginxの設定

/usr/local/nginx/conf/nginx.conf
#### NginX Conf ###
user  nginx;
#サーバのCore数似合わせる
worker_processes  1;

#worker_processes x worker_rlimit_nofile = Max Connection
#大きくし過ぎるとOSのUlimitに引っかかるので注意
worker_rlimit_nofile    2048;

error_log   /var/log/nginx/error.log warn;

pid        /var/run/nginx.pid;

events {
    #worker_rlimit_nofile と同じ値に
    worker_connections   2048;
    use epoll;
    multi_accept off;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    server_tokens off;

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

    sendfile       on;
    tcp_nopush     on;
    tcp_nodelay    on;

    #concrete5のインストール時にタイムアウトするようなら伸ばす
    keepalive_timeout   60;

    # gzip setting #
    gzip              off;
    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   2;
    gzip_proxied      any;
    gzip_vary         on;
    gzip_buffers      4 8k;
    gzip_min_length   1100;


##### hogehoge.com #####
    server {
        listen       80;
        server_name  hogehoge.com;

        charset      utf-8;

        access_log   /var/log/nginx/hogehoge.com_access.log main;
        error_log    /var/log/nginx/hogehoge.com_error.log warn;

        error_page   404              /404.html;

        error_page   500 502 503 504  /50x.html;

        root   /var/www/vhosts/hogehoge.com;

        location / {
            index  index.php;
            if (!-e $request_filename) {
            rewrite ^ /index.php last;
            }
        }   

        location ~ \.php($|/) {
             include       /usr/local/nginx/conf/fastcgi_params;

             fastcgi_pass  unix:/var/run/php-fpm/www.sock;
             fastcgi_index index.php;
             fastcgi_param URI $uri;
             fastcgi_param SERVER_NAME $host;
         fastcgi_param REQUEST_METHOD $request_method;
             fastcgi_param SCRIPT_FILENAME /var/www/vhosts/hogehoge.com$fastcgi_script_name;
         fastcgi_read_timeout 30;
        }

     location ~ /\.ht {
         deny all;
     }
   }

##### URLの統合 #####
    server {
        listen       80;
        server_name  www.hogehoge.com;
        rewrite      ^  http://hogehoge.com$request_uri?;
        #wwwアリで接続がくると、wwwなしにリライト
    }

}

Nginxの起動

コマンド
/etc/init.d/nginx start

Nginxの自動起動

コマンド
chkconfig nginx on

PHP

PHPのインストール

コマンド
yum install php55-mbstring.x86_64 php55-mysqlnd.x86_64 php55-common.x86_64 php55-devel.x86_64 php55-fpm.x86_64 php55-gd.x86_64

PHP-FPMの設定

/etc/php-fpm-5.5.d/www.conf
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/www.sock
;UNIXSCKETを利用

;listen.owner = nobody
listen.owner = nginx
;listen.group = nobody
listen.group = nginx
listen.mode = 0660

;user = apache
user = nginx
;group = apache
group = nginx

PHP-FPMの起動

コマンド
/etc/init.d/php-fpm start

PHP-FPMの自動起動

コマンド
chkconfig php-fpm on

MySQL

MySQLのインストール

コマンド
yum install mysql55.x86_64 mysql55-common.x86_64 mysql55-devel.x86_64 mysql55-server.x86_64

MySQLの起動

コマンド
/etc/init.d/mysqld start

MySQLの自動起動

コマンド
chkconfig mysqld on

MySQLのrootパスワードの設定

コマンド
/usr/bin/mysqladmin -u root password "hogehogehogehoge"

concrete5用のDB作成

MySQLにrootでログイン

コマンド
mysql -u root -p

password: #先程作成したrootのパスワードを入力

MySQLコマンドにてDBの作成

  • 以下の名前でMySQLのDBを作成 ※環境に合わせて変更してください。後で使うので控えてね!
    • サーバアドレス:localhost
    • MySQLユーザ名:concrete5
    • MySQLパスワード:hogehogehogehoge
    • MySQLデータベース名:concrete5_db
MySQLコマンド
create database concrete5_db;
GRANT ALL ON concrete5_db.* TO concrete5@localhost IDENTIFIED BY "hogehogehogehoge";
flush privileges;

concrete5のインストール

concrete5のダウンロード

コマンド
cd /usr/local/src
wget http://www.concrete5.org/download_file/-/view/73241/
mv index.html concrete5.7.2.1.zip
unzip concrete5.7.2.1.zip
cp -rp concrete5.7.2.1 /var/www/vhosts/hogehoge.com

concrete5の初期設定

※ドメインが通ってる前提です。

  • ブラウザで[hogehoge.com]にアクセス
  • concrete5の初期設定画面で以下を入力する

    • サイト情報は任意
    • MySQLデータベース情報
    • サーバアドレス:localhost
    • MySQLユーザ名:concrete5
    • MySQLパスワード:hogehogehogehoge
    • MySQLデータベース名:concrete5_db
  • 上記が終われば静かに完了するまで祈りながら待ちましょう。

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