Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

Laravel returns 500 Internal Server Error on Apache

Error500 Internal Server Error

Short answer

Apache and Laravel report different 500s. Read the Apache error log first. If it names .htaccess, enable mod_rewrite and allow overrides. If PHP cannot open vendor/autoload.php, run composer install. If it cannot write, give the web user storage and bootstrap/cache. Always point the document root at public.

  • Applies to Laravel 12, Apache 2.4, PHP 8.3, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read the newest lines of the Apache error log, then Laravel's own log. One of them names the real cause.

    sudo grep -rn "ErrorLog" /etc/apache2/
    sudo tail -n 30 /var/log/apache2/error.log
    tail -n 30 storage/logs/laravel.log
  2. 2Match what you see, then jump to its fix

    1. 1The Apache log names the .htaccess path and the directive, for example RewriteEngine or RewriteCondmod_rewrite is not loaded or .htaccess uses a directive that is not allowedFix
    2. 2Routes other than the home page do not work, and the log has no .htaccess errorAllowOverride None, so .htaccess is never readFix
    3. 3The log names vendor/autoload.php as a file PHP could not openvendor/autoload.php does not existFix
    4. 4laravel.log or the Apache log shows a permission error on storage or bootstrap/cacheThe web server user cannot write storage or bootstrap/cacheFix
    5. 5Files outside public, such as .env, can be requested in the browserThe document root is the project folder, not publicFix

What does the error look like?

  • 500 Internal Server Error
  • /var/www/html/.htaccess: RewriteCond: bad flag delimiters
  • /var/www/html/.htaccess: DirectoryIndex not allowed here

Cause 1 of 5

mod_rewrite is not loaded or .htaccess uses a directive that is not allowed

1Check

With overrides on, a directive that is not allowed or has a syntax error gives a 500 for that directory, and the error log names the file. The rewrite directives need mod_rewrite loaded and AllowOverride FileInfo or All.

ls /etc/apache2/mods-enabled/ | grep rewrite
sudo grep -rn "AllowOverride" /etc/apache2/

2Fix

Enable the module, allow overrides for the site's public folder, then restart Apache.

sudo a2enmod rewrite
# in the vhost
<Directory /var/www/example.com/public>
    AllowOverride All
    Require all granted
</Directory>
sudo systemctl restart apache2

3Verify

The rewrite link is present in mods-enabled and the site loads.

ls /etc/apache2/mods-enabled/ | grep rewrite
curl -I http://example.com/

Confirmed by httpd.apache.org

Did this fix it?

Cause 2 of 5

AllowOverride None, so .htaccess is never read

1Check

AllowOverride None is Apache's default. Apache then ignores .htaccess files, so Laravel's rewrite rules never run. For rewrite rules in a distributed file, FollowSymLinks or SymLinksIfOwnerMatch must also be enabled.

sudo grep -rn -B2 -A4 "example.com/public" /etc/apache2/sites-enabled/

2Fix

Set AllowOverride All (or FileInfo) and Options FollowSymLinks for the public directory.

<Directory /var/www/example.com/public>
    Options FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

3Verify

Restart Apache and open a route other than the home page.

sudo systemctl restart apache2
curl -I http://example.com/login

Confirmed by httpd.apache.org

Did this fix it?

Cause 3 of 5

vendor/autoload.php does not exist

1Check

Composer writes vendor/autoload.php when you run install. A folder copied without vendor, or a vendor ignored by version control, has none.

ls -l vendor/autoload.php
ls -l composer.lock

2Fix

Run composer install in the project folder; it installs the versions in composer.lock.

composer install

3Verify

The file now exists and the page loads.

ls -l vendor/autoload.php
curl -I http://example.com/

Confirmed by getcomposer.org

Did this fix it?

Cause 4 of 5

The web server user cannot write storage or bootstrap/cache

1Check

Laravel writes to storage and bootstrap/cache, so the web server process owner needs write access to both.

ps -o user= -C apache2 | sort -u
ls -ld storage bootstrap/cache

2Fix

Give the web server user ownership of the two folders.

sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R ug+rwX storage bootstrap/cache

3Verify

Reload the page and check no new error appears in laravel.log.

curl -I http://example.com/

Confirmed by laravel.com

Did this fix it?

Cause 5 of 5

The document root is the project folder, not public

1Check

Laravel must be served from its public folder, with all requests going to public/index.php. Serving the project root exposes sensitive configuration files.

sudo grep -rn "DocumentRoot" /etc/apache2/sites-enabled/

2Fix

Point DocumentRoot at the public folder and restart Apache.

DocumentRoot /var/www/example.com/public

3Verify

The site loads, and /.env returns 404 or 403.

curl -I http://example.com/
curl -I http://example.com/.env

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Deploy with composer install and keep vendor out of version control.
  • Always set DocumentRoot to the public folder in the vhost.
  • Read the Apache error log right after every restart or config change.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

nginx gives up waiting for the app and returns 504

upstream timed out (110: Connection timed out) while reading response header from upstream

nginx returns 504 when the app behind it takes the request but sends nothing back within proxy_read_timeout (60 seconds by default), or when the connection cannot be opened in time.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.