ãµã¼ãã¹åæé ï¼Windowsçnginxã»PHP8ã®ã¤ã³ã¹ãã¼ã«(2024å¹´9æçï¼
ç®æ¬¡
- Windowsçnginxã»PHP8ã®ã¤ã³ã¹ãã¼ã«ã»ãµã¼ãã¹åï¼ï¼ï¼ï¼ï¼å¹´ï¼æï¼
- nginxã®ãã¦ã³ãã¼ãã¨ã¤ã³ã¹ãã¼ã«
- PHP8ã®ãã¦ã³ãã¼ãã¨ã¤ã³ã¹ãã¼ã«
- PHP8ãåããããã®VCã®ã©ã³ã¿ã¤ã
- ãµã¼ãã¹åããã°ã©ã ã®ãã¦ã³ãã¼ãã¨ã³ãã¼
- nginxã®è¨å®
- PHPã®è¨å®
- nginxããµã¼ãã¹å
- php-cgiããµã¼ãã¹å
- ãµã¼ãã¹ã®èµ·å
- åä½ç¢ºèª
Windowsçnginxã»PHP8ã®ã¤ã³ã¹ãã¼ã«ã»ãµã¼ãã¹åï¼ï¼ï¼ï¼ï¼å¹´ï¼æï¼
Windowsä¸ã«nginxã¨PHPããã¦ã³ãã¼ããã¦Windowsã®ãµã¼ãã¹åããæé ã§ãã
2024å¹´9ææç¹ã®æ å ±ã«æ´æ°ãã¾ãã
ç°å¢ã¯ãc:\web2ããã©ã«ãã«ä½ãæ³å®ã§èª¬æã¯ãããã¾ãã
nginxã®ãã¦ã³ãã¼ãã¨ã¤ã³ã¹ãã¼ã«
nginxã®ãã¦ã³ãã¼ãã¯ä»¥ä¸ããè¡ãã¾ãã
ãã®æç¹ã§ã®ææ°çã¯ãnginx/Windows-1.27.1 ãã§ããã
ããããã¦ã³ãã¼ããã¦ã解åãã¾ãã
解åããã¨ãã©ã«ãã«ãã¼ã¸ã§ã³åãã¤ãã¦ããã®ã§ãnginxãã«ãªãã¼ã ãã¾ãã
解åããã¨åãååã®ãã©ã«ãã2層ã§ãã¾ãã
å称å¤æ´ãã¦ãC:\web2ãã©ã«ãã«ç§»åããã®ã¯ãµããã©ã«ãã®ã»ãã§ãã
PHP8ã®ãã¦ã³ãã¼ãã¨ã¤ã³ã¹ãã¼ã«
PHPã®ãã¦ã³ãã¼ãã¯ä»¥ä¸ããè¡ãã¾ãã
ã¡ãã£ã¨ãããã¥ããã§ããããã¦ã³ãã¼ãããã®ã¯ãThreadsafeçã®ZIPã§ãã
æç¹ã®ææ°çã¯ãphp-8.3.11-Win32-vs16-x64.zipãã§ããã
解åå¾ãã©ã«ãåããphpãã«å¤æ´ãããc:\web2ããã©ã«ãã«ç§»åãã¾ãã
ç°åå¾ãphpãã©ã«ãã®ä¸ã«ãlogsããã©ã«ããä½ã£ã¦ããã¾ãã
PHP8ãåããããã®VCã®ã©ã³ã¿ã¤ã
Windowsã®PHPã¯VCã®ã©ã³ã¿ã¤ã ãå¿ è¦ã§ãã
ã¯æ¢ã«ã¯ãã£ã¦ããå ´åã¯ããã¾ããã
ããããªãã¨ãPHPããµã¼ãã¹åãã¦èµ·åããã¨ãã¨ã©ã¼çµäºãã¾ãã
ãµã¼ãã¹åããã°ã©ã ã®ãã¦ã³ãã¼ãã¨ã³ãã¼
nginxã¨PHPã¯Windowsã§ã¯ãã®ã¾ã¾ãµã¼ãã¹åã§ãã¾ããã
winsw.Exeã使ãã¾ãã
ä¸è¨ãããææ°çããã¦ã³ãã¼ããã¾ãã
æç¹ã®ææ°çã¯2.12.0ã§ããã
ã¨ãããããWinSw-x64.exeãããã¦ã³ãã¼ããã¾ãã
ãã¦ã³ãã¼ãããWinSw.exeã¯C:\web2ã«ã³ãã¼ãããnginxãã¨ãphpããã©ã«ãã®ç´ä¸ã«ã³ãã¼ãã¦ããªãã¼ã ãã¾ãã
ä»åã¯ãwinsw_php.exeãã¨ãwinsw_nginx.exeãã«ãã¾ããã
nginxã®è¨å®
nginxãåããæä½éã®è¨å®ããã¾ãã
nginxãã©ã«ãç´ä¸confãã©ã«ãã®ãnginx.confããç·¨éãã¾ãã
â ããã¼ãã¨ãµã¼ãã¼åã®è¨å®
 listen    8090;
 server_name  localhost;
ããã©ã«ãã¯ã80ãã§ãããä»åã¯éçºç°å¢ãªã®ã§ãããã¦ã8090ãã«ãã¾ããã
ãã®è¨å®ã§ããã°ã以ä¸ã®URLã§ã¢ã¯ã»ã¹ã§ãã¾ãã
â¡ãããã¥ã¡ã³ãã«ã¼ãã®è¨å®
HTMLã®ç½®å ´æã§ãã
âhttp://localhost:8090/âã¨ããã¨ãããã¥ã¡ã³ãã«ã¼ãã«æ¢ãã«ããã¾ãã
ããã©ã«ãã¯ãhtmlãã»ã»ã¤ã¾ããnginx\htmlããã©ã«ãã§ãã
以ä¸ã®ä¾ã¯ãC:\web2\src\htdocsããã«ã¼ããã©ã«ãã«å¤æ´ããä¾ã§ãã
location / {
   root  C:/web2/src/htdocs
   index  index.html index.htm; }
â¢ãPHPãCGIã§ä½¿ããããã«ãã
PHPã使ããããã«ããã«ã¯ãlocation ~ \.php$ãã®é¨åã®ã³ã¡ã³ãã¢ã¦ãã#ããæ¶ãã¦æå¹ã«ããå¿ è¦ãããã¾ãã
ä¸è¨ã®ããã¥ã¡ã³ãã«ã¼ãã«æå®ãããã©ã«ãåã«ï¼ã±ææ¸ãæãã¾ãã
location ~ \.php$ {
   root      C:/web2/src/htdocs;
   fastcgi_pass  127.0.0.1:9000;
   fastcgi_index  index.php;
   fastcgi_param  SCRIPT_FILENAME  C:/web2/src/htdocs$fastcgi_script_name;
ã include     fastcgi_params;
 }
æä½éãªãããã ãã§ãã
ï¼æ³¨æç¹ï¼ãã¹åºåãã®æ¸ãæ¹ï¼
ãC:/src/htdocsãã®ããã«ã/ãåºåãã§ãããC:\src\htdocsãã®ããã«ã\ï¼ï¿¥ï¼ãåºåãã®ã©ã¡ãã§ã使ãã¾ããããC:\src\nhtdocsãã¿ããã«ã[\ãã®å¾ãã«ãnããæ¥ããããã¨ãæ¹è¡ã³ã¼ãã¨èªèããã¦ã¨ã©ã¼ã«ãªãããµã¼ãã¹ã®èµ·åã«å¤±æãã¾ãã
ãªã®ã§ãã/ãã«ãã¦ããã®ãå®å ¨ã§ãã
PHPã®è¨å®
php.iniãä½ãå¿ è¦ãããã¾ãã
ã¨ããããåããã ããªããphpãã©ã«ãç´ä¸ã«ãããphp.ini-developmentããããphp.iniãã«ãªãã¼ã ããã°åãã¾ãã
nginxããµã¼ãã¹å
EXEã¨åãååã§XMLãã¡ã¤ã«ãä½ãã¾ãã
winsw_nginx.exeããªããwinsw_nginx.xmlãã®ããã«ãã¾ãã
<service> <id>nginx</id> <name>nginx</name> <description>ãnginxãã§èµ·åããããnginx -s stopãã§åæ¢ããã</description> <logpath>C:\web2\nginx\logs</logpath> <logmode>roll</logmode> <depend></depend> <executable>C:\web2\nginx\nginx.exe</executable> <startarguments></startarguments> <stoparguments>-s stop</stoparguments> </service>
åºæ¬çã«ã¯ãã°ãã©ã«ãã¨nginx.exeã®ãã¹ãç°å¢ã«ãããã¦æ¸ãæãã¦ãã ããã
æºåãã§ããããã³ãã³ãããã³ããã管çè ã§éãã¦ä»¥ä¸ãå®è¡ãã¾ãã
WinSw_nginx.exe install
æåããã¨ä»¥ä¸ã®ãããªã¡ãã»ã¼ã¸ã表示ããã¾ãã
2024-09-07 17:47:07,959 INFO Â - Installing service 'nginx (nginx)'...
2024-09-07 17:47:08,038 INFO Â - Service 'nginx (nginx)' was installed successfully.
php-cgiããµã¼ãã¹å
EXEã¨åãååã§XMLãã¡ã¤ã«ãä½ãã¾ãã
<service> <id>php-cgi</id> <name>php-cgi</name> <description>ãphp-cgi -b 127.0.0.1:9000 -qããå®è¡ãã</description> <logpath>C:\web2\php\logs</logpath> <logmode>roll</logmode> <depend></depend> <executable>C:\web2\php\php-cgi.exe</executable> <startarguments>-b 127.0.0.1:9000 -q</startarguments> </service>
PHPãã©ã«ãç´ä¸ã«ãlogsããã©ã«ããä½ãåæã§æ¸ãã¦ããã®ã§ããªãå ´åã¯å¤æ´ãã¦ãã ãããä»ã®exeã®ãã¹ãªã©ã¯ç°å¢ã«ãããã¦æ¸ãæãã¦ãã ããã
æºåãã§ããããã³ãã³ãããã³ããã管çè ã§éãã¦ä»¥ä¸ãå®è¡ãã¾ãã
WinSw_php.exe install
æåããã¨ä»¥ä¸ã®ãããªã¡ãã»ã¼ã¸ã表示ããã¾ãã
2024-09-07 17:49:01,691 INFO Â - Installing service 'php-cgi (php-cgi)'...
2024-09-07 17:49:01,775 INFO Â - Service 'php-cgi (php-cgi)' was installed successfully.
ãµã¼ãã¹ã®èµ·å
ãµã¼ãã¹ãèµ·åãã¾ãã
ãã¡ã¤ã«åãæå®ãã¦å®è¡ã§ãservices.mscãããã¤ã¨ã以ä¸ã®ãããªç»é¢ãç«ã¡ä¸ãã£ã¦ãã¾ãã
ããã§ãnginxã¨php-cgiãæ¢ãã¦ãå³ã¯ãªãã¯âéå§ã¨ããã°ãå®è¡ä¸ã®ã¹ãã¼ã¿ã¹ã«ãªãã¾ãã
ããã§åããæºåã¯OKã§ãã
åä½ç¢ºèª
ãã§ã«ã½ã¼ã¹ãããå ´åã¯ããã使ãã¾ãã
ãªãå ´åã¯ãããã¥ã¡ã³ãã«ã¼ãã«æå®ãããã©ã«ãã«ã以ä¸ã®å 容ãã³ãã¼ãã¦ãindex.phpãã®ååã§ä¿åãã¾ãã
<?php
phpinfo();
 ?>
ãã©ã¦ã¶ã§ä»¥ä¸ã®URLããããã¾ãã
ããã§ã以ä¸ã®ããã«è¡¨ç¤ºãããã°OKã§ãã
ã§ã¯ã§ã¯ã