How to setup PHP on your machine?
After knowing the basic concepts of 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 which is developed and maintained by Apache Software Foundation. It is available for various operating system like UNIX, LINUX, WINDOWS etc.
Steps for installing PHP with Apache Sever
- Download the Apache Windows MSI Installer from http://httpd.apache.org/download.cgi
- Download the PHP Windows Zip package from http://php.net/downloads.php
- Execute the file downloaded for Apache , while installing Apache server it will ask to fill the information. The typical setup will use the default port 80.
- Select typical set up
- 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 following.
- Open httpd.conf file for editing on any editor like notepad. httpd.conf will be in sub directory 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 the 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 previous step . That can be found on line 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-ini-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 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 root directory , create a new php file on it and type 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(Web server), MySQL Database, PHP Language and PERL.
Here we will cover how to install XAMPP the process for WAMP & LAMP are almost similar.
XAMPP is a control panel developed and programmed by Apache. It contains different services like Apache, PHP, MySQL, Fillezilla
- Download latest version of XAMPP from http://www.apachefriends.org/en/xampp-windows.html
- Double click on the file which you have downloaded
- You will get a 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 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 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 XAMPP control panel start the required services
- Open the browser type http://localhost.
- Its done enjoy learning PHP now.
Share this Article on Social Media
Get Updates, Scripts & Other Tutorials to Directly to your Email
Over 20000+ Happy Readers already subscribed. (We don't send spam email). Every email subscriber can get our latest updates and download our 100+ scripts.