We could override the default php.ini settings using the
PHPINIDir /var/www/web1
directive in <VirtualHost> decription.
But I have seen php_value statements which is applied to all the sites in the httpd.conf files. For example :
php_value upload_max_filesize somevalue
Will the general settings like above override the custom php.ini settings?
Pardon me that I don't have an environment to test this out at present.
PHP configuration precedence order is as follows:
The php.ini
The conf.d directory. On some distros, there is a modularized conf.d directory. values specified in there override php.ini
The directive PHPINIDir /var/www/web1 replaces 1 and 2 with your custom php.ini
Apache virtual host configuration. e.g. "php_value error_reporting " overrides any php.ini
.htaccess files placed inside your webspace override the above configuration
Source code values specified in the source code override all other configuration
Some (security critical) options can only be set in higher level config files
Related
I have a clean install of a CentOs with php 5.2.13.
In php.ini that is loaded and present in the header of phpinfo() I have
safe_mode=off
in the phpinfo() information I have
// local value - safe_mode: On
// master value - safe_mode: off
the php file has only a phpinfo() function.
I am still looking for vhost file to see if any directives are there overwriting this, but still then any sugggestions?
Look for "Additional ini files parsed" in phpinfo() output. This setting can also be changed in the Apache config (including .htaccess files).
"Master Value" (from php.ini) could be overridden with "Local Value" in httpd.conf, .htaccess or other Apache configuration with php_value directive.
I found the problem/solution to be in the extra config file that is added in the vhosts folder.
The file is named httpd.include and it has this line
php_admin_flag safe_mode on
PS. I really hate when other systems create files on the fly like this, especially with values they want.
With EasyApache3 and Php5.4, the server was setup whereby the parameter values in the master php.ini file could be adjusted per account using a local php.ini file located in the account root. Having upgraded to EasyApache4 and Php 5.6 this configuration structure does not seem to be working, the local php.ini file shows as loaded in phpinfo.php but the parameters set do not change the master values eg:
post_max_size 20M
And ideas please?
With EA4 by default there's one server-wide php.ini located at /opt/cpanel/ea-php56/root/etc/php.ini but when the MultiPhp Editor is used I believe it creates ini files at /opt/cpanel/ea-php56/root/etc/php.d/local.ini, public_html/php.ini, and public_html/.user.ini where the hierarchy is:
php.ini > local.ini > .user.ini
So .user.ini over-rides local.ini which over-rides the server-wide php.ini
Although the MultiPhp editor creates it, public_html/php.ini seems not to be used as long as user_ini.filename is not set, since the default for user_ini.filename is .user.ini, and as long as there is not a directive in .htaccess
Ref: https://forums.cpanel.net/threads/ea4-php-ini-local-ini-behavior.559871/
I have mbstring.func_overload = 7 in my php.ini, and I need to have it set to 0 for one directory. I have found out I cannot use .htaccess when using PHP via mod_fcgid as I do in my Debian installation.
I have created a .user.ini in the directory where I want this setting set to 0 and I also placed a test.php containing a phpinfo(); line inside the same directory, to see if this .user.ini takes effect.
Beside of the setting above that I WANT to change I also put some other PHP settings in this .user.ini files which I will not keep there, they are just to notice if something actually changes.
My .user.ini:
post_max_size = 12M
upload_max_filesize = 128M
[Date]
date.timezone = "UTC"
[mbstring]
mbstring.language = German
mbstring.func_overload = 0
The strange thing is: all the above settings are accepted and shown as they are in my .user.ini when requesting the test.php file, as "local" settings, except one: mbstring.func_overload is still 7 both for local and global configuration.
Any hints why mbstring.func_overload is ignored while other PHP settings in my .user.ini work perfectly?
I have same problem. I can change any mbstrings-settings in .user.ini, but not mbstring.func_overload.
UPD: I found a reason - mbstring.func_overload can't be redefined in .user.ini, because have status PHP_INI_SYSTEM.
This setting can only be changed from the php.ini file.
Solution. Add follow lines into nginx.conf:
`
location ~ \.php$ {
fastcgi_param PHP_VALUE "date.timezone='Europe/Berlin'
mbstring.func_overload=2
memory_limit=1024M";
...another fastcgi-options...
}
`
I've installed EasyPHP WAMP for local development only (I'm not hosting any websites).
Is there a way to set custom php settings for separate virtual hosts?
Currently and out-of-the-box, the php.ini file is loaded from: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion\php.ini It would be nice if, say, I could drop in a custom php.ini file into the virtual host directory to override settings in the original php.ini This way, I could better emulate a production server's environment on a per-site basis.
I've seen this work with online hosting accounts. But I can't figure out how to make this work on my machine.
Using custom php.ini files is pretty straighforward for CGI/FastCGI based PHP installations but it isn't feasible when running PHP as Apache module (mod_php) because the whole server runs a single instance of the PHP interpreter.
My advice:
Set from PHP itself as many settings as you can:
ini_set('memory_limit', '16M');
date_default_timezone_set('Europe/Madrid')
...
In other words, directives that can be changed at runtime.
Set the rest of stuff from per-directory Apache setting files (aka .htaccess):
php_flag short_open_tag off
php_value post_max_size 50M
php_value upload_max_filesize 50M
i.e., settings that need to be defined before the script starts running
Please have a look at the Runtime Configuration for further details.
Sometimes, you'll actually need different settings in development and production. There're endless ways to solve that with PHP code (from creating a boolean constant from the $_SERVER['HTTP_HOST'] variable to just having a config.php file with different values) but it's trickier with .htaccess. I normally use the <IfDefine> directive:
<IfDefine DEV-BOX>
#
# Local server directives
#
SetEnv DEVELOPMENT "1"
php_flag display_startup_errors on
php_flag display_errors on
php_flag log_errors off
#php_value error_log ...
</IfDefine>
<IfDefine !DEV-BOX>
#
# Internet server directives
#
php_flag display_startup_errors off
php_flag display_errors off
php_flag log_errors on
php_value error_log "/home/foo/log/php-error.log"
</IfDefine>
... where DEV-BOX is a string I pass to the local Apache command-line:
C:\Apache24\bin\httpd.exe -D DEV-BOX
If you run Apache as service, the -D DEV-BOX bit can be added in the Windows registry, e.g.:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Apache2.4\Parameters\ConfigArgs
Related: Find out how PHP is running on server (CGI OR fastCGI OR mod_php)
Developing Multiple Domains on One Machine?
Embedding php.ini settings in the httpd-vhost.conf, typically found in your server root under conf/extra/, is a great way to solve this common problem. If you never knew you could do this, see the PHP.net Manual under How To Change Configuration Settings. This will solve the pesky include_path problem, without adding configuration code to your bootstrapping code or anything else.
Of course, to use this effectively as localhost, you would need to make copies of a <VirualHost> block and configure each accordingly. Then, comment out all virtual host blocks except the one that you want to use!
Alternatively, one could start Apache with the -f option to point the server daemon to a different httpd.conf upon starting. Each httpd.conf would require an "if module block," such as and <IfModule phpx_module> block. Be sure to remember to account for Apache logging!
httpd -f /usr/local/apache2/conf/domains/fooDomain.conf
httpd -f /usr/local/apache2/conf/domains/barDomain.conf
Virtual Host Block With php.ini statements.
<VirtualHost 127.0.0.1:80>
UseCanonicalName On
ServerName localhost:80
ServerAdmin you#localhost
CustomLog "/var/www/someDomain.com/data/logs/httpd_access_log" common
ErrorLog "/var/www/someDomain.com/data/logs/httpd_error_log"
LogLevel warn
DocumentRoot "/var/www/someDomain.com/public"
<Directory "/var/www/someDomain.com/public">
# disable directory listing
Options -Indexes +FollowSymLinks
AllowOverride FileInfo
Require all granted
</Directory>
<IfModule alias_module>
# Alias /webpath /full/filesystem/path
ScriptAlias /cgi-bin/ "/var/www/someDomain.com/scripts/cgi-bin/"
</IfModule>
<IfModule php7_module>
# Use php7_module in opening statement above if on PHP 7+
# Domain specific PHP configuration options.
# The Apache process user must own any of the following directories.
php_admin_value include_path "/var/www/someDomain.com/application/controllers:/var/www/someDomain.com/application/models:/var/www/someDomain.com/application/views"
# Errors and Logging
php_admin_flag display_startup_errors off
php_admin_flag display_errors off
php_admin_flag html_errors off
php_admin_flag log_errors on
php_admin_value error_log "/var/www/someDomain.com/data/logs/php_error_log"
# File Related
php_admin_flag file_uploads on
php_admin_value upload_tmp_dir "/var/www/someDomain.com/data/uploads"
php_admin_value upload_max_filesize 10M
php_admin_value max_file_uploads 5
# Sessions
php_value session.save_handler "files"
php_value session.save_path "/var/www/someDomain.com/data/sessions"
# Caching
php_value soap.wsdl_cache_dir "/var/www/someDomain.com/data/cache/sopa.wsdl"
</IfModule>
</VirtualHost>
If you could use the %{SERVER_NAME} variable in conjunction with the <IfModule phpx_module> blocks to form a compound conditional, you could have just one httpd.conf`, or include a extra/php.conf with all the domain specific PHP.ini settings (in blocks, also). However, as long as "localhost" is the domain target, it will not do what you want. Thus, my answer in the virtual host block above.
Simple way to use custom php.ini file for vhost using Fast CGI is to copy the php.ini into a folder in the host like "customini".
After that to your vhost directive and add this simple line :
FcgidInitialEnv PHPRC "/path_to_your_custom_ini_dir_for_this_vhost/"
BE SURE TO HAVE / to your path no \, (it won't work with \)
Restart Apache.
That's all!
Full sample (on Windows Server here) :
<VirtualHost *:80>
DocumentRoot "C:/APACHE/htdocs/vhost/myvhost"
ServerName www.vhost.com
FcgidInitialEnv PHPRC "C:/APACHE/customini/myvhost/"
</VirtualHost>
Several commentors have mention Vagrant which is an excellent solution.
If you're not interested in using Vagrant, you can investigate using FastCGI as your interface to Apache and using the SetEnv PHPRC... suggestion proposed on this blog:
Apache & PHP: Multiple PHP.ini Configuration Files (Sunday, February 8, 2009)
Source: http://hyponiq.blogspot.com/2009/02/apache-php-multiple-phpini.html
The second work-around is to use the PHPRC environment variable
configurable in Apache using the SetEnv directive. This directive
allows you to set an environment variable that is then passed to any
CGI script and/or Server Side Include (SSI) set in any static (x)HTML
page (or other document type). In this instance, you'd be telling each
PHP-CGI instance where to find its configuration settings. The example
would be (coinciding with the previous one):
# vhosts.conf
NameVirtualHost *:81
<VirtualHost *:81>
ServerAdmin admin#example.com
ServerName vhost.example.com
DocumentRoot "C:/path/to/doc/root"
ErrorLog "logs/vhost.example.com-errors.log"
# Set the PHPRC environment variable
SetEnv PHPRC "C:/path/to/doc/root/php.ini"
<Directory "C:/path/to/doc/root">
# ... yadda, yadda, yadda ...
# you get the point!
</Directory>
</VirtualHost>
However, the PHP documentation changing the runtime
configuration
suggests that you can use certain values like php_value to try
loaalong with, possibly the SetEnv directive.
He suggests another option not using FastCGI, instead leveraging the php_value, php_flag etc. configuration options.
Other's seem to have had some success with executing scripts through FastCGI though, see: Separate php.ini for different virtual hosts
Other suggestions involve the PHPINI directive, which may be pertinent for your needs, see: How do I limit PHP apps to their own directories and their own php.ini?
I have a clean install of a CentOs with php 5.2.13.
In php.ini that is loaded and present in the header of phpinfo() I have
safe_mode=off
in the phpinfo() information I have
// local value - safe_mode: On
// master value - safe_mode: off
the php file has only a phpinfo() function.
I am still looking for vhost file to see if any directives are there overwriting this, but still then any sugggestions?
Look for "Additional ini files parsed" in phpinfo() output. This setting can also be changed in the Apache config (including .htaccess files).
"Master Value" (from php.ini) could be overridden with "Local Value" in httpd.conf, .htaccess or other Apache configuration with php_value directive.
I found the problem/solution to be in the extra config file that is added in the vhosts folder.
The file is named httpd.include and it has this line
php_admin_flag safe_mode on
PS. I really hate when other systems create files on the fly like this, especially with values they want.