Monday, August 30, 2004

Getting Started with PHP - Part 1: Installation.

To start learning PHP, you first need PHP running on your computer. If you totally have no idea what PHP is, you might want to read my earlier story: Why I like PHP / MySQL

Assumptions are you are a Windows user(since most Linux distributions have PHP & MySQL included), most probably why you would want to learn this is because you are a: 1) programmer that wants to program for online applications aside from desktop applications only or 2) a web designer that wants to learn programming to also get into web development.

What I am going to discuss, is how to install PHP on a Windows system. And I will tell you three different installation procedures.

1) PHP Manual Installation
2) PHP Windows Installer
3) Other PHP Packaged Installers

PHP has many extensions to the language, which is also one of the reasons why it is one of the most powerful server side programming languages. To enable all available extensions, you will need to manually install PHP that is basically done by extracting files from a compressed downloaded file, placing the files in a certain location, editing windows registry, configuring your web server and configuring the php.ini file.

Since this story is about "getting started," I do not recommend doing this. And most of the additional extensions you may use are not needed by the novice PHP programmer.

Now using the PHP installer is a lot easier, it has all the basic extension enabled already. And installs like any other software, just run setup and it’s all next, next, next.

Although, either manual or automatic, you need your web server software installed and preconfigured prior to your PHP installation, or else PHP will not work.

Windows 98 and ME comes bundled with the Personal Web Server (PWS) and Windows XP and 2000 comes bundled with the Internet Information Server (IIS) that you could add to your computer as long as you have the original Windows Installation CDs.

But being a novice PHP programmer, I highly recommend using other PHP packaged installers. There are several out there when you search sites like SourceForge or FreshMeat and part of the so many results, you'll get PHPTriad and PHPDev. These package installers are simple to install, just run setup. And when your done, you have just installed Apache web server on Windows, PHP and MySQL. And you could use it right away without any configuration whatsoever. I use PHPDev5 Beta and I do suggest you do the same.



You can download PHPDev5 Beta from FirePages, or click here to go straight to the download page.

Once downloaded, simply run the downloaded file, it is pretty straight forward, no confusing questions. And once installed, try running the program and you will see something like this:



Now since you are just starting out, you would only want to click on the Apache button and the MySQL button. You could install both Apache and MySQL as a service, but if you have a slow running computer, I suggest not installing it as a service. But you will have to always run PHPDev and start Apache and MySQL whenever you need to run them. If you have a fast computer, installing them as a service will also keep them running once you turn on your computer.

There is no PHP button since PHP starts to run whenever it is needed and called by Apache. You may also notice an Apache2 button, don’t play around with it yet. It is still kind of an experimental feature, so just use Apache alone.

Now after running PHPDev5, how do you test if apache is working?

Simply open your favorite web browser and visit http://localhost and this should display the files in the apache web root directory. If you get error 404, something is wrong. Be sure that you started Apache already before visiting http://localhost.

If you see files in the apache root web files, simply click on the start_here.htm file and it will give you a brief summary if everything is running and how can you test them further.

Now with PHP successfully installed, how do you start off learning PHP? Well that’s a long story but to get you started, let’s do a simple "Hello World".

So let’s say we are going to create a file that simply says "Hello World" using PHP. Just follow the instructions step by step below:

  1. Create the folder c:\my_first_php_file

  2. Open your favorite HTML editor or simply use Notepad and type in the following:

    <?php
         echo "Hello World<br>";
    ? >


  3. Save this file in the created folder and name it hello.php

  4. Open PHPDev, click on Apache, then Edit Config.

  5. You can actually type this anywhere but I suggest place it somewhere by the end of the text window, so it is easier to find in the future, just go to the end and type this:

    Alias /myfirst "c:/my_first_php_file /"
    <Directory " c:/my_first_php_file /">
         Options Indexes FollowSymLinks MultiViews
         AllowOverride None
         Order allow,deny
         Allow from localhost 127.0.0.1
         DirectoryIndex index.html index.htm index.php
    </Directory>


    Please take note you are typing forward slashes, not back slashes.

  6. Click on the Save button, then Close button. Then back at the Apache options, click on the Restart button.

  7. Now try visting: http://localhost/myfirst/hello.php

  8. That’s it! How boring!

  9. Now try something else, create a new file and type the following:

    <?php
         phpinfo();
    ?>


    Save it and name it index.php. Since it is the index page, this is the first page that will appear when you visit http://localhost/myfirst Check it out and see what happens. PHPInfo will show many details about the PHP configurations on the server. It does help a lot in the future when you start using the other PHP extensions and also when you use some Apache environment variables, and server environment variables, especially when uploading on a new server that you do not know how PHP is configured.
Although PHPDev5 can be used live on the Internet. As long as you know your IP address and is connected to the Internet, anyone can visit your page running Apache even on a dial-up connection. But this is not recommended at all. PHPDev is ideal for testing PHP programs offline on a local web server. And once your program is ready for uploading, you will upload your PHP program to a secure web server.

Now that you have your first PHP program running and you want to learn more, wait for my next articles, in the meantime, I suggest you download the PHP Manual, at PHP.net in the documents section. You could actually download a Windows Help File format and start learning PHP on your own. Anyway that is how I started. I downloaded the MySQL manual too.

4 Comments:

At 2:30 AM, Blogger Fleadis said...

keep it going sir! your site rocks!

 
At 1:54 AM, Anonymous Anonymous said...

sir dapat sir ,you need to put a single button download from your blog, kasi nahirapan akong,mag
save ng Blog pages mo ,very helpful kasi to...
it saves me time spending reading from message boards & forum
pwede ba iyon? ...."wondering"

twocarlo@yahoo.com

 
At 3:05 AM, Anonymous Anonymous said...

Ben you Rock. Thanks for the help

 
At 2:08 AM, Anonymous Anonymous said...

you are rock <---stone

 

Post a Comment

<< Home