• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
The Electric Toolbox Blog

The Electric Toolbox Blog

Linux, Apache, Nginx, MySQL, Javascript and PHP articles

  • Applications
  • FCKEditor
  • Apache
  • Windows
  • Contact Us
Home / Set PHP configuration options in an Apache virtualhost

Set PHP configuration options in an Apache virtualhost

I’ve previously looked at how to set PHP configuration options in an Apache .htaccess file which allows you to change PHP_INI_PERDIR or PHP_INI_ALL settings but not PHP_INI_SYSTEM. All three of these settings types can be modified in an Apache virtualhost’s settings.

As an example, the "file_uploads" configuration option defines whether or not file uploads are allowed. This is a PHP_INI_SYSTEM option and if you attempt to set it in an .htaccess file as shown below then it will be ignored and the original value retained:

php_value file_uploads 1

When setting PHP_INI_SYSTEM options the "php_value" must be instead written as "php_admin_value". An example virtualhost might look like this:

<virtualhost *:80>
    ServerName www.example.com
    DocumentRoot /path/to/example.com
    php_admin_value file_uploads 0
</virtualhost>

This would then prevent file uploads for this particular virtualhost, and all the others would use the setting from the php.ini file, unless also defined like above.

Note that if you added the following to an .htaccess file you will get an internal server error message:

php_admin_value file_uploads 1

because only php_value directives can be included in .htaccess files.

There are also php_flag and php_admin_flag which can be used for settings which only have on and off (true/false, 1/0) settings but as shown above you can use php_value and php_admin_value for all settings including the flags.

Check Out These Related posts:

  1. Logging errors with PHP
  2. Apache .htaccess recipes, tips and tricks
  3. Automatically append or prepend files in a PHP script
  4. Set PHP configuration options with an Apache .htaccess file

Filed Under: PHP

Primary Sidebar

Categories

  • Apache
  • Applications
  • Article
  • Case Studies
  • Email Servers
  • FCKEditor
  • HTML And CSS
  • Javascript
  • Linux/Unix/BSD
  • Microsoft SQL Server
  • Miscellaneous Postings
  • MySql
  • Networking
  • Nginx Web Server
  • Offsite Articles
  • OSX
  • PHP
  • Quick Tips
  • RFC – Request for Comments
  • SilverStripe
  • VMWare
  • VPN
  • Windows
  • WordPress

Recent Posts

  • Vim Show Line Numbers
  • Add User To Group Linux
  • Chmod 777 Tutorial
  • How to Copy Directory Linux
  • Linux create user

Copyright © 2021. ElectricToolBox. All Rights Reserved.

  • Contact Us
  • Copyright Info
  • Privacy Policy
  • Sitemap