More on Getting PHP Up and Running on the way to Hosting your own Forum Server
Her's where we left off... Enabling PHP on your mac running Panther or Jaguar. So you need to get it running? It comes already installed, so all you need to do is follow a few simple steps in Terminal. You already know that when you open up a new window in terminal, the prompt tells you where you are – the “~maybeso” means you are in the home directory because that is how you logged in on your mac in the first place. You need to get to your root directory – All the other web sites that try to help you forget that most folks delving into unix are not geeks – they just want to do something that requires a little knowledge – they forget that you don’t know the basics of the command line interface – (CLI) that is all Terminal is. To get to the “root” directory from your prompt just type in “cd /” without the quotes. You will see something like this :
Garbo:~ maybeso$ cd /
Garbo:/ maybeso$
That “slash” or forward slash means you are in the root directory. Now type in “ls” that is an Ls but lower case. You should see a list of folders and files. Find one named “etc” and then at the prompt type in cd etc
this takes you to that folder or directory. Type “ls” again and you will see another list of files and folders. If you have a folder called “httpd” you are getting closer to your goal. Type cd httpd or cd /httpd to change directories to that one. Type “ls” and you will find a file called httpd.conf. That is the one you want. You are going to change this file, and it is an important file so you NEED to BACKUP this file before proceeding. This file is the configuration file for most of the system-wide settings in Unix. How to back up the file? While you are in the same directory you likely saw a file called httpd.conf.applesaved. That is your backup file for this file. You need to make a backup that you know is pre php changes so we will call the new backup file “httpd.conf.phpsaved. To do this you can do it this way:
Garbo:/etc/httpd maybeso$ sudo cp httpd.conf httpd.conf.phpsaved
it will ask you for your root password.
Password:
Garbo:/etc/httpd maybeso$
Now type “ls” to see if the new file is in that directory. If it is go to the next step. You will want to open up the httpd.conf file in a text editor. I use the included unix editor called pico. To open up the file in pico, stay in the same directory you were in. type sudo pico httpd.conf. What this does is tell unix to give you permission (sudo) to edit the file in Pico. Got it open? You should see the following :
## httpd.conf -- Apache HTTP server configuration file
Hehe – fooled you! You didn’t know about the apache server. That is what this file configures and you need this up and running properly to do most things with any server. The highlighted black squares are the commands to do things in the pico editor. To move around you use the Arrow keys. It moves the grey prompt which is the only place you can start typing. The other key commands are basically self-explaining – but for one thing – the Caret thingy in front of the commands such as ^V means to hold the control key while pressing the v key to page down. Got it? To find out more use the help command in pico.
The next thing you need to learn is what the heck the Number sign (#) means. Whenever you see the sign at the beginning of a line that means unix will not read and implement that line of code. It is called commenting the line out. To make a line work, you must uncomment it by removing the number sign at the beginning of the line and all other lines of that piece of code.
Keep in mind that what you are doing is making apache load, run and use PHP whenever it starts up. Next step: you need to find the
“LoadModule php4_module libexec/httpd/libphp4.so
AddModule mod_php4.c”
To find this line in the 1102 lines of the file use the Control W keys to find it and then type the first portion of the line you want to find in the black line and hit return. It will take you there. Delete the # sign by placing the grey cursor to the right of the # and delete it. Then scroll down to the addmodule area – just a few lines down and find the AddModule mod_php4.c and uncomment that line. For Mac os x 10.1 users you may need to add the following line :
addType application/x-httpd-php .php. Do a search using control W and search for addtype. Then cursor down to just below the other addtype uncommented line and add your line.
Back to the rest of the users – panther and jaguar – next find the
DirectoryIndex index.html index.htm index.php
to find it just search for directoryindex index.html. This set is likely to uncommented already – if so, leave it alone – unless you want to add the index.htm type like I did. The important thing here to make sure the index.php is in the directoryIndex line. Got it? Good! Now save that file by using control “O’ that is zero, and save to the httpd.conf file. To exit the pico editor – Control X and you are out!
Now, the easy way to restart apache is to go to your sharing panel in your systems preferences on your regular mac os system It is in your Dock or under the apple – Go to the sharing panel and start the personal web sharing. If it is running – turn it off then back on – that is the easy way to do it. The better, unix way to do it is to do this in Terminal: sudo apachectl restart
Terminal should then tell you apache is restarting.
Now you have to test it out – Remember where you turned on the personal web sharing? Just under the checkmarked box the computer will give you a line that will tell you where your web server is on your computer – in my case it was http://10.0.1.5/ - your mileage may vary.
Now, to test this php/apache stuff out you need to make a document called info.php and place it in the /library/webserver/documents/ folder. To make this file all you need is an editor that will save as plain text – like Textedit or BBedit. Open a new document in Textedit – and add these lines
Remove all the quote marks - they are only in there because the formatting in this blog wouldn't print the code correctly - If you can't get it right, let me know and I will post the file or send it to you. And you should get a page that show you the PHP logo and tells you your php configuration. Congrats to YOU! You are now in the web server bidness! If you have probs, feel free to leave a question or an answer in the comments on this article. Thanks for playing “You’ve got PHP!”<
?php
phpinfo();
?>
Make sure you select under the textedit menu FORMAT – make plain text. Then save it as info.php and place it where I said in the paragraph above.
Now, open a new page in Safari and type your web server address Example: http://10.0.1.5/info.php

