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…

1 year ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

1 year ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

2 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

2 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

2 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

2 years ago