How to setup PHP on your machine?

Abhigyan Singh 08th Oct 2020

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

  1. Download the Apache Windows MSI Installer from https://httpd.apache.org/download.cgi
  2. Download the PHP Windows Zip package from https://php.net/downloads.php
  3. 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.
  4. Select typical setup
  5. Choose the destination folder for the server. By default, it will be C: Program FilesApache Software Foundation
  6. Select Finish to complete the installation.

After this, the Apache server needs to be configured as follows.

  1. 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.
  2. Change the DocumentRoot to point to the location of the root document folder.
  3. 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”
  4. 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.
  5. Append the following lines to the end of the httpd.conf file:
    1. LoadMoudle php_module
    2. AddType application/x-httpd-php.php
    3. PHPIniDir “C:php”
  6. Save and Close.

Installing PHP

  1. Unzip the PHP files to C: PHP
  2. Copy C:phpphp-in-recommended.ini  and rename it as C:phpphp.ini
  3. Uncomment the windows include_path from line 506
  4. Update the doc_root to match the one that was set up in the httpd.conf file on line 513.
  5. Update the extension_dir on line 520 to “C:phpext”
  6. Uncomment php_gd2.dll extension on line 637.
  7. Uncomment mysql.dll extension on line 651.
  8. Update the session.save_path to the Windows temporary files directory ( i.e C: Temp).
  9. The PHP Directory needs to be added to the path environment variables
  10. Open the control panel
  11. Open System > Advanced > Environment Variables
  12.  Append C: PHP to the end of the Path System Variables list and click OK.
  13. 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.

Installing XAMPP

XAMPP is a control panel developed and programmed by Apache. It contains different services like Apache, PHP, MySQL, Filezilla

Steps

  1. Download latest version of XAMPP from https://www.apachefriends.org/en/xampp-windows.html
  2. Double click on the file which you have downloaded
  3. 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
  4. After that click on the install button and it will start extracting files.
  5. 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
  6. Well that’s it you have successfully installed XAMPP which will allow you to develop and execute PHP scripts on your computer.
  7. To Start Services, go to Windows>All Programs > Select XAMPP
  8. Click on the XAMPP control panel start the required services
  9. Open the browser type https://localhost.
  10. It's done to enjoy learning PHP now.

 

Authored By Abhigyan Singh

He is a continuous blogger and has blogged on different topic. He loves to surf Internet and always trying to get new Idea about new Technology and Innovations and sharing these great information to all the technology lovers.

Also on DiscussDesk