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
2 | Add configuration inside sites-available directory
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.