PHP error_log

jigster

Verified User
Joined
Jul 23, 2021
Messages
108
Hi everyone. We'd prefer to have a separate PHP error log in the site's root or logs directory for every account, but I'm having a little trouble: If I create a file /usr/local/php83/lib/php.conf.d/11-custom.ini and add
error_log = php_error_log
this creates the log file in the same directory as the php script causing the error, so we end up with multiple logs in multiple directories.

Does anyone know how we can set it so every account automatically has a separate PHP error log in the site's root or their logs directory, without having to hard code a different absolute path for every site? Thanks
 
Last edited:
Thanks @zEitEr that's just what I needed! As we want it set for all users, I used the global option - https://docs.directadmin.com/webser...h-to-have-global-custom-php-fpm-configuration with placeholders |USER| and |DOMAIN|. For anyone else needing to globally change the location of the php error logs for every account, here's what I did:

In /usr/local/directadmin/data/templates/custom/php-fpm.conf.custom2 I added:
Code:
php_admin_value[error_log] = /home/|USER|/domains/|DOMAIN|/logs/php_errors.log
Then
Code:
da build rewrite_confs
service php-fpm83 restart

So far it's working perfectly, creating php_errors.log if it doesn't already exist.
 
A new challenge! I've just introduced a second drive at /home2 so the above now won't work for that drive. I tried using:
Code:
php_admin_value[error_log] = |HOME|/|USER|/domains/|DOMAIN|/logs/php_errors.log
which is used in some of the templates at /usr/local/directadmin/data/templates, but it didn't work. Any ideas of a different way to go about this?
 
It works on my end fine:

Bash:
# cat /usr/local/directadmin/data/users/testuser2/php/php-fpm84.conf

[testuser2]
user = $pool
group = $pool
listen = /usr/local/php84/sockets/$pool.sock
listen.owner = $pool
listen.group = apache
listen.mode = 660
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 20
pm.max_requests = 500
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]
php_value[session.save_path] = /home2/testuser2/tmp
php_admin_value[open_basedir] = /home2/testuser2/:/tmp/:/var/tmp/:/opt/alt/php84/usr/share/pear/:/dev/urandom:/usr/local/php84/lib/:/usr/local/php84/lib/:/usr/local/php83/lib/:/usr/local/php82/lib/:/usr/local/php81/lib/:/usr/local/php80/lib/:/usr/local/php74/lib/:/usr/local/php73/lib/:/usr/local/php72/lib/:/usr/local/php56/lib/:/usr/local/lib/php/
php_admin_value[mail.log] = /home2/testuser2/.php/php-mail.log
security.limit_extensions = .php .php52 .php53 .php54 .php55 .php56 .php60 .php70 .php71 .phtml .inc .php84

Bash:
# cat /usr/local/directadmin/data/users/testuser2/php/php-isolated-fpm84.conf

[global]
error_log = /dev/null
log_level = notice
process_control_timeout = 60s
[main]
listen = /tmp/main.sock
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 20
pm.max_requests = 500
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]
php_value[session.save_path] = /home2/testuser2/tmp
php_admin_value[mail.log] = /home2/testuser2/.php/php-mail.log
security.limit_extensions = .php .php52 .php53 .php54 .php55 .php56 .php60 .php70 .php71 .phtml .inc .php84

Bash:
# grep ^testuser2: passwd
testuser2:x:1012:1014::/home2/testuser2:/usr/bin/jailshell
 
@zEitEr, is it working for you with the |HOME| placeholder in /usr/local/directadmin/data/templates/custom/php-fpm.conf.custom2? It's not working for me. That's what I'm trying to achieve, so that every user has their php error log in their logs directory within their account as the default. php-fpm.conf.custom2 works with the |USER| and |DOMAIN| placeholders, so I optimistically hoped |HOME| would also work (which I found in some of the other template scripts). Seems not, so looking for other inspiration! :)
 
affirmative:

Bash:
# cat /usr/local/directadmin/data/users/testuser2/php/php-isolated-fpm84.conf

[global]
error_log = /dev/null
log_level = notice
process_control_timeout = 60s
[main]
listen = /tmp/main.sock
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 20
pm.max_requests = 500
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]
php_value[session.save_path] = /home2/testuser2/tmp
php_admin_value[mail.log] = /home2/testuser2/.php/php-mail.log
security.limit_extensions = .php .php52 .php53 .php54 .php55 .php56 .php60 .php70 .php71 .phtml .inc .php84
php_admin_value[error_log] = /home2/testuser2/testuser2/domains/testuser2.com/logs/php_errors.log


Bash:
# cat /usr/local/directadmin/data/users/testuser2/php/php-fpm84.conf

[testuser2]
user = $pool
group = $pool
listen = /usr/local/php84/sockets/$pool.sock
listen.owner = $pool
listen.group = apache
listen.mode = 660
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 20
pm.max_requests = 500
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f [email protected]
php_value[session.save_path] = /home2/testuser2/tmp
php_admin_value[open_basedir] = /home2/testuser2/:/tmp/:/var/tmp/:/opt/alt/php84/usr/share/pear/:/dev/urandom:/usr/local/php84/lib/:/usr/local/php84/lib/:/usr/local/php83/lib/:/usr/local/php82/lib/:/usr/local/php81/lib/:/usr/local/php80/lib/:/usr/local/php74/lib/:/usr/local/php73/lib/:/usr/local/php72/lib/:/usr/local/php56/lib/:/usr/local/lib/php/
php_admin_value[mail.log] = /home2/testuser2/.php/php-mail.log
security.limit_extensions = .php .php52 .php53 .php54 .php55 .php56 .php60 .php70 .php71 .phtml .inc .php84
php_admin_value[error_log] = /home2/testuser2/testuser2/domains/testuser2.com/logs/php_errors.log
 
Once again, massive thanks @zEitEr, I noticed in your last post the path had the username twice and realised it should have been:
Code:
php_admin_value[error_log] = |HOME|/domains/|DOMAIN|/logs/php_errors.log
(not |HOME|/|USER|/domains/|DOMAIN|/logs/php_errors.log)

All working now. Very happy, thank you!
 
Last edited:
Back
Top