1. PHP Installation Considerations
Before PHP installation, it is advised to understand the basic need. Usually, PHP is installed to carry out the following tasks:
- Web Development and Web Application Development
- Command Line Scripting
- Desktop Development or Desktop Applications
1.1. What are PHP Installation Requirements?
After determining the desired category of development, there is a need to identify that what are the requirements of PHP installation? There are three main requirements to configure PHP which includes:
- PHP Itself Or It’s Core Libraries to Carry out the Interpretation
- A web server or Web Hosting
- An Operating system and a web browser installed on it
2. PHP Installation On Various Systems
Indeed, there are several ways to install PHP on the operating systems. These may comprise of compile and configure method and pre-packaged method. Moreover, PHP installation has separate methods on different operating systems. Follow the links below to discover the installation methods provided by php.net.
- PHP Installation on UNIX Systems
- PHP Installation on macOS
- Installation on Linux Operating System
- Installation on Windows Operating Systems
- FastCGI Process Manager (FPM) (For Heavy Sites)
Normally, PHP is already installed on macOS and Linux.
3. PHP Installation on Windows
Habitually, web developers install PHP on their operating systems to locally test their PHP code. The subsequent PHP tutorial illustrates the installation of PHP on the Windows operating system. Also, PHP installing software or PHP composer is available besides manual installation. Below are two ways to install PHP on windows:
- Manual Installation of PHP
- XAMPP Server Installation
3.1. Manual Installation of PHP
Commonly, manual installation is not preferred because of its complicated process to install and configure. However, below is the method to install the PHP manually. Also, the subsequent tutorial comprehensively illustrates how to configure PHP 7 with Apache server.
- Download PHP Package
- Extract the PHP Package
- Configure PHP Package
- Set Path Environment Variable
- Configure Apache Package
- Run PHP File
Step 1: Download PHP Package
Firstly, download the newest version of PHP, i.e. PHP 7.4.6 from windows.php.net/downloads. Certainly, this package is a .zip or .rar file. Moreover, the version may be updated when you are installing it. Furthermore, make sure to download the thread-safe version.
Step 2: Extract the PHP Package
Secondly, create a folder in your computer like C:\php7 i.e. in Local Disk C. Now, the Next step is to extract the downloaded PHP package inside this C:\php7 folder.
Step 3: Configure PHP
Now, after extracting, configure PHP by copying all the text from C:\php7\php.ini-development file to C:\php7\php.ini file. After that, modify some lines of code inside php.ini, the newly created file.
Then, configure PHP by opening the php.ini file in a text editor and use search and replace for some modification.
i-Define Extension Directory
Next, locate for ; extension_dir = "./", remove the semi-colon ( ; ) and set the extension directory.
extension_dir = “C:\php7\ext”
Now, search for the following extensions and remove the semi-colon ( ; ) before them. Importanly, majority of the applications will run by enabling just these extensions.
extension=curl extension=gd2 extension=mbstring extension=mysql extension=pdo_mysql extension=xmlrpc
iii-Configure PHP mail() Function
Moving further, enter the details of an SMTP server in order to configure the PHP mail() function. This will enable the PHP to send emails.
[mail function[ ; For Win32 only. SMTP = mail.myisp.com //Change this to your ISP smtp_port = 25; For Win32 only. sendmail_from = email@example.com //Change this to your email address
Step 4: Set Environment Variable
Usually, the path environment variable is set to ensure the working of PHP. Therefore, open system settings and set the path variable as below:
Step 5: Configure Apache Module
Firstly, download the Apache from apachelounge.com.
Secondly, configure PHP as apache module by following these steps:
i-Check Apache Installation
In the first place, make sure to check if the apache is already installed by giving this command in command prompt.
httpd -k start //if it is installed already, it will run successfully.
ii-Extract Apache Package
Now, extract the apache package and rename it to Apache24. Put this folder in C drive with the path as C:\Apache24.
iii-Configure Apache httpd File
Next, open the Apache directory and navigate to the conf folder. Open the httpd.conf file in a text editor and make the following modifications.
Search for DirectoryIndex on line 239 and add index.php as the default file.
<IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
The next step is to set the ServerName by searching ServerName and modify as follows. Make sure to eliminate the hash #.
Eventually, go to the bottom of the httpd.conf file and add below lines of code to finish the apache configuration.
# PHP7 module LoadModule php7_module “C:/php7/php7apache2_4.dll” AddHandler application/x-httpd-PHP .php PHPiniDir “c:/php7”
iv-Install And Run Apache
The final step in the Apache configuration is to install it. Open the command prompt as Administrator and enter the below command.
// To change the directory to bin directory cd C:\Apache\bin // To install the service httpd -k install // To start the service httpd -k start // To stop the service httpd -k stop
Step 6: Run PHP File
- Initially, locate the index.php file in C:\Apache24\htdocs\. If there is no index.php file, then create one
- After that, open the file in a text editor, write some PHP code, and save it
- Further, now open the browser and write in the search bar 127.0.0.1/index.php or localhost/index.php in the search bar
- Finally, The browser will display the output of index.php
3.2. XAMPP/LAMPP/WAMP Server Installation
XAMPP or LAMP or WAMP is a PHP composer or a pre-package software, that contains all the needed components to run PHP on a system. It only requires installing the package and database configuration as illustrated below for XAMPP server:
a. How to Install XAMPP Server on Windows?
- This is an easy and automatic process
- Firstly, download the XAMPP server from sourceforge.net official website
- Secondly, the next step is to install the downloaded package by opening it
- It will automatically install PHP, Apache Server and database along with all the necessary settings
- Further, now run the XAMPP server from the XAMPP shortcut icon on desktop or start menu
- Lastly, iitiate the Apache and MySQL services only and you are good to go
b. How To Configure XAMPP and phpMyadmin on Windows?
- Firstly, initiate the MySQL and Apache services from XAMPP panel
- Secondly, go to 127.0.0.1/phpmyadmin
- In PHPMyAdmin, create a database with appropriate name as below
- XAMPP is all set up now and is ready to use
- Just navigate to c:\xampp\htdocs\ and open the file index.php
- Then, in index.php file, write the PHP code and save it
- Now open the URL address 127.0.0.1/index.php or localhost/index.php in the search bar
- Atlast, the browser will display the output of index.php