Install Nginx + PHP FPM + Caching + MySQL on Ubuntu 12.04

  • Last Created On Dec 05, 2024
  • 9
0 0

Archived content

Ubuntu 12.04 has reached end-of-life. The steps and commands used in this guide may no longer be relevant to newer versions of Ubuntu.

Probably a lot of people are going to use their AKLWEB HOST VPSes as webservers, a good choice would be Nginx as a webserver. In this topic I’m going to describe on how to install Nginx, PHP FPM and MySQL. Also we’re going to look at Nginx’s caching feature. In this topic we’re using Ubuntu 12.04, I do not know if this will also work on CentOS or Debian.

First steps

Make sure your server is up to date:

apt-get update

Install Nginx and PHP FPM

apt-get install -y nginx php5-fpm

Install MySQL

apt-get install -y php5-mysql mysql

When prompted enter a password. This is the root password which you will need to create databases and users.

Now that we’re installed all the programs we need, we’ll configure our so called vhosts. A vhost is the configuration file for a domain, this means you can attach multiple domain to your server.

The configuration file can be found here: https://gist.github.com/GiovanniK/11194798

To begin we’ll remove the default vhost for nginx:

rm -rf /etc/nginx/sites-enabled/default

We’ll now create a new one with the contents of the vhost I gave you.

nano /etc/nginx/sites-enabled/DOMAIN

Now that we’ve created our vhost and we’ve pasted the contents we’ll have to edit some things.

Below the old values:

Line 1: fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=Nginx:100m inactive=60m;
Line 6: server_name nginx.dev;
Line 9: root /var/www/nginx.dev/public/;
Line 26: fastcgi_cache Nginx;
Line 27: fastcgi_cache_valid 200 5m;

And the new values:

Line 1: fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=DOMAIN:100m inactive=60m;
Line 6: server_name DOMAIN;
Line 9: root /var/www/DOMAIN/public/;
Line 26: fastcgi_cache DOMAIN;
Line 27: fastcgi_cache_valid 200 TIME_TO_CACHE;

If you don’t want caching, remove/comment the following lines:

Line 1 & 2
Line 12 - 16
Line 26 - 31
Line 34 - 37

Now that our configuration is complete and we’ve setup all our services, we can restart Nginx.

service nginx restart

We’re done! If you go to the domainname you’ve pointed to your server, you should see the new document root and you should be able to put content on it.

Enjoy!

Views: 9

Recent Articles

  • How to Install JAX with ROCm Acceleratio...
    96
  • Deploy a PyTorch Workspace on a Vultr Cl...
    71
  • Managing Backup Storage
    82
  • Automating FTP Backups in Windows Server
    71
  • Automating FTP Backups in Linux
    75

Popular Articles

  • Our General Terms & Conditions
    2630
  • Our Privacy Policy
    2474
  • Our Cookies Policy
    275
  • Our Terms of Use
    152
  • How to Install JAX with ROCm Acceleratio...
    96