俺ããã£ã¦ã¿ããã£ãh2oã¨phpã®æ§æã«ã¤ãã¦
ãã£ã¨æãã§ããã®ã§ãã£ã¦ã¿ã¾ããã
ã¨ããã§ãããããããªããMicrosoftã®çºè¡¨è¦ã¦ãããã§ããããã¸ã§ããããSurface bookã¨ãLumiaã¨ãå®éã«ã¢ããè¦ã¦ã¿ãªãã¨ãªãã¨ããããªããã©ããã¬ã¼ã³ã ãã§ããã°å®å ¨ã«Appleè¶ãããã¬ã¼ã³ã ã£ãâ¦ããªãã¦ããããä¹ ã ã«çºè¡¨ã§çãä¸ãã£ãï¼
ãã¦ãã
PHPã®ãµã¼ãã¼æ§ç¯ãã·ã¥ãã¨ããã®ãå人çã«ã¯çµæ§é¢å*1ãçç±ã¯ããã¤ãããããã©
- ãä»è¨èªã®æè¦ã§ãã¦ã§ãã¢ããªãè¤æ°åãåä¸ã®ãµã¼ãã¼ï¼ã¨ããããããã¼ãã£ã«ãã¡ã¤ã³ï¼ã§åããæããã¡ã©ã¿ãããªhtdocsãä½ããã¡ã«ãªããéæ³ã¿ãããªconfãæ¸ããã¡ã«ãªãã
- nginx+Nåã®Apacheï¼PHPããã¦ãã°è§£æ±ºããå ´åãããã ãapacheã¯è¤æ°é£¼ãã®ã¯é¢åã
- phpã®ãã¼ã¸ã§ã³ãä¸ãããä¸ãããå ±åãããããé¢åï¼ããããã£ãäºã ãï¼ãApacheã ã¨ããã«é¢åï¼apxsããã©ãï¼
- ãã£ã±ãhttpdã欲ãããfastcgiã ãã§ã¯URLã®baseãå¤ãããããªrewriteã¯è¨å®é¢å
- ã¨ã«ãããã£ããåãåããããï¼ï¼
ã¨ããæãã
ä»ã®è¨èªã®ä¸çã§ã¯å¤§ä½supervisordã¨ãã§èµ·åãããhttpdãããã£ã¦ãã¦ä¸ã«nginxããã¶ããæãã§ãããPHPããããã風ã«ãããï¼ï¼ï¼ã¨æãã¤ã¤å¹¾æ°å¹´ã
ããã§æ°ã«ãªã£ã¦ããã®ãh2o+php-cgiãh2oãªã軽éã«ãç°¡åã«phpã管çã§ããã®ã§ã¯â¦ï¼
PHPã«ã³ãã¡ã¬ã³ã¹ãããã£ããï¼ã¾ã ããã°æ¸ãã¦ç¡ãï¼ãã£ã¨è©¦ããã以ä¸ã¯ãã®æé ã§ããã
ããããæ§æã¯ã©ããï¼ã¨ãããã¨ã§ãã
ããã»ã¹ã®è¦ªåé¢ä¿çã«ã¯
(systemd) -> supervisord -> ( H2O -> PHP(php-cgi) )
å¤ããè¦ãã¨ãã¯phpãh2oã§wrapãããã¨ã§ãphpèªä½ãhttpdããã£ã¦ããããªè¦ãæ¹ã«ãããã
ãã¡ã¤ã«ã¯ãåºæ¬çã«/opt
ã®ä¸ã«å
¨é¨ãã¯ãã£ã¦ããã
/opt /php PHPã®ä¸ååå /h2o h2oã®ä¸ååå /logs /sites/_/htdocs ï¼ã¾ãã©ãã§ãããï¼
æé
â» ããã¯Ubuntu 15ã§ã®ä¾ã§ãã
apt-get -y install libcurl4-openssl-dev libmcrypt-dev libreadline-dev libtidy-dev cmake git build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev openssl libssl-dev libxml2-dev libgd-dev libxslt-dev libxml2-dev libgd-dev mkdir -p /opt/src mkdir -p /opt/logs chmod 777 /opt/logs mkdir -p /opt/site/_/htdocs echo "<?php phpinfo();" > /opt/site/_/htdocs/index.php # h2o ã®ãã«ã cd /opt/src/ wget https://github.com/h2o/h2o/archive/v1.5.0.tar.gz tar xvzf v1.5.0.tar.gz cd h2o-1.5.0/ cmake -DWITH_BUNDLED_SSL=on -DCMAKE_INSTALL_PREFIX=/opt/h2o . make make install # phpã®ãã«ã cd /opt/src wget https://downloads.php.net/~ab/php-7.0.0RC4.tar.gz tar xvzf php-7.0.0RC4.tar.gz cd php-7.0.0RC4/ ./configure --prefix=/opt/php/ --with-gd --enable-sockets --with-jpeg-dir=/usr --with-png-dir=/usr --enable-exif --enable-zip --with-zlib --with-zlib-dir=/usr --with-kerberos --with-openssl --with-mcrypt=/usr --enable-soap --enable-xmlreader --with-xsl --enable-ftp --enable-cgi --with-curl=/usr --with-tidy --with-xmlrpc --enable-sysvsem --enable-sysvshm --enable-shmop --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --enable-pcntl --with-readline --enable-mbstring --disable-debug --enable-fpm --enable-bcmath make make install
vi /opt/h2o/h2o.conf
pid-file: /opt/logs/h2o.pid access-log: /opt/logs/access.log error-log: /opt/logs/error.log user: nobody listen: 80 file.custom-handler: extension: .php fastcgi.spawn: "PHP_FCGI_CHILDREN=32 exec /opt/php/bin/php-cgi" hosts: "localhost:80": paths: /: file.dir: /opt/site/_/htdocs redirect: url: /index.php internal: YES status: 307
ããã§ãã¨ããããèµ·åã§ããããã¹ãã以ä¸ã³ãã³ãã§h2oãèµ·ããã¦ããã©ã¦ã¶ã§éãã¦phpinfoãã§ã¦ããã°OKã
/opt/h2o/bin/h2o -c /opt/h2o/h2o.conf
åé¡ãªããã°supervisordã§ãã¼ã¢ã³åã
apt-get -y install supervisor
vi /etc/supervisor/conf.d/h2o.conf
[program:h2o] command=/opt/h2o/bin/h2o -c /opt/h2o/h2o.conf autorestart=true
service supervisor restart
å®äºã
å人çã«ã¯ã¹ã¼ãã¼ã·ã³ãã«ã§ããã
ããã»ã¹ã¯ãããªæãã«ãªã
ââsupervisordâââh2oââ¬âperlâââphp-cgiâââ10*[php-cgi] â ââperl â ââ2*[{h2o}]
ã¾ã¨ã
- ã¢ããªã®æ°ã ãh2o.confã¨supervisordã®è¨å®ãæ¸ãã°ãè¤æ°ã®PHPã¢ããªã®ãµã¼ãã¼*2ãä»ã®è¨èªã£ã½ã管çã§ããã
- phpã
/opt/php
ã«å ¨é¨åºã¾ã£ã¦ããã®ã§è¦éãå®ãããå·®ãæ¿ãããã*3ãphp-buildã¨ãã®ç¸æ§è¯ãã¨æãã - ã¤ã¾ããã¿ã¬åï¼èªååï½ï¼ãããã
- H2Oãã¤ããã¨ãphp-fpmãã¤ãããªãã§ãphpããã»ã¹ã管çã§ããã®ã§ãå®è³ªh2oã ãç¸æããã°ãã
- supervisordã§h2oãèµ·åãã¦ããã®ã§ãinitãupstartãsystemdã®æ··ä¹±ã«å ¥ããã«æ¸ã
å®éç¨ã§ã¯ãããã«ãã®ä¸ã«nginxããã¶ããæããæ³å®ãã¦ããã
ãh2oã§é ä¿¡ããã°HTTP/2ã§ãããããï¼æã¡è ãã§ã¯ï¼ãã¨ããã®ã¯ãããªã®ã ããå®éç¨ã§ã¯ãã¯ãããã¡ãã£ã¨åé¨ã«æè»æ§ãã»ãã*4
課é¡ã¨å±æ
- ãã°ãã©ããã£ã¦ç®¡çãã£ããªã¼â¦ï¼
- ç°å¢å¤æ°ã¨ãã§PHPãã¤ããªãã³ã³ãã£ã°ãã·ã¥ãã£ã¨åãæããããã¦ã¿ããããã£ã¨phpãåãªãããã»ã¹ã¨ãã¦ãã¤ããããã
- ã¾ã æ¬çªã§ã¯ãã®æ§æã§éç¨ãã¦ã¿ã¦ãªããä»åº¦ãã£ã¦ã¿ãäºå®ã
- ä»æ°ä»ãã¦ããã®ããh2oã®fastcgi.spawnã¯backlogãå°ãªãï¼ï¼ï¼ã®ã§ãPHP_FCGI_CHILDREN(PHPããã»ã¹ã®æ°)ãå°ãªãããã¨ã100ã¨ã200ã¨ãåææ¥ç¶ãå¢ãããã¨ãã«ãã¼ã¡ã¼ã¡ã¨ã©ã¼ãã§ããéã«PHP_FCGI_CHILDRENããµãããã解決ããããã©ãã®ã¨ãããããã£ããå¾ ã¡è¡åã伸ã°ããã®ãï¼
- ï¼ã¨ã¯ãããç§ããããããªã¡ã¼ã«ãã©ã¼ã æ¡ä»¶ã¨ãã§åææ¥ç¶æ°100ã¨ãæ» å¤ã«ç¡ããã並ã¹ãã°ããã®ã§åé¡ã«ã¯ãªããªãï¼
ãã¡ãããã¯ä»¥ä¸ã§ãããæè¦ãå¾ ã¡ãã¦ããã¾ãã