Friday, February 20, 2009

Learning PHP

So far this semester I don't have any really neat projects to work on for school and I seem to have a fair amount of free time on my hands. So I decided to start learning my way through the LAMP stack. I already have some familiarity with Linux from experimentation and my knowledge of SQL is pretty respectable. I have experience working with Access and Oracle and learning MySQL will be nice. The first thing to learn is PHP. I found a nice looking tutorial here and started working my way through it.

Before I could really begin, I configured my Mac for use with PHP and Apache. Both of these come bundled with OS X 10.5 but are not active my default. Apache is turned on by going through System Preferences to the sharing menu. Checking the box marked "Web Sharing" activates Apache, with the directory where it stores pages located at "/Library/Webserver/Documents". The local webserver is viewable at "http://localhost/". I created a new folder in here to store my PHP files and created a link to it from my Home directory using the commands from this post.

Activating PHP involved manually editing a config file. The file is located at "/etc/apache2/httpd.conf". This is a hidden system file so in order to find it you'd have to either show all hidden files or navigate directly to that folder using the "Go to Folder" command in Finder available from the Go menu or with the keyboard shortcut command+shift+G. To show all hidden files instead, there are two methods I have used in the past. First is the Terminal command "defaults write AppleShowAllFiles -bool true". This is followed by the "KillAll Finder" command. This will restart Finder and all hidden files will be visible. To hide them again reuse the first command but swap "true" at the end for "false". The other option is a graphical program Houdini.

In the httpd.conf file, lines are commented out using the "#" character. Everything following this is considered a comment and ignored by the system. Uncommenting the line that reads "#LoadModule php5_module libexec/apache2/" by removing the "#" at the beginning will enable PHP.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.