PHP Configuration Environment – Info PHP
As we know, when we install PHP in our local machine using wamp or xampp like a local server provider then sometimes we need to configure our PHP work environment and that means changing the PHP configuration setting. More than 45 extensions are provided in the latest versions of PHP. To use these extensions one must uncomment some of the lines in the PHP.ini file.
For example, if we want to enable PHP’s XML-RPC extension then the following changes will be done in the PHP.ini file:
- Open the PHP.ini file and search for ;extension=PHP_xmlrpc.dll.
- Search for the line ;extension=PHP_xmlrpc.dll. Uncomment this line by removing the left-most (starting) semicolon. Save and close the file.
- Restart your web server and it’s done.
PHP Runtime Configuration
The PHP.ini file is a global configuration file that contains important sections, like language, Syntax Highlighting, Miscellaneous, Resource Limits, Error Handling and Logging, Paths and Directories, File Uploads, Dynamic Extension and so on.
For example, if we want to allow a short tag in PHP like:
Then we should enable it from the PHP.ini file and change the code snippet to what is found in PHP.ini.
short_open_tag = Off
Change Off to On and restart your server and see the changes. Actually the changes take effect depending on our installation process of PHP. If we install our PHP as a CGI binary then the PHP.ini file is reread every time PHP is invoked, thus making the changes every time. If PHP is installed as an Apache module then it is read only once when we start our Apache server.
Apache httpd.conf and .htaccess Files
There are basically four types of configuration scope for security reasons so that not all directives can’t be changed in the user’s PHP script. These scope are:
- PHP_INI_PERDIR: Only modified within the PHP.ini, httpd.conf, or.htaccess files.
- PHP_INI_SYSTEM: This Only modified within the PHP.ini and httpd.conf files.
- PHP_INI_USER: This modified within user scripts.
- PHP_INI_ALL: This can be modified anywhere.
When PHP is running in an Apache module then we can modify many directives using the httpd.conf file as shown in the preceding figure. This is done by prefixing the directory assignment with one of the following:
- PHP_flag: to set Boolean directive
- PHP_value: to set the value of the specified directive
For example, if we want to enable the use of short tags then we add the the following code snippet PHP_admin_flag short_open_tag On in the starting of httpd.conf file and restart our server if necessary.
We can modify the PHP configuration in our own PHP script file using the ini_set() function.
- ini_set(‘max_execution_time’, ’60’);
Some of PHP configuration directives and their scopes are as follows:
More Information and directives can be seen in our PHP.ini file. We can changes their default value depending on our use.
If we want to see all the information regarding our PHP installation then we would write the following code in our PHP file:
The PHP configuration environment provides an extensible nature for a project development by providing thousands of directives and their access level with information regarding them that can be found in the PHP.ini file or httpd.conf file.
Article Prepared by Ollala Corp