← 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).

Config

<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>

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

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

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

Unlock all the notes for $4

No subscriptions, no auto-renewals.

Just a simple one-time payment that helps support my free, to-the-point videos without sponsered ads.

Unlocking gets you access to the notes for this video plus all 200+ guides on this site.

Your support is appreciated. Thank you!

Payment Info

/
$4 6 months
$25 forever
Please check the form for errors
Questions? help@codewithsusan.com
← Other topics