302

I've installed Apache, PHP, and MySQL on Ubuntu 10.10 desktop edition, and it's working fine.
Except I have no clue where to look for Apache or PHP log files.

kiri
  • 28,986
Stann
  • 15,416

6 Answers6

430

By default, /var/log/apache2/error.log.

This can be configured in /etc/php5/apache2/php.ini.

misterben
  • 7,437
78

Check these settings in php.ini:

  1. error_reporting = E_ALL | E_STRICT (as recommended for development in php.ini)

  2. error_log = /var/log/php_errors.log

  3. Then create log file manually

    touch /var/log/php_errors.log
    chown www-data: /var/log/php_errors.log
    chmod +rw /var/log/php_errors.log
    
  4. And finally

    sudo service apache2 restart
    

Now you can view PHP errors by this way

tail /var/log/php_errors.log

This is an agreeable solution to this issue for me.

muru
  • 207,228
31

You can also define a specific error log file for each VirtualHost in Apache. If you have any VirtualHost defined in /etc/apache2/sites-available/ and enabled in /etc/apache2/sites-enabled (enable with sudo a2ensite [your-virtualhost-definition-file]), you can change the error log by adding the following line inside your VirtualHost config:

ErrorLog ${APACHE_LOG_DIR}/[your-vhost]-error.log

That might be useful if you have a lot of vhosts and want to split where they report the errors.

Also, you can watch your error log live by issuing the following command (adapt to your own log file if different from the default):

sudo tail -f /var/log/apache2/error.log

This is particularly useful when doing live debugging.

Eliah Kagan
  • 119,640
ywarnier
  • 461
2

If Apache was setup with Webmin/Virtualmin there is a separate folder for each VirtualHost.

It is

~/logs

folder for each VirtualHost user.

These are two files:

~/logs/access_log

and

~/logs/error_log

So they are

/home/onedomain/logs/access_log

/home/onedomain/logs/error_log

/home/anotherdomain/logs/access_log

/home/anotherdomain/logs/error_log

...

etc.

To view log files for each particular domain login as VirtualHost owner user of that hostname and run

tail -f ~/logs/error_log

Ilyich
  • 141
1

If you use a bitnami distribution, it is at:

tail /opt/bitnami/apache2/logs/error_log

Bitnami distributions have their own directory structure. I had to find what it was for my server, and this is where it resides by default for bitnami. I would assume lots of people are looking for the same thing when using a bitnami distribution.

For more info see here: https://docs.bitnami.com/bch/infrastructure/lamp/troubleshooting/debug-errors-apache/

eyal_katz
  • 179
0

Apache log files and PHP log files are not the same thing.

Apache logs

To find out where the Apache log files are, look in the Apache configuration for your site (for example, in /etc/apache2/sites-enabled/FOOBAR.conf). You may see configuration for ErrorLog and CustomLog that looks like this:

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

If ErrorLog isn't specified, you can find the default error log by running apache2 -V | DEFAULT_ERRORLOG, on Ubuntu, it is logs/error_log. The value of the environment variable APACHE_LOG_DIR is set in the script /etc/apache2/envvars, on Ubuntu, it is /var/log/apache2/ .

Tip: to find error.log quickly, you can try running locate error.log or locate access.log.

These logs are written as a user in the adm group, which is a group on Ubuntu that is used for logging. Make sure that the directory and file is writable by the adm group.

PHP logs

PHP also has logs that you can look at. In your Apache configuration or in .htaccess, you may see a line like this:

php_admin_value error_log /var/log/FOOBAR.log

PHP can change this configuration at run time by running ini_set(). You can check the value of the error_log PHP configuration by running phpinfo(); in your PHP code.

Note that both the directory of this log file and the log file itself needs to be writable by the Apache user, which is www-data user (in the www-data group) on Ubuntu. This is different from the Apache logs, which uses a user in the adm group.

Create a PHP file, with these contents:

<?php
error_log("test");

Visit that PHP file in your browser. In your PHP error log file, you should now see something like this:

[28-Nov-2024 11:11:28 UTC] test

You might be interested in my guide to troubleshooting PHP calls to error_log().

Flimm
  • 44,031