Config files for Nginx Server on Ubuntu 18.04 to serve CodeIgniter, Custom PHP Frameworks, Laravel, and other LEMP stack frameworks. Still a work in progress, however I am trying to start a go-to repository for setting up Nginx on Ubuntu Linux distros and didn't know where else to start. Feel free to contribute and help with the code.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.


Config files for Nginx Server on Ubuntu 18.04 to serve CodeIgniter, Custom PHP Frameworks, Laravel, and other LEMP stack frameworks.

Note: This is an ongoing project for me as I learn how to use Nginx in place of Apache, this repository is intended to help beginner to intermediate PHP developers up and running for educational videos. I will work on security and better ways to improve the speed and performance of the setup as I learn more.

Pre-requisites For Using This Source Code To Setup Nginx Server on Ubuntu 18.04

  • Must be using PHP-FPM 5.0 or newer, however this code is set up for using PHP-FPM 7.2 with Ubuntu 18.04. Please make the necessary changes to the code to whatever version of PHP-FPM version you are using.

  • Already have Nginx, PHP, and MySQL installed on your Ubuntu 18.04 server. The code should work with Ubuntu 16.04 or newer, however our code was built for 18.04. If you do not have the LEMP stack or Nginx setup on your machine, then please check out this great guide from Digital Ocean on how to setup the LEMP stack on Ubuntu at: You may download Nginx at:

  • Have Nginx downnloaded and enabled, if you do not, below is the command line order to enable nginx as your localhost service.

sudo systemctrl stop apache2.service

sudo systemctrl enable nginx.service

sudo systemctrol start nginx. service

  • You have at minimum a index.php file for testing to see if nginx server is working properly.

  • Have fireware software permissions set to allow access to the service.

  • Have PHP-FPM installed and properly running.

Instructions for Using Setting Up Nginx to Serve Index.php files on Ubuntu 18.04

  1. Copy the files from /etc/sites-available/default to a new folder named /etc/sites-available/, substituting your domain for

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/

  1. Edit the newly created file with the code in the repository labeled using the nano text editor in the command line.

sudo nano /etc/nginx/sites-available/

  1. Make sure the default server is in the /etc/nginx/sites-enabled/ directory.

grep -R default_server /etc/nginx/sites-enabled/

  1. Create a symbolic link the new directory to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

  1. The /etc/nginx/conf.d/default.conf file is used to configure the default virtual host. Copy the default.conf to create a new file names

sudo cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/

  1. Edit the nginx.conf file. Copy and paste the code in the repository into the newly created .conf file, changing to your own custom URL.

sudo nano /etc/nginx/nginx.conf.d/

  1. Restart the Nginx service

sudo systemctl restart nginx.service

  1. Test the configuration file using this command. You should get a response stating that sytax is ok and configuration was successful

sudo nginx -t

  1. Edit the nginx hosts file using the Nano text editor. Add your domain to the list under localhost. If you are unsure how to do this, please cut and paste the code in the repository with the file name nginx_hosts.

sudo nano /etc/hosts

  1. It's a good idea to make sure file permissions are set to be able to write to your files, if you haven't already done so, the following commands will make sure all permissions are set for writing. Adjust setting based to your security needs.

sudo chmod 755 /var/www

sudo chmod 755 /var/www/

sudo chmod 755 /var/www/

  1. Restart the nginx service

sudo systemctl restart nginx.service

Your project should now be viewable at http://localhost/

If you do not see your application please check to make sure you have a index.php file first, then check the status of your nginx service. Also check to be sure you replaced all locations with your_site to your domain or project name.

Troubleshooting Links and Other Helpful Nginx and LEMP Stack Resources

Spent a little time trying to figure this out so I thought I would share it. It is mainly for my re-use efforts, however feel free to make changes or make it better as needed. Hope it helps someone else out. Most of the tutorials on development are for the LAMP stack or use XAMPP or WAMPP, so I wanted to create some files for Nginx as I think it is a far better performing server then Apache.