What is PHP?
PHP is known to be one of the most commonly used server-side programming language on the web. It provides an easy to master with a simple learning curve. It has close ties with the MySQL database, and various libraries to cut your development time.
Two Ways to install PHP locally.
There are several ways that we could install PHP locally. Here i have added two of the most common ways to install PHP as shown below.
- Installing a Web Server (XAMPP, WAMP etc)
- Implementing via PHP Installer
Installing a Web Server
There are many all-in-one packages are available for Windows and other OS’s which comes with Apache, PHP, MySQL and other applications as a single file installer, e.g. XAMPP, WampServer, MAMP etc. There is no any issue in going with these packages, however manually installing Apache and PHP will help you to have more control and access to its configuration options.
- WampServer
https://www.wampserver.com/en/
Implementing via PHP Installer
It provides several benefits for backing up, reinstalling, or moving the web server can be executed easily in a short amount of time and it provides more control over PHP and Apache configuration. In the Manual Installation, you need to configure several steps in order to install PHP successfully.
STEP 1 : DOWNLOAD THE PHP PACKAGE & EXTRACT THE FILES
Get the PHP version 8.0 or later (x64 Thread Safe) package zip file via navigating under the windows downloads URL mentioned in the link below.
https://www.php.net/downloads.php.
After, downloading the zip successfully to your PC, create a folder as “PHP” in any drive and extract the PHP package files into it.
STEP 2 : CONFIGURE PHP
Initially php.ini
file doesn’t exist inside the php package files. so copy {drive_name}:\php\php.ini-development and rename it as {drive_name}:\php\php.ini whereas the default configuration provides a development setup.
To uncomment a setting inside the php.ini file you need to remove a leading semicolon (;
). Uncomment the following lines to enable the required extensions whereas the following extensions are mostly required by many PHP frameworks and for other operations.
extension=curl
extension=gd
extension=mbstring
extension=pdo_mysql
STEP 3 : ADD PHP TO THE ENVIRONMENT VARIABLE
To access PHP globally at your PC add the PHP package path by following the steps below.
- Step 1: Click the Windows Start button and type “environment”.
- Step 2: Click Edit the system environment variables. Select the Advanced tab, and click the Environment Variables button.
- Step 3: Scroll down the System variables list and click Path followed by the Edit button.
- Step 4 : Click New and add
{drive_name}:\php
:
You are not required to reboot the PC, but you may need to close and restart any cmd terminals if you have opened before.
STEP 4 : TEST A PHP FILE
Create a new file named index.php
and add the following lines of codes and save it.
<?php
phpinfo();
?>
Run the PHP file by entering the following command in CMD where you have created the index.php file.
php index.php