Setting document root for Laravel project on Apache virtual host

You need to allow the mod_rewrite in the apache server and allowSymLinks.
Source

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName appname.com
    ServiceAlias www.appname.com
    DocumentRoot /var/www/appname/public

    <Directory "/var/www/appname/public">
            Options FollowSymLinks
            ReWriteEngine On
    </Directory>

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

in the DocumentRoot Directory i would also allow MultiViews

<Directory "/var/www/appname/public">
        Options FollowSymLinks MultiViews
        ReWriteEngine On
</Directory>

You may need to also do

sudo a2enmod rewrite

to enable module rewrite.

Edit 1:

In my .conf files i got them with the quotes and they are working.
Did you enable the modudle rewrite?

Besides some options i also have the “https://stackoverflow.com/” folder with the next config.

<Directory "https://stackoverflow.com/">
    Options FollowSymLinks
    AllowOverride All
    ReWriteEngine On
</Directory>

and here i’ll write my full code of public directory

<Directory "/var/www/appname/public">
        Options FollowSymLinks MultiViews
        Order Allow,Deny
        Allow from all
        ReWriteEngine On
</Directory>

Try it and see if it works, after delete the options that you don’t like to use.

Leave a Comment