PHP Error Logs in Heroku
Asked Answered
C

5

20

I have a PHP app deployed on Heroku, but I can't seem to locate the apache error log. Using the command $heroku logs I seem to get only the apache access logs. So a bunch of GET 200 OK etc, but no error information that is put into the error log locally, such as 'PHP Fatal error: blah blah'

Where do I access these error logs on Heroku, or how do I tell the app to write to Heroku's log like it does the local error log?

I feel like I'm overlooking something obvious but I can't seem to find a solution.

Coroner answered 7/12, 2012 at 23:12 Comment(1)
was wondering this myself. Please give an answer if you've found out.Untold
U
6

After a lot of experimentation, it looks like you need to comment out error_log in php.ini and make sure log_errors = on .. this should output your errors to stderr where the heroku logplex can pick up the stream, then monitor with heroku logs --tail .. I launched a heroku facebook app and looked at their phpinfo() and copied the setup.

Untold answered 13/12, 2012 at 18:48 Comment(1)
In you opinion so I just need to set log_errors = On in my php.ini? It doesn't work for me..Lioness
G
3

Try adding:

error_reporting(E_ALL);
ini_set("display_errors", 1);

To the very top of your PHP page/app

Gebelein answered 26/1, 2013 at 23:28 Comment(4)
Really? I see this in my log: "Wed Feb 06 18:51:35 2013] [error] [client 10.44.51.101] PHP Parse error: syntax error, unexpected T_STRING in /app/www/index.php on line 5" Is that not what the OP wanted?Gebelein
The test code is just: <?php error_reporting(E_ALL); ini_set("display_errors", 1); obvious error here ?> I deploy to Heroku, no config changes - and the run heroku logs after hitting index.php.Gebelein
@joshbirk's code works for me - I get 2013-02-07T18:12:14+00:00 app[web.1]: [Thu Feb 07 18:12:14 2013] [error] [client 10.92.74.179] PHP Parse error: syntax error, unexpected T_STRING in /app/www/index.php on line 1 in my Heroku log.Butyraldehyde
This actually looks like the easiest approach, since it requires no ini file or buildpack hacking - just set it in some PHP file that everything includes.Butyraldehyde
N
1

We had to add this to our buildpack in the bin/compile file:

cat >>boot.sh <<EOF
for var in \`env|cut -f1 -d=\`; do
  echo "PassEnv \$var" >> /app/apache/conf/httpd.conf;
done
touch /app/apache/logs/error_log
touch /app/apache/logs/access_log
touch /app/apache/logs/php_error.log
tail -F /app/apache/logs/error_log &
tail -F /app/apache/logs/access_log &
tail -F /app/apache/logs/php_error.log &
echo "Launching apache"
exec /app/apache/bin/httpd -DNO_DETACH
EOF

We left the php.ini and https.conf settings mostly as-is.

Nole answered 6/2, 2013 at 19:25 Comment(0)
G
0

That is not related to Heroku way of deploying, but to your PHP configuration. The error_log directive manages that.

The error_log directive defines the name of the file where script errors should be logged. The file should be writable by the web server's user.

Gunner answered 19/12, 2012 at 8:45 Comment(0)
F
0

I my laravel project I achieve see the errors by issue

heroku config:set APP_DEBUG=true

Acess app again and the errors will showed in browser

Femininity answered 10/7, 2020 at 0:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.