After knowing the basic concepts of install PHP, the next thing which comes to your mind is “Ok so how do I install PHP on my machine?”, so before proceeding further all you need is a proper environment setup on your machine.
Well, this article will guide you for the same.
Installing PHP with Apache
Apache is the web server that is developed and maintained by Apache Software Foundation. It is available for various operating systems like UNIX, LINUX, WINDOWS, etc.
Steps for installing PHP with Apache Server
- Download the Apache Windows MSI Installer from https://httpd.apache.org/download.cgi
- Download the PHP Windows Zip package from https://php.net/downloads.php
- Execute the file downloaded for Apache, while installing the Apache server it will ask to fill the information. The typical setup will use the default port 80.
- Select typical setup
- Choose the destination folder for the server. By default, it will be C: Program FilesApache Software Foundation
- Select Finish to complete the installation.
After this, the Apache server needs to be configured as follows.
- Open httpd.conf file for editing on any editor like notepad. httpd.conf will be in a subdirectory called conf in your directory of apache. Alternatively, a shortcut may be found in the start menu under the Apache HTTP Server folder.
- Change the DocumentRoot to point to the location of the root document folder.
- In the default httpd.conf file, this is found on line 149 and if the defaults were used during installation, it would point to “C: Program FilesApache Software FoundationApache 2.2htdocs”
- Change the directory path to match the one used in the previous step. That can be found online 177 of the default httpd.conf file. Add index.php to the Directory Index. This is found on line 212 of the default Http.conf file.
- Append the following lines to the end of the httpd.conf file:
- LoadMoudle php_module
- AddType application/x-httpd-php.php
- PHPIniDir “C:php”
- Save and Close.
- Unzip the PHP files to C: PHP
- Copy C:phpphp-in-recommended.ini and rename it as C:phpphp.ini
- Uncomment the windows include_path from line 506
- Update the doc_root to match the one that was set up in the httpd.conf file on line 513.
- Update the extension_dir on line 520 to “C:phpext”
- Uncomment php_gd2.dll extension on line 637.
- Uncomment mysql.dll extension on line 651.
- Update the session.save_path to the Windows temporary files directory ( i.e C: Temp).
- The PHP Directory needs to be added to the path environment variables
- Open the control panel
- Open System > Advanced > Environment Variables
- Append C: PHP to the end of the Path System Variables list and click OK.
- Restart Apache.
Well that’s it you are now ready with your PHP
To test PHP go to the root directory, create a new PHP file on it, and type the following code in it.
Save it as prog.php and run it.
There are other ways available to install PHP
The other and simplest technique to install and use PHP, Apache & MySQL is to use the tool like WAMP, LAMP, XAMPP
WAMP is an acronym for Windows (OS), Apache (web-server), MySQL (database), PHP (language).
LAMP is an acronym for Windows (OS), Apache (web-server), MySQL (database), PHP (language).
XAMPP is an acronym for X(any Operating System), Apache(The webserver), MySQL Database, PHP Language, and PERL.
Here we will cover how to install XAMPP the process for WAMP & LAMP is almost similar.
XAMPP is a control panel developed and programmed by Apache. It contains different services like Apache, PHP, MySQL, Filezilla
- Download latest version of XAMPP from https://www.apachefriends.org/en/xampp-windows.html
- Double click on the file which you have downloaded
- You will get an installation wizard where it will ask where you want to install your XAMPP, by default it will be C: drive, so if you want to change the installation drive you can change it
- After that click on the install button and it will start extracting files.
- Once all the files are extracted this will configure all the necessary setting and file paths automatically, which we have done manually for the previous installation. Press any key to continue after that
- Well that’s it you have successfully installed XAMPP which will allow you to develop and execute PHP scripts on your computer.
- To Start Services, go to Windows>All Programs > Select XAMPP
- Click on the XAMPP control panel start the required services
- Open the browser type https://localhost.
- It's done to enjoy learning PHP now.