Per-Domain php.ini settings - start point
With the many different types of php modes, this means the method of adding custom per-domain changes can vary greatly. Check your custombuild options.conf to determine which php1_mode you're using, and find the related guide below.
mod_php is the default and the most commonly used. You can use 3 different methods to change php settings:
.htaccess in the public_html to add php_admin_flag / php_admin_value
Admin Level -> Custom Httpd Config, to add php_admin_flag / php_admin_value
php-fpm is handy for multiple instances of php, allowing the User to change php version from within their User Level area. php-fpm does not support
.htaccess changes as php-fpm is it's own stand-alone php server, but you can use
The fastcgi mode is effective, but some find it somewhat rigid in it's flexibility (blend of suphp and php-fpm). To edit per-domain settings, you have 2 options:
- Manually create the .ini file at
/usr/local/directadmin/data/users/username/php/domain.com.iniand the call to fastcgi will read that in if it exists.
Note that it's a full replacement and not an 'addon' ini, so ensure you have all settings you need in that file, as the default php.ini isn't used here. Take a look inside the User's httpd.conf to see which .sh script is called, and the variables passed. Then check inside that .sh script for more info on how it works.
suhp is older, end-of-life, but some still use it. Your options are:
- per-User suphp setting, although you could just the "SetEnv" to the |CUSTOM| token on a per-domain basis at the Custom Httpd Config. Example:
SetEnv PHP_INI_SCAN_DIR /usr/local/directadmin/data/users/|USER|/php/
Note that some settings like disable_functions can only be set once in the main
php.ini file, and cannot be overridden by other areas, but this varies per php-mode. php-modes like php-fpm/fastcgi are much more stand-alone php instances, so you can get away with these types of overrides, away from the main
Where is my php.ini?
Depending of a setup the location of php.ini may vary. The easiest trick to find your php.ini would be to ask php itself what it's using, eg:
/usr/local/bin/php --ini | grep 'Loaded Configuration File'
which does assume that the php output will be in English.
Usually your php.ini will be located at (XX - PHP version, for example 73):
CustomBuild 2.0 installs will also uses the
php.conf.d directory to load miscellaneous .ini files into php. The files that CustomBuild will create are:
You can add your own files there if you need to add settings or load modules into php, for example
/usr/local/php74/lib/php.conf.d/11-custom.ini and place custom options inside.
The ever best option is to place phpinfo() page inside a domain DocumentRoot directory, create the file
phpmyinfo.php with content:
<?php phpinfo() ?>
Next open it in browser: http://example.com/phpmyinfo.php and watch for 'Loaded Configuration File' and 'Scan this dir for additional .ini files' .
How to increase the max upload filesize
Find where is your php.ini then edit it.
; Maximum allowed size for uploaded files. upload_max_filesize = 2M
Change the 2M to whatever new value you want, then restart apache.
Note, this setting may also be related:
; Maximum size of POST data that PHP will accept. post_max_size = 8M
Note, some RoundCube versions have limits set in the file
/var/www/html/roundcube/.htaccess so be sure to increase them there as well, if they are set.
For PHP-FPM service use this article.
Fatal error: Allowed memory size exhausted
If you see the error like:
Fatal error: Allowed memory size of 123456 bytes exhausted (tried to allocate 234567 bytes) in /path/file.php
Php is setup is to limit memory usage per process. If you require more, this limit can be increased.
Find where is your php.ini then edit it, search for
memory_limit = 8M
to a higher value, like 128M. Save, exit, then restart apache.
For PHP-FPM service use this article.
How to use per-domain or per-path settings for php
As suPhp is getting old, and doesn't have the performance of newer php types, many Admin's would want to combine the faster methods, while still keeping the ability to have per-item settings to allow custom changes where needed.
If you're using mod_php (cli), the bulk of the php settings can be set in the Custom Httpd Config with the standard php_admin_flag/php_admin_value settings right in the VirtualHost.
However, you might want even more control, say with a variable that isn't supported in that way, or with a path, rather than a host.
For this case, CustomBuild 2.0 uses a folder for additional php.ini files, loaded if they exist in the folder. The install path can vary depending on the php mode; in this example, we'll use
/usr/local/lib/php.conf.d but for other php modes, if the php version is 5.6, the path might be:
You can determine where you php.ini and php.conf.d folder is by using the where is my php.ini guide.
Once you know the path, let's use in our example, you can then create your custom ini file. The load of the ini files is done alphabetically, so we number the files to control in which order they're loaded in. Usually the order doesn't matter too much, unless you're altering settings for a module that should be loaded first.
1. Per-domain settings
If you would like to create per-domain settings for , you could create:
And add code like:
[HOST=example.com] session.save_path=/home/fred/tmp upload_tmp_dir=/home/fred/tmp
2. Per-path settings
Similarly, you can alter settings on a per-path basis, say for User which is handy if you want the settings to apply to a domains under that given path (usually, on a per-User basis), edit the file:
And set, for example:
[PATH=/home/fred] session.save_path=/home/fred/tmp upload_tmp_dir=/home/fred/tmp
In the above examples, it is implying the use of one file for each item you want to separate. This is not required. You can use one additional file to make load times faster, but also to hide the list of domains from the phpinfo() output, as all "additional" loaded php.ini files are displayed, so if you were to use:
you could add many [HOST=xx] entries into the same file, one after the other.
Based on: http://php.net/manual/en/ini.sections.php
How to allow <? and not require <?php
If you have scripts with the php tags:
but php isn't parsing the code between those tags, php may be set to require:
You can force php to allow the short tags by setting the following in your php.ini:
Related: Where is my php.ini
How to disable magic-quotes
If you need to disable magic quotes, the easiest way is to edit your php.ini and set:
magic_quotes_gpc = Off
and then restart apache.
Another way is to edit your php configure file and remove the line:
and recompile php.
Testing which uid php is running as to debug read/write issues
Often times, a php script needs write access to disk. Most new installs will use mod_ruid2+cli, suPHp, fastcgi or php-fpm, which should all run php as the given User, rather than as "apache".
To determine what uid a php process is running as, you can use this script to get a definitive answer:
<?php system('/usr/bin/id'); phpinfo(); ?>
Save this to an info.php file in a path you're trying to debug, then view it through Apache.
Note that this requires that both "system" and "phpinfo" not be set in your disable_functions list in your php.ini.