Access Laravel With *.test Domain — Nginx — Linux

Today i will show you how to create a simple configuration to access locally your laravel project without valet on Linux (on this tutorial I’m using Ubuntu 18.04 LTS). When you have already finished installing laravel by laravel or composer command line below:

laravel new project-name

or by this:

composer create-project --prefer-dist laravel/laravel blog

move to this directory:

cd /etc/nginx/sites-available/

Create new file with the identity of your project, or something else you’d like to create:

sudo touch project-name

Edit the file you’ve already created before

sudo nano project-name

fill the file with this

server {
listen 80;
listen [::]:80;
root /home/username/project/path/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name project.test; location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
  • Changes project path above with your own project path, and don’t remove public after the path.
  • Change project.test domain of your project.

3 | Update /etc/Hosts

After that, edit and add configuration to hosts file: (you can use nano / sublime / gedit / whatever you’d like to use. I’m using nano here)

sudo nano /etc/hosts

add your project.test domain to the end of file:

127.0.0.1    project.test

4 | Restart the nginx server

The last thing you need to do is restarting the nginx server by code below:

sudo service nginx restart

Voila, you have already setting up your localhost *.test server.

I wrote these tutorials for myself in future when I forget for the next steps.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store