Laravel returns 500 Internal Server Error on Apache
500 Internal Server ErrorShort 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.
Fix it fast
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.log2Match what you see, then jump to its fix
- 1
The 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
Routes other than the home page do not work, and the log has no .htaccess errorAllowOverride None, so .htaccess is never readFix - 3
The log names vendor/autoload.php as a file PHP could not openvendor/autoload.php does not existFix - 4
laravel.log or the Apache log shows a permission error on storage or bootstrap/cacheThe web server user cannot write storage or bootstrap/cacheFix - 5
Files outside public, such as .env, can be requested in the browserThe document root is the project folder, not publicFix
- 1
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 apache23Verify
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
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/loginConfirmed by httpd.apache.org
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.lock2Fix
Run composer install in the project folder; it installs the versions in composer.lock.
composer install3Verify
The file now exists and the page loads.
ls -l vendor/autoload.php
curl -I http://example.com/Confirmed by getcomposer.org
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/cache2Fix
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/cache3Verify
Reload the page and check no new error appears in laravel.log.
curl -I http://example.com/Confirmed by laravel.com
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/public3Verify
The site loads, and /.env returns 404 or 403.
curl -I http://example.com/
curl -I http://example.com/.envConfirmed by laravel.com
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
Back end
require(vendor/autoload.php): Failed to open stream: No such file or directory
Fatal error: Uncaught Error: Failed opening required 'vendor/autoload.php'
PHP looked for vendor/autoload.php at a path where it does not exist.
3 causes, each with a fixServers
Apache returns 504 Gateway Timeout when PHP takes too long
Quick requests work, slow ones end in a 504 after a fixed wait
A 504 from Apache means the backend did not answer within the proxy timeout.
2 causes, each with a fixServers
Composer reports a different PHP version than php -v on Ubuntu
You are running 8.1.2.
Composer takes its PHP version from the interpreter that runs it, unless config.platform fakes one.
3 causes, each with a fixServers
docker-php-ext-install mbstring fails: oniguruma not found
The docker-php-ext-install step exits with a non-zero code
mbstring needs the Oniguruma library to build its regex functions, and the PHP build finds it through pkg-config.
3 causes, each with a fixServers
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 fixServers
nginx and PHP-FPM show File not found or Primary script unknown
File not found.
PHP-FPM received a script path it could not turn into a file.
4 causes, each with a fix