Showing posts with label PHP Configuration. Show all posts
Showing posts with label PHP Configuration. Show all posts

Wednesday, 12 September 2018

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.

Related posts:

Thursday, 4 September 2014

PHP Environment Setup

In order to develop and run PHP Web pages three vital components need to be installed on your computer system.
  • Web Server - PHP will work with virtually all Web Server software, including Microsoft's Internet Information Server (IIS) but then most often used is freely availble Apache Server. Download Apache for free here: http://httpd.apache.org/download.cgi
  • Database - PHP will work with virtually all database software, including Oracle and Sybase but most commonly used is freely available MySQL database. Download MySQL for free here: http://www.mysql.com/downloads/index.html
  • PHP Parser - In order to process PHP script instructions a parser must be installed to generate HTML output that can be sent to the Web Browser. This tutorial will guide you how to install PHP parser on your computer.

PHP Parser Installation:

Before you proceed it is important to make sure that you have proper environment setup on your machine to develop your web programs using PHP.
Type the following address into your browser's address box.
http://127.0.0.1/info.php
If this displays a page showing your PHP installation related information then it means you have PHP and Webserver installed properly. Otherwise you have to follow given procedure to install PHP on your computer.
This section will guide you to install and configure PHP over the following four platforms:
  • PHP Installation on Linux or Unix with Apache
  • PHP Installation on Mac OS X with Apache
  • PHP Installation on Windows NT/2000/XP with IIS
  • PHP Installation on Windows NT/2000/XP with Apache

Apache Configuration:

If you are using Apache as a Web Server then this section will guide you to edit Apache Configuration Files.

PHP.INI File Configuration:

The PHP configuration file, php.ini, is the final and most immediate way to affect PHP's functionality.

Windows IIS Configuration:

To configure IIS on your Windows machine you can refer your IIS Reference Manual shipped along with IIS.