The following tutorial is done with Ubuntu Lucid 10.04 on Lenovo Thinkpad X200 laptop. In this tutorial, I will show you the shortest and easiest way to set up nginx up with PHP5, MySQL and phpmyadmin running through FastCGI.
UPDATE: I am going to do another post on nginx installation, but this time with PHP-FM instead of spawn-fcgi, this new piece of software has gained attention recently. Stay tuned guys!
Install all softwares:
sudo apt-get install nginx mysql-server-5.1 php5-cgi php5-mysql phpmyadmin
Make sure you set up the MySQL root password.
Create php-fastcgi init script:
sudo nano /etc/init.d/php-fastcgi
Inside, paste the following code into it:
#!/bin/bash BIND=127.0.0.1:9000 USER=www-data PHP_FCGI_CHILDREN=15 PHP_FCGI_MAX_REQUESTS=1000 PHP_CGI=/usr/bin/php-cgi PHP_CGI_NAME=`basename $PHP_CGI` PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND" RETVAL=0 start() { echo -n "Starting PHP FastCGI: " start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS RETVAL=$? echo "$PHP_CGI_NAME." } stop() { echo -n "Stopping PHP FastCGI: " killall -q -w -u $USER $PHP_CGI RETVAL=$? echo "$PHP_CGI_NAME." } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "Usage: php-fastcgi {start|stop|restart}" exit 1 ;; esac exit $RETVAL
Next we make the script executable and make it auto-startup by default.
sudo chmod +x /etc/init.d/php-fastcgi sudo service php-fastcgi start sudo update-rc.d php-fastcgi defaults
Create virtual host file for phpmyadmin
sudo nano /etc/nginx/sites-available/phpmyadmin
The content is
server{ listen 80; server_name phpmyadmin; access_log /var/log/phpmyadmin.access_log; error_log /var/log/phpmyadmin.error_log; location / { root /usr/share/phpmyadmin; index index.php; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin$fastcgi_script_name; include fastcgi_params; } }
Now we need to enable this vhost
sudo ln -s /etc/nginx/sites-available/phpmyadmin /etc/nginx/sites-enabled/phpmyadmin
sudo nano /etc/hosts
Append the ‘phpmyadmin’ into 127.0.0.1 line
127.0.0.1 localhost phpmyadmin
Now restart the nginx server
sudo service nginx start
Fire up your Firefox and type in http://phpmyadmin. Enjoy!
Thanks, ill try this.
Typo on step 1. mysql-server-5.1
Thanks. Fixed.
Also missing is the installation of nginx.
sudo apt-get install nginx
Jay, he edited without commenting, or he already had it, because I see it in the first line. In fact, it’s the first package he installs.
joneslee85, THANK YOU VERY MUCH! Finally found a tutorial that explains how to get nginx and PHP working. I just needed PHP for some personal testing, not server setup, and well, all other documents were using PHP-FPM or the Lighttpd Spawn-CGI module, which for some reason I couldn’t get to work properly.
Thanks again, and good luck!
thx for this tutorial, but i still have porblem here…
i follow your tutorial and this one too (http://www.howtoforge.com/installing-nginx-with-php5-and-mysql-support-on-debian-lenny). but when i open php file (ex: index.php) it just download it to my PC, not open it on browser as a web!
how to fix this?
thanks before
sorry for my bad English
Hi , Jones!
Thank you for the article , it was really useful.
I found one mishmash: you used destination – source instead of source-destination as a ln‘s params.
Thanks for that, I didn’t pay attention when sitting down and rewritting the step. Fixed in the post.
I have automated nginx installation with php5 support. Here is the script and the article on how to use it http://www.initcron.org/how-tos/autoinstall-nginx-web-server-with-php-on-ubuntu-10-4-lucid/
just look at your script Gourav Shah
@joneslee85, I’m totally new to this, but want to try it out. I heard nginx is for static content. My blog uses buddypress which is a very interactive and dynamic theme. Can I still use nginx? or, what else to add on nginx to work with the dynamic contents?
Pingback: PHPCOE » [Tutorial] Part 1: Installing Nginx, Php-Fpm, MySql, Phpmyadmin and apc on Ubuntu 10.10
After 4 hours of agony, it just worked in seconds after reading this post. Thanks joneslee85!!!
Hi,
I get error at the beginning:
“E: Couldn’t find package nginx”
I think you have not yet enabled Universe or Multiverse repository for apt.
Thanks for a quick reply 😉
Doesn’t Ubuntu enable by default ?
How to enable?
thanks.
got it thanks.
we’ll see how it goes.
Great “how-to”… Worked like a charm…
Thumbs up! 🙂
Cheers 😉
very bad install, you MUST take care of setup and library dir, look at the default config for apache that comes with phpmyadmin. you failed. you failed multiple times, because you are not only doing bad, but you are teaching people bad! Double-FAIL!
I’m no expert or anything but the whole idea of a nginx install is to not have apache installed which takes tons of memory correct? I want to avoid installing apache as much as possible.
Out of curiosity how does going to http://phpmyadmin work?
without some ip in there.. wouldn’t anyone who visits that link visit the same exact page?
This would not allow others to go to the site. That is specific to that machine. For example on your local network if you go to http://phpmyadmin on a different machine it will not take you to the phpmyadmin interface. It is ONLY specific to that computer.
Just a heads up, I was using this and ran into an error “no input file specified” when hitting the url.
After some searching around I found I needed to add the GROUP to the php-cgi config.
so added:
GROUP=www-data
and
PHP_CGI_ARGS=”- USER=$USER GROUP=$GROUP …
Pingback: Creating Debian VM on Parallels, w/ Rails,PHP, RVM, and NGINX | Victory's Awesome
Debian squeeze repos for php-fpm (as alternative to php-fastcgi): http://www.dotdeb.org/2011/01/11/php-5-3-5-now-for-squeeze/
Just add repos to /etc/apt/source.list
apt-get update; apt-get install php5-fpm
/etc/init.d/php5-fpm restart
This is no longer an ideal install as PHP-FPM is now included with PHP 5.3.X+ which is a great FASTCGI Process manager!
I highly recommend NOT creating your own PHP FASTCGI Wrapper and going this route…
Pingback: Ubuntu 10.04TLSにnginx + php-fpmを出来るだけパッケージで構築する方法! | それでも地球はまわっている
Great tutorial, I’ve got one problem though.
I want my phpmyadmin to be located at ‘http://localhost/phpmyadmin’
and not ‘http://phpmyadmin’
Does any1 know how to do this?
Pingback: Build SUT-Kiosk
Pingback: Ubuntu配置ngnix+phpmyadmin | what is the RIA? just it…||咖啡兔
Pingback: Konfigurasi nginx, php, mysql dan phpmyadmin di BlankOn « Layar Hitam
When I install phpmyadmin using apt-get it prompts me whether I have apache or lighttpd but ngnix is not listed so what do I select ?
http://localhost or http://phpmyadmin do nothing (sends me to the website for phpmyadmin)
Here’s what I have in the hosts file:
————-
127.0.0.1 localhost phpmyadmin
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Any help?
Thanks for the article. It worked even now with Ubuntu 11.10!
maybe you sould change :
PHP_FCGI_CHILDREN=15
to:
PHP_FCGI_CHILDREN=5
it used all the memory on my poor 512M vps…..
Hopefully I killed them before too late 🙂
Pingback: From Apache to NginX | TECHiE TALKS
Pingback: PHP, CGI/Perl Script Installation Service
it’s really not working on Debian 6 Squeeze, any help?
It really works! thanks a lot!
It’s not the easiest way to do the thing. BTW, mysql-server5.5 in latest ubuntu for now.
That works perfectly for me, only mysql-5.5 is to be replaced over 5.1.
Great post!
I cannot say if it is working all I see is welcome to nginx. How can I access phpmyadmin?
Very easy. Download phpmyadmin.tar.gz from official site, extract to your localhost folder and hit http://localhost/phpmyadmin 🙂 It works for me. 🙂
It did not still work. The welcome to nginx still shows
I wrote a post on how to install mysqp+php+phpmyadmin+nginx. Might help you. Check: http://minhazulhaque.blogspot.com/2012/08/setup-nginx-php-mysql-server-in-5.html
It’s been a while I haven’t updated this tutorial. I’d recommend you use php-fpm way. Here is the tutorial http://interfacelab.com/nginx-php-fpm-apc-awesome/
I had an error trying to restart the service nginx. This is what I got as output
Restarting nginx: nginx: [emerg] unknown directive “With” in /etc/nginx/sites-enabled/default:68
nginx: configuration file /etc/nginx/nginx.conf test failed
My tutorial seems not up-to-date with latest version of ubuntu/debian. Please try other method, such as php-fpm. http://interfacelab.com/nginx-php-fpm-apc-awesome/
Pingback: Nginx에서 phpmyadmin VirutalHost 설정 하기 » Ilhwan's Blog
Pingback: Ubuntu 10.04TLSにnginx + php-fpmを出来るだけパッケージで構築する方法! | NO AC.Milan, NO LIFE
Not so far I have found new cool tool to work with mySQL on ubuntu – Valentina Studio. Its free edition can do things more than many commercial tools!!
I very recommend check it. http://www.valentina-db.com/en/valentina-studio-overview
Pingback: Some links | Summer and winter and springtime and harvest
Pingback: Install Nginx, Php-Fpm and MySql on Debian - Tidak lebih…… - Catatan Dalam Blog
Pingback: Some links | summer and winter and springtime and harvest