Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohokh67/e25737c54eddefe8aa11c4d8d623886e to your computer and use it in GitHub Desktop.
Save mohokh67/e25737c54eddefe8aa11c4d8d623886e to your computer and use it in GitHub Desktop.
How to install nginx, php7.1 and setup a virtual host in Ubuntu

Install Nginx and add a virtual host

  • First, make sure the Ubuntu Repo. is up to date.
sudo apt-get update
  • Check if Nginx is install in you machine:
nginx -v
  • If the previous command didn't return the Nginx version, then it means Nginx is not installed. Try to install it by following command:
sudo apt-get install nginx
  • Goto to this directory
cd /etc/nginx/sites-available
  • Copy the default config file and change example to your project name. Make sure the extention is .conf
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.conf

Modify the .conf file. Here is an example file

  • Now that we have our server block files, we need to enable them. Create the symbolic link from the .conf file to sites-enabled directory. Nginx reads them during startup
sudo ln -s /etc/nginx/sites-available/laravel.test.conf /etc/nginx/sites-enabled/
  • If you need to check the link, type this comand in terminal:
ls -l /etc/nginx/sites-enabled/
  • (Optional) Increase server_names_hash in nginx.conf file by uncommenting server_names_hash_bucket_size 64; line. In order to open the config file, tyoe this command:
sudo nano /etc/nginx/nginx.conf
  • Now, add the virtual host to the system by modifying hosts file and adding this line:
127.0.0.1       www.example.test        example.test

System hosts config file is accessible with this command:

sudo nano /etc/hosts

More commands

  • Restart nginx
sudo systemctl restart nginx
sudo service nginx restart
  • Check the syntax for nginx config files
sudo nginx -t
sudo apt-get install php-fpm php-mysql
  • Modify the php.ini and enable cgi.fix_pathinfo=0 and set it to ZERO. In order to do this, type this command: (You will find it in line 775)
sudo nano /etc/php/7.1/fpm/php.ini
  • Restart the php-fpm
sudo systemctl restart php7.1-fpm
  • If you need to change thee ownership of a directory to the current user:
sudo chown -R $USER:$USER /var/www/example.test
  • Change the www direcotry permission for development server
sudo chmod -R 755 /var/www
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment