Laravel How to Configure Domains for in Apache/Nginx


For Apache, file name may be in sites-enabled folder, for example /etc/apache2/sites-enabled/000-default.conf or, for MAMP, it would be /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf where you need this:

<VirtualHost *:80>
    DocumentRoot "/Applications/MAMP/htdocs/project1/public"
    ServerName project1.test

See that /public part at the end of DocumentRoot? That’s exactly how to point your domain to that public folder.

Notice: after editing that configuration file, don’t forget to restart Apache server.



For Nginx server, configuration file will be somewhere like /etc/nginx/sites-enabled/project1.test, with this code:

server {
    listen 80;
    listen [::]:80;

    . . .

    root /var/www/html/project1/public;
    index index.php index.html index.htm index.nginx-debian.html;


    location / {
        try_files $uri $uri/ /index.php?$query_string;

    . . .

In this case, you need to look at root variable and put /public at the end of it. Also, restart the server.



Don’t forget .env file

Another thing I see often is that people leave .env file with default values after installation, except for changing DB credentials.

What you need to set up is APP_URL variable.

In your case, it should be your domain name with full prefix http:// or https://.