Categories: Development

How to fix Laravel showing the directory structure on Apache

Prevent Laravel from showing the directory structure and instead show your application when using Apache.

This is done by creating and assigning a new virtual host, to incorporate the /public directory.

Once you have downloaded/composer installed the Laravel project or app into /var/www/html

Navigate to the Apache virtual hosts configuration directory

cd /etc/apache2/sites-available

Create a new Apache virtual hosts file

sudo nano the_project.conf

Add (and edit) in the following and save it

<VirtualHost *:80>
   ServerName domain.com
   ServerAdmin webmaster@domain.com
   DocumentRoot /var/www/html/public

   <Directory /var/www/html>
       AllowOverride All
   </Directory>
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Disable the default virtual hosts configuration file for Apache2

sudo a2dissite 000-default.conf

Now enable the one created above with

sudo a2ensite the_project

Enable the Apache rewrite module

sudo a2enmod rewrite

Restart Apache

sudo systemctl restart apache2

When you navigate to the domain or IP address instead of the Laravel files and folders showing it will be the app homepage.

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

2 years ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

2 years ago

Early September spring shots

Some early September spring shots from a bushwalk, It is still too early for wildflowers.

3 years ago

Cloning an NVMe to SK Hynix Platinum P41 NVMe

I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…

3 years ago

Using Laravel’s deleteDirectory to delete folders and their contents

If you ever needed a simple solution in Laravel to delete an entire directory and…

3 years ago

How to allow only 1 user to register in a Laravel application

How to enforce only one user to register or be registered in a Laravel web…

3 years ago