How to install Nginx with PHP5 and MySQL
Ummmm, I'm going to help you to install Nginx with MySQL and PHP and I will include how to setup PhpMyAdmin.
This will be tut on a Debian based distro so if you use CentOS or some other distro, the config part should be the same but other way to install the package. 😎
Install MySQL services
PHP Code
<?php
apt-get install mysql-server mysql-client
In this process you need to set a mysql password. Keep it secure.. 😁
Install Nginx
PHP Code
<?php
apt-get install nginx
So there it is. you may need to start Nginx, and you do that by doing
PHP Code
<?php
/etc/init.d/nginx start
But that is not all, you also need to add Nginx to your startup. 😈
PHP Code
<?php
update-rc.d nginx defaults
and there we go, if you visit your server you should get up a default Nginx page.
Install PHP5 and configure it
PHP Code
<?php
apt-get install php5-cgi php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-mhash php5-ming php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
next thing we do is change php.ini.
PHP Code
<?php
nano /etc/php5/cgi/php.ini
and find this line : cgi.fix_pathinfo = 1 and make sure its there and uncommented if you can't find it, then add it to the bottom of the file.
install & starting spawn-fcgi
next we do is installing spawn-fcgi.
PHP Code
<?php
apt-get install spawn-fcgi
IF that does not work you need to install lighttpd and remember to take it out of the startup ... (apt-get install lighttpd && update-rc.d -f lighttpd remove).
next we do is starting spawn-fcgi...
PHP Code
<?php
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
And so you don't need to run that command manually at startup, you edit you rc.local file.
and add the line above to it ...
Configure Nginx
Ok, this is the part I HATE.
We need to edit /etc/nginx/sites-available/default...
PHP Code
<?php
nano /etc/nginx/sites-available/default
and change from
Server {
listen 80;
CRAAP
}
to this :
Quote:server {
listen 80;
server_name _;
access_log /var/log/nginx/localhost.access.log;
location / {
root /var/www/;
index index.php index.html index.htm;
}
location /doc {
root /usr/share;
autoindex on;
allow 127.0.0.1;
deny all;
}
location /images {
root /usr/share;
autoindex on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
Then restart Nginx and try the PHP out. Now, Nginx with PHP + MYSQL should be up...
PHP Code
<?php
/etc/init.d/nginx restart
Installing PhpMyAdmin
Lets install phpmyadmin first.
PHP Code
<?php
apt-get install phpmyadmin
and then edit default again.
PHP Code
<?php
nano /etc/nginx/sites-available/default
and add this above "# deny access to .htaccess files, if Apache's document root"
Quote: location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param HTTPS on; # <-- add this line
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_scri$
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|x$
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
Then restart nginx and test SERVERIP/phpmyadmin 🤗
PHP Code
<?php
/etc/init.d/nginx restart
And everything should be up and running. If not comment or PM me and I will try to help any way I can. ✌