Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sauladam's avatar

compiled.php causing "500 Internal Server Error"

Hey guys,

I'm having a really weird issue with Laravel 5 (.0 and .1) on a fresh Ubuntu 14.04 server with Apache 2.4.7.

When I first deployed the project (that works just fine), I got a "500 Internal Server Error" response from every route of the app. The log says:

[fastcgi:error] [pid 14334] (104)Connection reset by peer: [client xxx.xxx.xxx.xxx:41395] FastCGI: comm with server "/var/www/clients/client1/web1/cgi-bin/php5-fcgi-yyy.yyy.yyy.yyy-80-domain.com" aborted: read failed

[fastcgi:error] [pid 14334] [client xxx.xxx.xxx.xxx:41395] FastCGI: incomplete headers (0 bytes) received from server "/var/www/clients/client1/web1/cgi-bin/php5-fcgi-yyy.yyy.yyy.yyy-80-domain.com"

[fastcgi:error] [pid 14334] (104)Connection reset by peer: [client xxx.xxx.xxx.xxx:41395] FastCGI: comm with server "/var/www/clients/client1/web1/cgi-bin/php5-fcgi-yyy.yyy.yyy.yyy-80-domain.com" aborted: read failed

[fastcgi:error] [pid 14334] [client xxx.xxx.xxx.xxx:41395] FastCGI: incomplete headers (0 bytes) received from server "/var/www/clients/client1/web1/cgi-bin/php5-fcgi-yyy.yyy.yyy.yyy-80-domain.com"

I narrowed down the cause or the error to a single line in bootstrap/autoload.php:

$compiledPath = __DIR__.'/cache/compiled.php';

if (file_exists($compiledPath))
{
        require $compiledPath; // this causes the server error
}

If there is a compiled.php and Laravel tries to require it, I get the 500 Error Response. As soon as I remove the compiled.php (either with php artisan clear-compiled or manually), everything works like a charm.

This is especially annoying because php artisan optimize (which creates the compiled.php) is part of my automated deploymet process. This error did not occur with Laravel 5.0 on Ubuntu 12.04 with Apache 2.2. But I was able to reproduce it with Laravel 5.0 and 5.1 on 2 separate servers with Ubuntu 14.04 an Apache 2.4

Does anybody have an clue what this sorcery is? After 2 days of debugging and googling I'm really out of ideas...

P.S.: I'm more of a 'coder guy' than a server expert, so chances are high that I'm just missing something obvious.

0 likes
17 replies
mstnorris's avatar

Have you followed the Upgrade Guide?

Does the bootstrap/cache directory exist? Did you create it? And is it writeable?

sauladam's avatar

@mstnorris Yes and yes, I can see the file, I can delete it with php artisan clear-compiled and create it again with php artisan optimize. I've even tried giving full 777 permissions, but no change. Tried the same for L5.0, where the compiled.php was located at DIR.'/../vendor/compiled.php';. And I can reproduce it with a fresh (not manually upgraded) Laravel 5.0 and 5.1 project. My project was in production on another server with the same deployment strategy, never had any problems there.

So there seems to be something special about this file in particular, maybe only in connection with this version of Apache or something... I'm really confused that nobody but me seems to have encountered this problem yet, but I can reproduce it on 2 different servers.

tgif's avatar

Hi @sauladam I just set up a new server with the same exact settings as the previous. I copied all my Laravel project folders to the www directory and all they show is a blank page with a 500 internal server error (although the laravel favicon loads without error). I updated everything created a new project using Laravel 5.1. And I get the same error. I think it is my apache settings because neither 5.0 nor 5.1 projects work but I'm not sure because the favicon uploads ok. If you figure it out please post back:)

bashy's avatar

Have you checked the path it's trying to include?

Tried

exec("ls -lah $compiledPath");
tgif's avatar

@sauladam well I put a generic php file in the public folder and that opens fine. So now I now it is not my server setup. Am I missing any installs? I am running:
Server version: Apache/2.4.7 (Ubuntu)
Zend Engine v2.5.0
PHP Version => 5.5.9-1ubuntu4.9
PHP Version => 5.5.9-1ubuntu4.9
Laravel Installer version 1.2.1
Composer version 1.0-dev
MYSQL 5.5.43-0 ubuntu0.14.04.1
what am I missing?

bashy's avatar

Look at the requirements?

Mcrypt PHP Extension
OpenSSL PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
sauladam's avatar

@bashy Yep, and it's definitely all there. In the end it's not even my code, this is Laravel-specific stuff I didn't even touch.

@csuarez Yes, actually I was able to solve (or at least identify) the problem. Xcache (a PHP code accelerator) turned out to be the culprit. I can't really tell why, probably because of the filesize (compiled.php is 600kB). The PHP version also seems to play a role, Xcache + PHP 5.4 did work fine on another server.

Anyway, everything seems to work smooth now after replacing Xcache with APC. On Ubuntu you can do this:

> sudo apt-get remove --purge --auto-remove php5-xcache

If you want to use APC or another opcode cacher (which is recommended), you just do:

> sudo apt-get install php-apc

I went with APC because it was discussed to be part of PHP 5.6, and I think they chose it for a reason. Also note that an opcode cacher is optional. You don't have to have one installed. But it's recommended for performance reasons.

tgif's avatar

Thank you @sauladam its 5:30 am in Miami so I will go to bed and fix it when I wake up ( now that I know the solution:) )

sauladam's avatar

@csuarez Sure, good luck, I hope it works for you too! Good night from Germany :)

tgif's avatar

@sauladam @bashy hey guys can you tell me the technique you used to track down the problem? Was it Laravel log files?

tgif's avatar

@sauladam @bashy Well this is odd for me listing all my php extensions I get Zend Opcache and not Xcache

I disabled opcache in /etc/php5/apache2/php.ini and /etc/php5/cli/php.ini

; Determines if Zend OPCache is enabled
opcache.enable=0

; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=0

Then I installed apc

sudo apt-get install php-apc

when I print out php extensions and modules apc is now listed.

 php -m
[PHP Modules]
apc
apcu
bcmath
bz2
calendar
Core
ctype
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

I restarted apache and I still get a blank page.

Anyone have any ideas.

tgif's avatar

Finally found the solution to my issue for anyone who has the same problem. I originally set permissions to project files to 755. That may be correct but first I needed to change the storage folder permissions to 777. The page opened successfully. Then I changed permissions back to 755. AND the page opened successfully. Shrug:|

Now I will try changing back to Opcache and see what happens.

1 like
bashy's avatar

@csuarez It's not always Xcache or OPcache. Glad you figured that out but I'm sure any permission errors will come up in Nginx/php5-fpm logs...

zhiyong's avatar

@csuarez

Thanks for the tip. I recently did a fresh installation of L5.1 and migrated all my code from L5 to the new folder. After doing everything mentioned in upgrade guild, setting up all permissions etc, the thing just don't work. The weird thing is, my API routes work just fine.

Then after hours and hours search and research, I stumbled upon this post. All of a sudden, everything starts to work again!!!!

Could some genius tell me why is this?

Please or to participate in this conversation.