Install Nginx + PHP-CGI on SnowLeopard for a long time don't touch PHP, a little unfamiliar! However, it is imperative to migrate the WEB front-end to PHP!
Here we introduce how to build Nginx + PHP-CGI development environment on Snow Leopard!
With MacPorts, everything is much simpler!
Install Nginx
Sudo port install nginx
If you just want to create a development environment and do not want to start Nginx automatically at startup, run the following command:
Sudo launchctl unload-w/Library/LaunchDaemons/org. macports. nginx. plist
Initialize Nginx configuration
Cd/opt/local/etc/nginx/
Cp fastcgi. conf. example fastcgi. conf
Cp fastcgi_params.example fastcgi_params
Cp nginx. conf. example nginx. conf
Start
Sudo/opt/local/sbin/nginx
Close
Sudo/opt/local/sbin/nginx-s quit
Restart
Sudo/opt/local/sbin/nginx-s reload
Install PHP-CGI
Sudo port install php5 + fastcgi fcgi
Initialize php configuration
Cd/opt/local/etc/php5
Cp php. ini-development php. ini
Start php-cgi
Php-cgi-B 127.0.0.1: 8888
For debugging, it is enough to start a process. to disable it, press ctrl-c.
Adjust Nginx configuration
location ~ \.php$ { root share/nginx/html; fastcgi_pass 127.0.0.1:8888; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /opt/local/share/nginx/html$fastcgi_script_name; include fastcgi_params; }
Note:
The address and port in fastcgi_pass must be consistent with that in php-cgi.
/Opt/local/share/nginx/html in fastcgi_param. this path must be correct. Otherwise, a 404 error will be reported, prompting "No input file specified .".
Compile a test file/opt/local/share/nginx/html/test. php
Restart php-cgi and nginx, and then access http: // localhost/test. php
If you can see the phpinfo table, the nginx + php-cgi development environment with the simplest configuration is complete.