Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mirai's avatar
Level 1

Installing Laravel application on main domain (without using subdomains)

Hi, I am new to Laravel so I am sorry for the question but, I have seen many inquiries on how to set up a subdomain. I have successfully setup my subdomain but I wonder if is possible to, instead of accessing my app through a subdomain.domain.com, to access my application as domain.com. I am using DigitalOcean (Ubuntu). How would one do that? Below is my 000-default.conf file:

<VirtualHost *:80>
    ServerName myappname.domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html/myappname/public
    <Directory /var/www/html/myappname/public/>
        AllowOverride All
    </Directory>
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.domain.com [OR]
    RewriteCond %{SERVER_NAME} =domain.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

Any help is greatly appreciated.

0 likes
2 replies
ConfusedDevelopment's avatar
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/app/public/
    <Directory  "/var/www/app/public">
            AllowOverride All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I've got a simple setup to run a catchall on my main domain (subdomains are elsewhere setup). Laravel public folder already has a .htaccess that specifies the rewrite conditions, so that should be enough

(Remember to enable mod-rewrite in apache2 if you're using that and haven't already:)

a2enmod rewrite

Then restart apache

Mirai's avatar
Level 1

Thank you very much, excellent suggestion! It was not working at the beginning, maybe it had something to do with the SSL certificate that I installed previously. so I had to save the new host block in a new separate conf file. Then I disable the default file with the following:

sudo a2dissite 000-default.conf
sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo service apache2 restart

Now is working but the subdomain is also working, so both: domain.com and myapp.domain.com are pointing to my app. Now I have to figure it out how to disable the "myapp.domain.com"...

Thank you very much, I appreciate it.

Please or to participate in this conversation.