Tuesday, July 14, 2009

Blog Moved.

Please visit http://www.ielashi.com for my updated blog.

Sunday, November 16, 2008

Installing PHP

In the following video I guide you in installing PHP, Apache, and MySQL on Mac OS X.


Intro to PHP

Since PHP was created by Rasmus Lerdorf in 1995, it grew to be one of the most popular programming languages used for website development. According to PHP’s official website, more than 11 million websites use PHP. These websites include Yahoo!, facebook, Wikipedia, and myYearBook.

1.0 What is PHP?

PHP stands for Hypertext Preprocessor. It is a general-purpose scripting language used for website development. Rasmus Lerdorf, the creator of PHP, defines it as “a cross-platform, HTML-embedded, server-side web scripting language”.

If you are new to programming, this definition will most likely sound like dull and puzzling. Thus, let’s analyze this definition and see what it means.

Cross-platform: PHP can be installed on a host of different operating systems. Whether you’re using Windows, Linux, Mac or Solaris you can easily install and develop in PHP.

HTML-embedded: If you’re not familiar with HTML, it stands for Hyper Text Markup Language and is the language responsible for the layout of elements in a webpage. You can read more about HTML here.

PHP being “HTML-embedded” means that the PHP code that you write can be put inside your website’s HTML code. That way, PHP fetches the data and HTML takes care of the layout and appearance of the data on your webpage.

"I don’t get it. So a browser can interpret and understand PHP just as it does with HTML?"
No. A browser does not understand PHP code. When a user opens a PHP page, the server (see below) interprets the PHP code and dynamically generates HTML code from it. Thus, a PHP website can offer each of its user a customized page.

Server-side: A server is a computer that transfers information stored on it to other computers. In our case, your server is the machine on the internet that has your website stored on. When a person visits your website, the server sends that person the data of your website.

“Server-side” means that PHP code is run and executed on the server machine. It does not directly interact with the users’ computer. It can’t initiate actions based on, say, a user's mouse click or a user’s web browser.

Javascript, a client-side scripting language, can, on the other hand, interact with the user’s computer. It can respond to the user’s mouse actions, screen size, browser, and so forth.

"So why not just use Javascript?"
Because Javascript does not have the functionalities of PHP. It can’t access the server to read files or communicate with databases.


"So which one should I choose?"
Fortunately, you can use both! PHP can be used for fetching and storing the data from users while Javascript is used to make your website more interactive.

Scripting Language: PHP code is not compiled into an application, but rather resides in the form of scripts. Scripts are, in a very simple sense, pieces of code that run independently of each other.

2.0 What can PHP be used for?

PHP can do many tasks, including but not limited to:

Communicating with databases: PHP can read and write information to and from databases. This opens a door for websites to store data on the server such as product information or client information. Some of the databases supported by PHP include:
  • MySQL
  • Oracle
  • Microsoft SQL server
  • PostgreSQL
  • Ingres
  • Informix
Accessing files: PHP can read, write and create websites. This can be useful if a website needs frequent backups or needs to save information temporarily to a file before storing it in a database.

Securing web pages: you can create password protected web pages that only users with a valid username and password will be able to see.

Generating graphics: PHP can generate graphics, such as graphs and charts on the fly. Graphpite is one of the popular PHP graphing tools.

3.0 Why use PHP?

  • Easy to use: the code is very simple and easy to understand.
  • Fast: the time it takes to process a webpage written in PHP is relatively short.
  • Secure: if written correctly, the code is hidden from viewers and only available for the website developer.
  • Cross platform: as previously noted above.
  • Extensible: PHP can be easily expanded on with new modules. It is also open source, so engaging in its expansion is permitted and encouraged.
  • Best of all – it’s free!

Enough theory! In the next tutorial I’ll be showing you how to install PHP on Windows, Linux, and Mac using a simple tool called XAMPP.