← Other topics

Run Laravel via a subdirectory on an Apache server

Video Notes

The following Apache site config can be used to run a Laravel application via a subdirectory (e.g. yourdomain.com/admin).


<VirtualHost *:80>
    # What domain these configs are for
    ServerName yourdomain.com

    # What directory is served when the root domain is visited (e.g. yourdomain.com)
    DocumentRoot /var/www/main/public
    # What directory is served when yourdomain.com/admin is visited
    Alias /admin "/var/www/admin/public"

    # Directory settings for main
    <Directory /var/www/main/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

    # Directory settings for admin
    <Directory /var/www/admin/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted

    ErrorLog ${APACHE_LOG_DIR}/mydomain-error.log
    CustomLog ${APACHE_LOG_DIR}/mydomain-access.log combined

Summary of setting up an Apache site config

Place config file in /etc/apache2/sites-available directory

Enable the config with this command:

> a2ensite yourdomain.conf

Run this command to check for any errors in the configs:

> apache2ctl -t

Restart Apache to make the changes take effect:

> systemctl restart apache2

As an alternative to running multiple Laravel apps on the same server via subdirectories you can use separate domains or subdomains. More details here: Multiple Laravel apps on a single Apache server

If this info helped you out you can say thanks and support future content by clicking my Amazon affiliate link: https://amzn.to/3UtgnYk. If you make a purchase on Amazon within 24 hours of clicking the link I may receive a micro-commission and it costs you nothing extra. Any income from these sales goes directly to supporting me in making new videos and guides. Thank you for your support!

← Other topics