phpenv + php-build ã使ã£ã¦ 5.3 㨠5.4 ãå ±åããã¤ã¤ php-fpm ã使ã
ã£ã¦ãã話ãªãã§ãããåæã¨ãã¦ã phpenv + php-build ã¯ä»ã«ãå¤ãã®æ¹ãèªã£ã¦ãã®ã§ããã¡ããåèã«ããããããåãåèã«ããã¦ããã ãã¾ããããããã¨ããããã¾ãããããå®ãã¨ã¯ãããã㧠PHP 5.4 ã®ããã«VPS1å°åããã¨ãã£ã¦ãã¨ããªããªã£ã¦ããã£ãã§ããã¨ããã @yuya_takeyama ããã®ãããã§ããããã¨ããããã¾ãã
ãªãã§ããããã¼ã£ã¨ãä½ãã®ã¯ã ãããWebã¢ããªã§ãcli ã® php ãè¤æ°ãã¼ã¸ã§ã³ãããããã®ã¯å¤§å¤å¬ãããã©ããã ãã 㨠PHP 5.4 ãªã built-in server ããããããããã© PHP 5.3 ã®éçºã¨ãå°ããã£ã¦ãã¨ã§ãphp-fpm ãå
¥ãããã¨æãã¾ãã
æµã
- enable-fpm 㧠php-build ãã
- ãã㪠fpm ããã»ã¹ãç«ã¡ä¸ãã
- nginx ã¨ãè¨å®ãã
enable-fpm 㧠php-build ãã
ã¾ããphp-build ããã®ã«ã¹ã¿ã ãªè¨å®ãã¤ããã¾ãã5.4.0s ã§ã¤ããã¾ããs-suffix 㯠sotarok ã® s ã§ãã
$ v ~/.php-build/share/php-build/definitions/5.4.0s
å 容ã¯ãããªããããå ¨é¨å ¥ãã§ããconfigure_option ãããããã§ããã©ã --enable-fpm ã ãããã°ãããã§ããã©ã --with-mysql-sock=/tmp/mysql.sock ã¨ãããã¦ãã®ã¯å¥½ã¿ã®åé¡ãªã®ã§ããããªãã¦ãè¯ãã¯ãã§ãã
configure_option "--enable-fpm --enable-fileinfo --enable-hash --enable-json --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-bcmath --with-bz2 --enable-ctype --with-iconv --enable-ftp --with-gettext --enable-mbstring --with-onig=/usr --with-pcre-regex --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --enable-phar --enable-shmop --enable-sockets --enable-simplexml --enable-dom --with-libxml-dir=/usr --enable-tokenizer --with-zlib --with-kerberos=/usr --with-openssl=/usr --enable-soap --enable-zip --with-mhash=yes --without-mm --with-enchant=/usr --with-zlib-dir=/usr --with-gd --enable-gd-native-ttf --with-gmp=/usr --with-jpeg-dir=/usr --with-xpm-dir=/usr/X11R6 --with-png-dir=/usr --with-freetype-dir=/usr --with-imap=/usr --with-imap-ssl --enable-intl --with-t1lib=/usr --with-mcrypt=/usr --with-snmp=/usr" install_package "http://www.php.net/distributions/php-5.4.0.tar.bz2" install_pyrus install_xdebug_master
ã§ããããæå®ãã¦ã¤ã³ã¹ãã¼ã«
$ php-build 5.4.0s ~/.phpenv/versions/5.4.0s
ã¨ããã§ãããããã°ãphp-build ã install_pyrus ã§ã³ã±ãç¾è±¡ãåãã£ã¦ããããã°ã£ã¦ãã¨ã§ install_pyrus ã¾ããã«ãã°ãä»è¾¼ãã§ãã¨åããããã¦ãªããåå ãç¹å®ã§ããªãã£ãã§ãã
ã¡ãªã¿ã«ãinstall_pyrus ã£ã¦ php ãã«ãããå¾ã«å®è¡ããããã§ããããã«ã³ã±ãã¨ãphp æ¬ä½ã® make ã¯æåãã¦ãã®ã«ããã¾ãã㨠cleanup ããã¡ããã£ã¦ããä»æ§ã«ãªã£ã¦ã¦æ²ããæããããã®ã§ã cleanup å¦çã¯ã³ã¡ã³ãã¢ã¦ããã¡ãã£ã¦ã¾ãã
428 # Handles build errors, and displays the last 10 lines 429 # of the build log. 430 function build_error { 431 { 432 echo 433 echo "BUILD ERROR" 434 echo $(tail -n10 "$LOG_PATH") 435 echo 436 echo "The full Log is available here ${LOG_PATH}" 437 echo 438 } >&3 439 440 # Removes the prefix when the build fails. 441 #cleanup_abort # âãããã³ã¡ã³ãã¢ã¦ããã¦ã 442 }
PHP-FPM ã®è¨å®
話ãããã¾ããã
ã§ãphp-fpm ã¤ãã§ãã«ããã§ããã¨ã以ä¸ã®ããã« sbin/php-fpm ãçæããã¾ãã
$ ls -la .phpenv/versions/5.4.0s/sbin/php-fpm -rwxr-xr-x 1 sotarok sotarok 31055874 2012-05-02 00:38 .phpenv/versions/5.4.0s/sbin/php-fpm
ããã¤ãããããã«å®è¡ãã¦ã¿ãã¨ã
$ cd .phpenv/versions/5.4.0s $ ./sbin/php-fpm [22-May-2012 16:16:27] ERROR: failed to open configuration file '/home/sotarok/.phpenv/versions/5.4.0s/etc/php-fpm.conf': No such file or directory (2) [22-May-2012 16:16:27] ERROR: failed to load configuration file '/home/sotarok/.phpenv/versions/5.4.0s/etc/php-fpm.conf' [22-May-2012 16:16:27] ERROR: FPM initialization failed
php-fpm.conf ã¤ãããªãããããªãæãããã¾ãã(php-build ã§ãªããã²ã£ããã¦ã¤ããã°ãããã§ãããå¤åãé¢åã ããè¦ã¦ãªããã©ãå¤åããã)
ã£ã¦ãã¨ã§ã ~/.phpenv/versions/5.4.0s/etc/php-fpm.conf ã« é©å½ã«ãã¡ã¤ã«ãä½æãã¾ãã
- https://gist.github.com/2767859
- path ã¨ãé©å½ã«å¤ãã¦ãã ããã
- ãããã°ã®ããã«ã daemonize = no ã¨ãã«è¨å®ãã¦ã¾ãããã®ã»ããåèµ·åã¨ã楽ãªã®ã§ãã§ãããããã¨ã¿ã¼ããã«ã¨ããã¡ãããã§ããã©ãã©ã£ã¡ã«ãã screen ã§1ã¤ãããã¦ã¡ããã°ããã ãã®ã¯ãªãã§ã
- listen ã 127.0.0.1:9002 ã¨ãã«ãã¦ã¾ã
ãã¨ã¯... ãããã¨ããã ããªããé©å½ãªä½ç½®ã«ãã°ãããã¾ãããã ~/var/log ã¨ããªãã£ããã¤ãã£ã¦ãã ãã
ã§ãèµ·åï¼
$ ~/.phpenv/versions/5.4.0s/sbin/php-fpm [22-May-2012 18:44:48] WARNING: [pool www] 'user' directive is ignored when FPM is not running as root [22-May-2012 18:44:48] WARNING: [pool www] 'group' directive is ignored when FPM is not running as root [22-May-2012 18:44:48] NOTICE: fpm is running, pid 787 [22-May-2012 18:44:48] NOTICE: ready to handle connections
pool ã® user, group 㯠root ãããªãã¨ããããªããã¼ã£ã¦è¦åã§ããã§ãããã³ã¡ã³ãã¢ã¦ãããã¨ãèµ·åããªãã§ããroot ã§ã¯åãããªãã®ã§ãã¾ããé©å½ã§ãã
ã§ããã㧠fastcgi ã§åãä»ããæºåãã§ãã¾ããã
nginx ã®è¨å®ã¨ã
127.0.0.1:9002 ã§åãä»ãã upstream ãå®ç¾©ãã¾ãã
upstream php54 { server 127.0.0.1:9002; } # {{{ z.merlot.strk.jp; server { listen 80; server_name z.merlot.strk.jp; index index.php; root /usr/local/var/www/z.merlot.strk.jp/public; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php$1 last; } } location ~ \.php.*$ { fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_pass php54; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; } } # }}}
ã§ãåèµ·åã
z.merlot.strk.jp ã«ã¢ã¯ã»ã¹ããã¨ã
ãã¨ã¯
5.3.13 ã¨ããåãæ¹æ³ã§ã¤ãã£ã¦ãfpm 㯠listen port ããã¦ãnginx ã®è¨å®ã§ãããã¤ãæå®ããã°ããã§ããã
upstream php53 { server 127.0.0.1:9003; } # {{{ p.merlot.strk.jp; server { listen 80; server_name p.merlot.strk.jp; # .. (snip) location ~ \.php.*$ { # .. (snip) fastcgi_pass php53; # .. (snip) } } # }}}
ããã§å¿«é©ã« fpm ç°å¢ã®ãã¹ããã§ããããphpenv ã¤ãã£ããã®ã®ãphpenv ã§ãã¼ã¸ã§ã³ãåãæ¿ããå¿
è¦ãããªããport ãæå®ãã¦å¥ã® php-fpm ããã»ã¹ããã¡ããã¦ããã°ã幸ãã«è¤æ°ãã¼ã¸ã§ã³ã§éçºããããããããããã¹ãå¥ã«åããã®ã¯ãã nginx ã®è¨å®ã§é©å½ã«ããã°ããã®ã§ã楽ãã³ã§ãã
enjoy it!