macportでnginx/php5.4/phpmyadminを動かすまでザザーッと

php5.4のインストール

$ sudo port install php54
$ sudo port install php54-cgi
$ sudo port install php54-mbstring
$ sudo port install php54-curl
$ sudo port install php54-mcrypt
$ sudo port install php54-mysql

うちで出たエラーは下記の通り。対処も同時に。

エラー対処:

$ sudo port install php54
Error: Target org.macports.activate returned: Image error: /opt/local/bin/captoinfo is being used by the active ncursesw port.  Please deactivate this port first, or use 'port -f activate ncurses' to force the activation.
$ sudo port -f uninstall ncursesw

エラー対処:

$ sudo port install php54
Log for perl5 is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_perl5/perl5/main.log
$ sudo port installed perl
$ sudo port -f perl5 @5.8.9_0
$ sudo port -f perl5 @5.12.3_1+perl5_12
$ sudo port -f perl5.8 @5.8.9_3
$ sudo port -f perl5.12 @5.12.4_0

spawn-fcgi/nginxのインストール

$ sudo port install nginx
$ sudo port install spawn-fcgi

mysql5のインストール

$ sudo port install mysql5-server
$ sudo /opt/local/bin/mysql_install_db5

普通に起動するとエラーが出るので下記のように設定変更。
_mysqlの権限を与える必要があります。

$ sudo cd /opt/local/var/db/mysql5
$ sudo chown _mysql:_mysql mysql
$ sudo /opt/local/lib/mysql5/bin/mysqld_safe & # mysql5起動

mysql5の起動とパスワードの設定

$ sudo /opt/local/lib/mysql5/bin/mysqld_safe &
$ sudo /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'

spawn-cgiを使ってphp-cgiの待ち構え設定

$ sudo vim /bin/php-fastcgi-start

ファイルphp-fastcgi-startの内容:

#! /bin/bash
/opt/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 3 -f /opt/local/bin/php-cgi54
$ sudo /bin/php-fastcgi-start

php.initの設定

$ sudo cd /opt/local/etc/php54
$ sudo cp php.ini-development php.ini
$ sudo vim /opt/local/etc/php54/php.ini
pdo_mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
date.timezone = Asia/Tokyo


nginxの設定

$ sudo cd /opt/local/etc/nginx
$ sudo mv nginx.conf.example nginx.conf
$ sudo mv fastcgi_params.example fastcgi_params
$ sudo mv scgi_params.example scgi_params
$ sudo mv mime.types.example mime.types
$ sudo mv uwsgi_params.example uwsgi_params
$ sudo vim /opt/local/etc/nginx/nginx.conf

ファイルnginx.confの内容:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}
http {
    include /opt/local/etc/nginx/mime.types;
    sendfile on;
    keepalive_timeout  65;
    #gzip  on;
    include /opt/local/etc/nginx/sites-enabled/*;
}
$ sudo mkdir /opt/local/etc/nginx/sites-enabled
$ sudo vim /opt/local/etc/nginx/sites-enabled/localhost

ファイルlocalhostの内容:

server {

    listen 80;
    server_name localhost;
    access_log /opt/local/var/log/nginx/localhost.log;
    error_log /opt/local/var/log/nginx/localhost.error.log;
    root /opt/local/var/www;
    index index.php;

    location /phpmyadmin {
        alias /opt/local/share/phpmyadmin;
        index index.php;
    }
    location ~ /phpmyadmin/.*\.php$ {
        include /opt/local/etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /opt/local/share/$uri;
    }
    location ~ ^/.+\.php(/.*)?$ {
        set $script $uri;
        set $path_info "";
        if ($uri ~ "^(.+\.php)(/.+)") {
          set $script $1;
          set $path_info $2;
        }
        fastcgi_pass 127.0.0.1:9000;
        include /opt/local/etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_NAME $script;
        fastcgi_param SCRIPT_FILENAME /opt/local/var/www$script;
        fastcgi_param PATH_INFO $path_info;
    }

}

nginx起動

$ sudo /opt/local/sbin/nginx


phpmyadminの準備

visit:
http://www.phpmyadmin.net/home_page/downloads.php

$ sudo cd /opt/local/share
$ sudo wget http://downloadhost/phpMyAdmin-3.5.1-all-languages.tar.gz

$ sudo tar zxvf phpMyAdmin-3.5.1-all-languages.tar.gz
$ sudo mv phpMyAdmin-3.5.1-all-languages phpmyadmin

$ sudo mv config.sample.inc.php config.inc.php
$ sudo vim config.inc.php


メモ:nginxやphp-cgi, mysqlの落とし方など

$ sudo nginx -s reload
$ sudo killall php-cgi54
$ sudo /opt/local/bin/mysqladmin5 -u root shutdown