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

subarkah's avatar

Laravel 7 with Apache2 - Virtualhost Config not redirect to public folder

I have a problem when I deploy laravel with apache web server on Ubuntu 20 Server. My apache running on 8080 port. When I access the laravel directory the project is not directed to the public folder. Even though I have made a virtualhost configuration.

 <VirtualHost 127.0.1.2:8080>
        ServerName admin-baledono.com
        ServerAlias www.admin-baledono.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/html/admin-baledono.com/public

        <Directory /var/www/html/admin-baledono.com>
                Options -Indexes +FollowSymLinks
                AllowOverride All
                Require all granted

                Allow from all
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/admin-baledono.com-error.log
        CustomLog ${APACHE_LOG_DIR}/admin-baledono.com-access.log combined
</VirtualHost>

I have disabled the default configuration file from virtual host in Apache. And enabled my virtualhost configuration.

I've also created a .htaccess file like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/ [L]
</IfModule>

But the result is still the same. When I access my website, what is displayed is the contents of my project directory

0 likes
8 replies
s4muel's avatar

.htaccess like that is not needed. everything should be handled by the vhost configuration. the DocumentRoot directive says where are the files served from, so it should work, have you reloaded/restarted apache service after these changes?

subarkah's avatar

@s4muel yes, i created a .htaccess because vhost not worked. i've been restarted apache service several times.

s4muel's avatar

if you execute these two command, what does the second output?

source /etc/apache2/envvars
/usr/sbin/apache2 -S
subarkah's avatar

I thought it was the port problem. When I access using the server name on my vhost I am directed to the nextcloud page running on port 80. And when I access using the server address (localhost:8080/admin-baledono.com) is still not directed to the public laravel directory.

subarkah's avatar

@s4muel

VirtualHost configuration:
127.0.1.2:8080         admin-baledono.com (/etc/apache2/sites-enabled/admin-baledono.com.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex watchdog-callback: using_defaults
Mutex rewrite-map: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33 not_used
Group: name="www-data" id=33 not_used
s4muel's avatar
s4muel
Best Answer
Level 50

oh, i see. if you want to access the page on localhost:8080, you need to specify that in the <VirtualHost HERE> directive. because, currently like that, it only "listens" on 127.0.1.2

either add localhost:8080, like this <VirtualHost 127.0.1.2:8080 localhost:8080> (i suppose), or use a wildcard

<VirtualHost *:8080>
...
subarkah's avatar

@s4muel worked. But my landing page display apache ubuntu default page. If i go to another url is worked. localhost:8080 display apache default page. localhost:8080/login display my login page.

now whats wrong?

subarkah's avatar

Solved. The problem was with my browser cache

1 like

Please or to participate in this conversation.