Simple Nginx Setup with PHP
- Install Nginx
]# yum install nginx
- Install php-fpm
]# yum install php54-fpm
- Create a *.conf file for php-fpm
]# cd /etc/php-fpm.d/
]# cp www.conf your-domain.conf
- Setup the your-domain.conf file
]# vim your-domain.conf
- Type
i to enter Edit mode.
- Change the second line
[www] to [your-domain]
- Change line 12 to:
listen = /var/run/php-fpm/your-domain.sock
- Change line 31 to:
listen.owner = nginx
- Change line 32 to:
listen.group = nginx
- Change line 39 to:
user = nginx (do this if you’re running nginx as a proxy to Apache)
- Change line 41 to:
group = nginx (do this if you’re running nginx as a proxy to Apache)
- Type
Esc : wq [enter]
- Modify the default Nginx Config file
]# vim /etc/nginx/nginx.conf
- Change
index index.html index.htm; to index index.html index.htm index.php;
- Type
Esc: wq [enter]
- Setup your virtual host file for nginx
]# cd /etc/nginx/conf.d/
]# vim virtual.conf (This is a new file that will be created)
- Enter all your
server {} info for the domain you’re adding.
- Type
Esc: wq [enter]
- Modify the fastcgi_params file
]# vim /etc/nginx/fastcgi_params
- Add
pastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name; to the list of parameters
- Type
Esc: wq [enter]
- Start the servers
]# /etc/init.d/php-fpm restart
]# /etc/init.d/nginx restart
- Notice any errors, and make the appropriate adjustments.