Alright, so here it is I will share the manual method how to install Nginx web server and PHP5 on a server running either Ubuntu or Debian. For your information, I posted tutorials how to easily and (almost) automatically install Nginx, PHP and MySQL using Tuxlite script. You can read the tutorial here. I also already shared how to manually install Apache and PHP. Before we proceed, lets talk a bit about Nginx.
Pronounced as “Engine X”, Nginx is an HTTP and reverse proxy server. Its main function is just like Apache but it is just better. It works as a web server but with various advantages compared to Apache. Personally, my first introduction with Nginx is when I was searching for a fix for my Apache-related problems. Then I read a discussion forum where one of its member said: “You better ditch Apache and start using Nginx”. So I became curious and start trying and learning Nginx since then.
So many users say Nginx is better, faster and lighter than standard Apache. The only rival of Nginx so far is LiteSpeed which is unfortunately not free. As I read in several sources, there are many users already claiming that a combination of Nginx with another technology like Varnish Cache can deliver ultra-fast performance. They claimed such technology can out-perform LiteSpeed.
p.s: Every time I say “server” it can refer to both VPS or Dedicated server.
Anyway, you will never know except if you tried it. So, let’s get it on..
What you’ll need
- A server with Ubuntu or Debian running on it. In this example I use Ubuntu 12.04 (see my playground server)
- A basic knowledge about common commands used in Linux
- Putty tool for Windows or Terminal app in Linux or Mac
- You may also need some basic tweaks for initial setup of your Ubuntu server.
- About 20 minutes of your time.
How To Install Nginx and PHP5
Step 1 – Login to your server via SSH and login using your username and password. If you’ve followed our guide for initial server setup (point 4 above) then “root” login should be already disabled. Once logged in, type “su” then hit Enter. You will be asked to enter root password.
However if you can logged in as root, you don’t have to use the “su” command.
Step 2 – Before installing, make sure your server has an up to date repositories. In this case you’ll need to run “apt-get update” command. Anyway, for better experience, you can also add another updated repository. Use commands below to add new repo as I use to get latest version of PHP 5.4 which is claimed much faster, better and more stable.
apt-get install python-software-properties
Screenshot pics for illustration..
Once done, it is time to update the apt. Execute this command:
Just wait till it’s done.
Step 3 – Alright you’ve done well so far. Now use this command below to install PHP5 (v5.4) on your server. PHP is an open source web scripting language used by many people around the web to build and develop dynamic web pages. What I show you below is a command syntax to install PHP5 with most common extensions:
apt-get install php5-common php5-mysql php5-xmlrpc php5-cgi php5-curl php5-gd php5-cli php5-fpm php-apc php-pear php5-dev php5-imap php5-mcrypt
If it asks to confirm, simply answer Yes / Y to continue the process.
Once done, you’ll see something like this..
To make sure you’re getting the right version of PHP we want, run following command to check PHP version installed on your server:
It will give output something like this..
Step 4 – In this step I will show you how to install latest stable version of Nginx. Common syntax to install Nginx is “apt-get install nginx” but this time I will grab Nginx from Ubuntu PPA repo which is maintained by volunteers and it has additional compiled-in modules and may be more fitting for most Ubuntu server.
apt-get install nginx
Sit tight and wait for each process to finish. Some screenshot pics from what I did:
Done. You may also restart Nginx to make sure the service is running:
service nginx restart
Step 5 – Well, basically that’s all. With Nginx as web server and PHP5 installed you can already host a dynamic website but this time not a website with MySQL database. You can host scripts like RapidLeech in it. However if you wish to build / host a blog, you’ll need to firstly install MySQL server on it. Fortunately I’ve covered that in my previous posts. Read:
Finally, you are now having a working Ubuntu server to host your website and blog. Commonly, this kind of setup is called as LNMP (Linux, Nginx, MySQL, PHP) or also LEMP (Linux, Engine X, MySQL, PHP). However if you still feel above steps are too complicated, you can try following my previous method to install Nginx which is much simpler and easier. Have fun!!