Nginx Server Setup with PHP-FPM and MySQL on Ubuntu 14.04

Setting up Nginx with PHP took some serious effort few months ago. It’s much easier now. It shouldn’t take 10 minutes to set up fully functional web server with Nginx and PHP5. This tutorial shows you how to properly setup Nginx server with PHP, MySQL and APC Cache.

This tutorial was tested and worked on Ubuntu 12.04 LTS Ubuntu 14.04. It may work on other Ubuntu versions as well. But I don’t expect to test it on other versions as Ubuntu 14.04 LTS is the latest version. This is a basic setup and it’ll need further configurations to support some CMS such as WordPress or tracking software like Prosper202.

This is an outdated tutorial. Although it should still work perfectly. But in any case, refer to the VPS setup with Virtualmin and nginx tutorial for more modern server set up.

This setup is meant to be deployed on an unmanaged VPS, not on a managed or cPanel enabled server. If you don’t have an unmanaged VPS ready to go, please read Best Unmanaged VPS Hosting Providers for suggestions.

Prepare the Server

We’ll start by removing some packages from server which we don’t use. Run following command on CLI logged in as root.

sudo apt-get purge apache2* bind9* samba*

Update and upgrade the server,

sudo apt-get update

Press Y and hit Enter when asked.

Install PHP-FPM and APC Cache

We’ll now install PHP 5.5.9 on the server. It’s the latest version of PHP (4th October. 2014) and is the fastest version yet. Ubuntu 14.04 comes with PHP 5.5. So we can install it directly from apt. Run following command to install PHP-FPM, APC Cache and other essential PHP modules.

sudo apt-get install php5-mysql php5-xmlrpc php5-cgi php5-curl php5-gd php5-cli php5-fpm php-pear php5-dev php5-imap php5-mcrypt

Confirm it when asked by hitting Y. After few seconds, PHP will be up and running on your server.

Install MySQL

Now that we have PHP running on our server, next step is to install MySQL. All major CMS and web software use MySQL as database. It’s a must have for any server. Following command will install MySQL and mysqltuner on your server.

 sudo apt-get install mysql-server
sudo mysql_install_db

Again, you’ll be asked to confirm the installation. You’ll also ask to set up MySQL root password during setup. Do it as asked. MySQL will also be up and running in few seconds.

It’s a nice idea to secure the MySQL installation,

sudo mysql_secure_installation

This will ask you few questions. Type N when it ask you to change MySQL root password as you just set it up. Then Just hit Enter to all other prompts to secure the MySQL installation.

Install Nginx

Now We’ll install Nginx on the server. Rather than dealing with third-party repo’s, I find it easy to go with Ubuntu 14.04’s built in package. Which is nginx/1.4.6 (Ubuntu) at the moment of writing.

sudo apt-get install nginx

Nginx does not support longer domain names by default. If you have a bit longer domain, you’ll need to edit Nginx configurations to support it. I think it’s better to do it now than later. Open Nginx main configuration file,

sudo nano /etc/nginx/nginx.conf

Look for following line within the file and uncomment it (Delete # mark).

# server_names_hash_bucket_size 64;

It’s should look like this after uncommenting,

server_names_hash_bucket_size 64;

Save file and exit nano text editor (Ctrl+X). Then restart Nginx,

sudo service nginx restart

Nginx is now successfully installed on your server. Open your Server’s IP address in web browser to confirm it. You’ll see Nginx default web page saying “Welcome to nginx!”

What’s Next?

Now you can install whichever CMS you like on your server. Please note that some CMS like WordPress have special requirements. If you’re planning to host multiple websites on this server, you must create server blocks (Virtual Hosts) for each site. I’ll cover it on CMS specific tutorials.

Tharindu

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

Related Articles

16 Comments

  1. Hi

    I followed your tutorial to configure and install Prosper202, on a vps, but I haven´t good results. I know someone who can install Prosper202 on my VPS for a few dollars?

    I hope you can help me.

    Greetings

    Nicolas

  2. Good tutorial! I’m glad other internet marketers are starting to promote the nginx and php-fpm combo. I have a similar set up running on a 512mb VPS, which I use for prosper202. After some tweaking and tinkering, my VPS can handle 8 million clicks/redirects a day, with no issues.

  3. I bought an Interserver VPS and followed all your instructions step by step both here and on AffiliateFix but it still says “The web server software is running but no content has been added, yet.” when I visit my server. Any ideas why this is happening?
    BTW, I’m trying to install Prosper202 version 1.8.3.3. The free version which was recently released.

    1. That’s another tutorial Wariya. However if your server is already and running with websites, you don’t need to install Nginx. If it’s a fresh server, I suggest you reinstall it with Ubuntu.

  4. thanks Tharindu,
    I am totally noob on vps things. But I can finally setup nginx on my vps thanks to your tutorial.
    However, ubuntu 14.04+nginx according to your tutorial eating memory about 1.5 GB on my vps. Can it be lowered down? Maybe by removing more unusable packages?

  5. Thanks Tharindu,

    I have applied your tutorial on Amazon EC2 and i can see the “Welcome to nginx!” when calling the server ip address. but when i tried to upload a test.php file i couldn’t browse it as i receive a 404 error “404 Not Found nginx/1.4.6 (Ubuntu)”.

    So please tell me what’s the directory should i upload my files or just tell me what’s the wrong.

    Thanks

  6. Thanks man. I’ve configured everything now and it’s fine but i want to install prosper202 on a subdomain not on the main domain. Is there any tutorial showing how to make a subdomain (points to a directory) on nginx ? And how to install new domain names as separate websites on the same server?

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.