Website is optimized in multitude of ways. Diversified components have to align in cordial style to generate desired user experience. Moulding a dimension that is NOT actually demanding alteration of settings for faster performance can not spare for the requiring element. Web server is often overlooked and under-estimated for tight configurations with back-end technologies.
In this text, we will see best commands, their switches and steps for configuring PHP with Apache web server.
Pre-requisites
You already need to have a working computer, good internet connection and a Linux or Windows operating system installed at your disposal.
Alternatively, you can obtain distributions of both these softwares from first source sites. Whether you install them from binaries or building from source code – both are fine.
We want to overcome common pitfalls that come in the way if we do NOT care of.
Scope
The purpose, scope, and default values of many of PHP’s most commonly used configuration directives are similar for most Unix flavours. If you are using very specific distribution, you may need to refer their documentation.
By no means, this discussion serves as one-stop self-contained reference, rather it is aimed to become useful, non-nonsense guide that can ease the life of developers.
Procedure
It is good that you possess successfully working, tested set-up of PHP and Apache.
However, we need to make at least a few run-time changes so as the software can operate up to your satisfaction.
Majority of these changes are handled through work-around on Apache’s httpd.conf file and PHP’s php.ini file.
Each and every file contains a myriad of settings or directives that collectively control the behaviour of each component.
We will keep our observations limited to Apache’s configurations that affect PHP website.
Pitfalls after installation
Before we bring first PHP-enabled page online, we meet with errors in browsers.
Below list touches upon some of the common symptoms:
- Changes made to Apache’s configuration file will NOT take effect until Apache is restarted.Therefore, be sure to restart Apache after adding any PHP-specific lines tohttpd.conf file.
- Take care when you modify the Apache configuration file, we don’t want to accidentally introduce any invalid characters that can not be processed or abnormally interpreted by Apache. So start, go back, save the file and then execute.
- Verify that all files are attached with any PHP-specific extensions as recognizable by the httpd.conf file.
- Appropriately delimit your PHP code within the file. Neglecting tofollow this will cause to generate error as output in the browser.
- Add index.php to Apache’s Directory Index directive. Otherwise index.html will be referenced by web server for initiating a website out of your will.
Recommendations for php.ini file
There are two initialization parameters’ files bundled with PHP source code.
We will elect php.ini file instead php.ini-dist as it recommended by most PHP folks. It is likely to save you time and efforts in securing the application.
Although default values go with healthy state of application for a time, additional adjustments become necessary to achieve full mileage.
The php.ini and httpd.conf are PHP’s and Apache’s global configuration files respectively.
We are allowed to set thresholds for parameters related to below indications :
- Language Options
- Data Handling
- Safe Mode
- Paths and Directories
- Syntax Highlighting
- Miscellaneous
- Resource Limits
- Error Handling and Logging
- Dynamic Extensions
- File Uploads
- fopen Wrappers
- Module Settings
Each of these features or settings are supplied towards handling of special functionality of PHP web application.
Code lines in php.ini file with ; as starting character define comments.
Statements consisting = operator are assignment pairs.
;
; Safe Mode
;
safe_mode = Off
Therefore, from above snippet, we can see that the parameter safe_mode is assigned the default value Off.
Once you’re comfortable with unique purpose of each single directive, consider deleting the accompanying comments and embellishing its values to streamline the file’s contents. This also provides better readability.
When changes will take effect depends on the way you installed PHP. If PHP is installed as a CGI binary, the php.ini file is re-decipher each time PHP is invoked. So as we run website from IDE(integrated development environment), modifications show effects instantaneous.
If PHP is installed as an Apache module, php.ini is only read when the Apache daemon process is invoked. So we have to restart Apache when settled PHP in latter way so as to watch impacts of new values of parameters.
Bliss Web Solution Pvt. Ltd is a well known web development company of India. It offers custom mobile applications development, open source development, eCommerce solutions with outstanding focus on Magento, and web services projects across the world.