Monday, October 14, 2013

How To : Install PHP 5

So now that we have Apache installed and our 2 virtual hosts configured, lets add a server side language so you can start using your web server. I know.... lets install PHP.

So what is PHP ?

PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. PHP code is interpreted by a web server with a PHP processor module, which generates the resulting web page.



So how do I install it ?

Well that's what I'm going to go over in today's post on How To : Install PHP.

There are a few different ways to install and configure PHP, and the way I'm going to show you how to do it is.....manually. Seriously... wheres the fun in letting an installer do it for you ?

So lets go download a PHP package.

Download PHP

Now which version do I use you may be asking ? Well since we are going to be deploying this on an Apache web server as a module, we want the Thread Safe version (Download the .ZIP).



After the download, extract it to a place on your computer (generally this is where it stays, so make sure it's in an easy spot to access).

After the .zip is extracted go to the location you installed it in and find the 2 php.ini-XXX files (XXX is either development or production).



Now, after finding these 2 files, we need to rename one of them. I am going to choose php.ini-development since this will be a development server ( I suggest you do the same ;) )

Rename the file to php.ini ( just get rid of the -development ) , it will ask you if you are sure... click yes and lets open the file.

Once opened, press CTRL + F and type in extension_dir . Keep hitting next until you see the line that looks like this :



Delete the semi-colon in front of it (thats how you comment lines out) and add a /to the end so it looks like this:
extension_dir = "ext/"
Save and close when done.

So now we have PHP installed and configured right ? Unfortunately not, there is a little more to it.

Remember where Apache was installed? If not go find it.

Next we have to tell Apache we installed PHP, and set it up so it can use it.

Go to your Apache folder, and open the conf  folder. Once inside open the httpd.conf , press CTRL + F and search for LoadModule. We are going to go to the end of the LoadModule section and add the following line :


LoadModule php5_module "C:/php/php5apache2_2.dll"
*WARNING - if you installed PHP somewhere other than your C:/ drive, change the path above or it will not work.

Next press CTRL + F and instead search for Addtype and we are going to add this line to the end of the Addtype section :

AddType application/x-httpd-php .php

Now, we have one final step to finish configuring PHP and creating a test file.

To complete the installation, you need to configure the PATH variable located on your computer. PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located.

So to configure this:

  1. Open your start menu, and
  2. Right click on Computer 
  3. Click properties
  4. On the left hand side click Advanced system settings
  5. A popup will appear, click on Environment Variables
  6. On the bottom half (should be a title named System Variables)
  7. Find the variable named Path, click it then click Edit
  8. Once the popup opens, be sure not to mess with anything. Go to the end of the textbox and type the following:

;C:\php

 *WARNING - if you installed PHP somewhere other than your C:/ drive, change the path above or it will not work.

** The semicolon at the start is to separate it from the other paths, if it is already there - omit the semicolon ;)

Once done, click OK 3 times to exit the properties.


YAY, PHP is installed and ready to go, lets test it. In your htdocs folder, create a new file named phptest.php  and paste the following code

<?php
 Echo "Hello, World!";
 ?> 
Now lets see if it works..... go to a browser and type in localhost and you should see:


Congratulations, you have successfully installed PHP on your Apache server,

Stay tuned for my next tutorial on How To : Install MySQL Community Server (5.5)

Thanks for reading !

No comments:

Post a Comment