Welcome Guest ( Log In | Register )


Why register for free on WebRadiance?
Welcome to WebRadiance forums! WebRadiance is a place for discussion and help on a large range of web design and development related topics such as HTML, CSS, ASP & .NET, PHP and SEO. It is provided for free, without ads and is a friendly place for beginners and professionals alike. By joining us today you can take part in our rapidly growing community.

Registering enables you to:
  • have your say by posting new messages and taking part in topics and polls
  • keep up to date with the latest news and trends in the web design and development world
  • send private messages to other members
  • have your questions answered by our knowledgeable community
  • add a link to your website in our links area
  • receive emails when someone replies to your posts

How to run PHP on OS X within the Sites directory

More of a local hosting thing, on your own computer.

 
Reply to this topicStart new topic
> How to run PHP on OS X within the Sites directory, More of a local hosting thing, on your own computer.
Marc Amos
post Nov 3 2006, 08:11 PM
Post #1


W.R. General
Group Icon

Group: Administrators
Posts: 2,799
Joined: 4-April 06
From: Massachusetts - USA
Member No.: 5



As a web developer, I am constantly creating and/or editing php-based web sites on my Mac. I have my own web space to upload these files to and test my work, but the extra step of FTP'ing a file to my web server each time I wanted to see my edits was a large annoyance for me. I wanted to streamline my process and increase productivity.

I knew it was time to take advantage of the built in web server in OS X, using Apache and the PHP module that comes preinstalled. Since I keep all web sites in the default “Sites” directory, I wanted to use it as the directory which Apache served files from. Here is what I did, and how you should do it…

By default OS X ships with Apache and PHP, but PHP is disabled. In order to enable it you must do the following:
  1. Open up Terminal.app, and type the following: sudo vi /etc/httpd/httpd.conf
  2. You'll be asked for your root password, so type it in and you'll be brought into the httpd.conf file
  3. You have to uncomment two lines of code by removing the hash symbol in front of them. To quickly jump to these lines of code without having to scroll through the file, type each of the following commands, with the leading forward slash, and press enter: /LoadModule php4_module and /AddModule mod_php4.c
  4. To remove the hash symbols type i to go into Insert mode, and using your arrow keys, you can delete the hash symbols
  5. Once you're done deleting the hash symbols, press the escape key to leave Insert mode
Next, you'll want to tell Apache to serve files from your directory of choice. By default, it will serve only files placed into /Library/WebServer/Documents/, but I have always kept my sites in /Users/Marc/Sites/, and didn't really want to change where I keep them. Below I'll show you how to change the default directory to one of your choosing by using my personal choice as the example:
  1. If you're not inside httpd.conf, follow steps 1 & 2 above.
  2. To jump to the line of code we need to change, type the following command and press enter: /DocumentRoot
  3. Press i to go back into Insert mode, and using your arrow keys, position the cursor so you can delete the default path (usually /Library/WebServer/Documents/) and type in the new path to your desired directory. (Mine is /Users/Marc/Sites/ but replace “Marc” with your own username)
Finally, once that is done you need to save the file, close it, and restart Apache.
  1. To save & close the file, type in the following command and press enter: :wq. This will save & close the file in one action
  2. After completing the above step, the httpd.conf file is closed, but you are still inside Terminal.app. From here, it is easy to restart Apache by typing the following command: sudo apachectl graceful
That is it! If you followed the steps above, you should now have Apache running with the PHP module enabled, and any files you keep inside /Users/yourname/Sites/ will be visible in your web browser simply by typing http://localhost/.


--------------------
Go to the top of the page
 
+Quote Post
ShakingSpirit
post Nov 3 2006, 09:23 PM
Post #2


Pedantic Whinger
Group Icon

Group: Members
Posts: 237
Joined: 1-August 06
From: Southampton, UK
Member No.: 23



Nice little guide herkalees happy.gif Though I'd recommend pico if you're reading this, and are ready to smash your keyboard over vi laugh.gif


--------------------
QUOTE(MSN)
Benbramz says: i had orgasmic thoughts at the excitement of that
Go to the top of the page
 
+Quote Post
Marc Amos
post Nov 4 2006, 10:28 AM
Post #3


W.R. General
Group Icon

Group: Administrators
Posts: 2,799
Joined: 4-April 06
From: Massachusetts - USA
Member No.: 5



It's funny, I was going to use pico, but as a much-smarter-than-me friend was walking me through the keyboard commands, he mentioned that VI is much better. I'm certain it is simply a matter of preference laugh.gif


--------------------
Go to the top of the page
 
+Quote Post
benbramz
post Nov 26 2006, 08:33 PM
Post #4


The buddy system:never fails
Group Icon

Group: Administrators
Posts: 1,766
Joined: 4-April 06
Member No.: 1



Great clear article by Marc, im going to carry on with the flow of things and show how to install MySql.
I advise following the steps in the above post first.

Firstly we need to grab the files. Make sure you get the latest version, its not essential but advised.

Once you have the files downloaded, run them.

now, here you need to make a descion.. do you want mysql to start each time you start the computer? (i reccomend this). If so, install the PKG file named MYSQLstartupitem.pkgb

Have you run the package files? good. lets move on.

If you have installed the Startup Item, use this command:

(PRESS CONTROL-D OR ENTER "EXIT" TO EXIT THE SHELL)

If you don't use the Startup Item, enter the following command sequence:

CODE
cd /usr/local/mysql

CODE
sudo ./bin/mysqld_safe

(ENTER YOUR PASSWORD, IF NECESSARY)
(PRESS CONTROL-Z)
shell> bg
(PRESS CONTROL-D OR ENTER "EXIT" TO EXIT THE SHELL)

You should be able to connect to the MySQL server, for example, by
running `/usr/local/mysql/bin/mysql'.

You should be up and running ;-) this was just a brief article to cut the fat from the chunk of the readme file, not in anyway the most complex article. but hey, they're macs, they practically run themselves!


--------------------
QUOTE (Sirkent @ Sep 21 2007, 09:26 AM) *
<monty python high-pitched female voice>I DON'T LIKE SPAM!</monty python high-pitched female voice>
Go to the top of the page
 
+Quote Post
TJSingleton
post Nov 27 2006, 08:32 AM
Post #5


Allegedly Legendary
Group Icon

Group: Members
Posts: 512
Joined: 31-July 06
From: Winder, GA
Member No.: 11



So it ships with php4?

Pico is a lot easier to use than vi, but I've never spent much time with either.


--------------------
Go to the top of the page
 
+Quote Post
Marc Amos
post Nov 27 2006, 08:47 AM
Post #6


W.R. General
Group Icon

Group: Administrators
Posts: 2,799
Joined: 4-April 06
From: Massachusetts - USA
Member No.: 5



QUOTE(TJSingleton @ Nov 27 2006, 08:32 AM) *
So it ships with php4?

Yes, though it's disabled by default.


--------------------
Go to the top of the page
 
+Quote Post
temhawk
post Oct 10 2007, 01:49 PM
Post #7


W.R. Private First-Class
Group Icon

Group: Members
Posts: 253
Joined: 30-August 07
From: Vienna, Austria
Member No.: 586



I a having an odd problem: I type "sudo vi /etc/httpd/httpd.conf" into Terminal (step one from the original post) and it then asks for root password; though I can't type anything into the window?!


--------------------
Go to the top of the page
 
+Quote Post
Marc Amos
post Oct 10 2007, 02:23 PM
Post #8


W.R. General
Group Icon

Group: Administrators
Posts: 2,799
Joined: 4-April 06
From: Massachusetts - USA
Member No.: 5



QUOTE(temhawk @ Oct 10 2007, 02:49 PM) *
I a having an odd problem: I type "sudo vi /etc/httpd/httpd.conf" into Terminal (step one from the original post) and it then asks for root password; though I can't type anything into the window?!

While you type the password, it WON'T appear as though you are typing (on purpose). Just type the password and hit enter... should work.


--------------------
Go to the top of the page
 
+Quote Post
temhawk
post Oct 10 2007, 02:50 PM
Post #9


W.R. Private First-Class
Group Icon

Group: Members
Posts: 253
Joined: 30-August 07
From: Vienna, Austria
Member No.: 586



Oops, didn't know that whistling1.gif

I am almost there! Just when I press cmd+s this window appears...
How do I give the "wq" command? This is the first time for me using Terminal rolleyes.gif I hope you forgive me! Thanks! biggrin.gif

PS: http://www.freewebs.com/elalcon/ImageHost/...ing%20httpd.png

This post has been edited by temhawk: Oct 10 2007, 02:51 PM


--------------------
Go to the top of the page
 
+Quote Post
Sirkent
post Oct 11 2007, 04:52 AM
Post #10


Loose bits sink chips
Group Icon

Group: Administrators
Posts: 2,068
Joined: 4-April 06
From: Kent, UK
Member No.: 2



I've split Billy's post into a new topic: Mac OS X, Apache and JBOS

Temhawk: To give any command in vi, press escape, then type : and then the command.
So:
escape -> : -> wq -> enter
Will save and quit.

And the link to an image you've posted is the ability to save a terminal shortcut, not to save the file you're editing in vi!


--------------------
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) *
Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
Go to the top of the page
 
+Quote Post
temhawk
post Oct 11 2007, 05:49 AM
Post #11


W.R. Private First-Class
Group Icon

Group: Members
Posts: 253
Joined: 30-August 07
From: Vienna, Austria
Member No.: 586



Thank you! jump.gif

But I think I might have done something wrong.
Yesterday, I closed the Terminal window after I typed "sudo vi /etc/httpd/httpd.conf", entered my password and made the few changes. But I didn't save it since I didn't know how to write the "wq" command. So the popup came up and asked me if I wanted to Terminate "login bash" etc. whatever, I can't remember. I thought Terminate means it will be closed without saving the changes.

Today, when I found out how to do everything properly, something different happened when I wrote "sudo vi /etc/httpd/httpd.conf" and hit enter; This text came up.
I tried some random stuff, hit F13 and suddenly I got what I had yesterday again (unchanged). I did the couple changes, and then typed ":wq". This appeared. (not "disappeared" rolleyes.gif get it?)

So I am wondering whether everything is still 'ok' here, or if I have done something improperly. By the way, I always get this message now when I type "sudo vi /etc/httpd/httpd.conf", the one in the first link of this post. Do I just have to delete the httpd.conf.swp file, that message is talking about? I just want to get reassurance in case I fug up my mac more and more; I don't really know how much terror Terminal is capable of, but I imagine it can mess things up a lot, and since I've never used Terminal before...

Thanks ahead!

This post has been edited by temhawk: Oct 11 2007, 06:45 AM


--------------------
Go to the top of the page
 
+Quote Post
Sirkent
post Oct 12 2007, 04:23 AM
Post #12


Loose bits sink chips
Group Icon

Group: Administrators
Posts: 2,068
Joined: 4-April 06
From: Kent, UK
Member No.: 2



Yes, you can delete the .swp file. It's a temporary file used by vi to prevent more than 1 person modifying a file at once and to allow you to recover any changes you make if, for whatever reason, your editing is interrupted.

I think there's also a command to do that for you... when you get that message up you can press the space bar to read more and it may well tell you there how to do that.

The reason this problem arose is because you didn't close vi properly (by using :wq or :q, or if you've made changes and don't want to save them :q!).


--------------------
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) *
Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
Go to the top of the page
 
+Quote Post
temhawk
post Oct 12 2007, 05:39 AM
Post #13


W.R. Private First-Class
Group Icon

Group: Members
Posts: 253
Joined: 30-August 07
From: Vienna, Austria
Member No.: 586



Thank you, what you said worked! smile.gif

- - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I just tried to load "http://localhost/test.php" but Safari said it couldn't locate the remote server.
I checked "sudo vi /etc/httpd/httpd.conf" in Terminal, and it was set properly.
So I figured maybe I have to restart apache, so I typed "sudo apachectl graceful" and then tried opening the page again, and it worked.

How come? "http://localhost/" worked (mac os x's index.html page) but what was going on?
Also, when I clicked "Preview" in Taco HTML Edit (also for PHP) it opened in FF and worked (though it was a temporary file created by Taco; in the Taco preferences, I specified the path for the PHP (/Users/Hawk/Sites/) so it would work)

That's weird, isn't it?

This post has been edited by temhawk: Oct 12 2007, 05:57 AM


--------------------
Go to the top of the page
 
+Quote Post
Sirkent
post Oct 12 2007, 06:07 AM
Post #14


Loose bits sink chips
Group Icon

Group: Administrators
Posts: 2,068
Joined: 4-April 06
From: Kent, UK
Member No.: 2



I'm not sure what you're asking?

localhost/ works, but localhost/test.php doesn't?


--------------------
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) *
Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
Go to the top of the page
 
+Quote Post
temhawk
post Oct 12 2007, 06:13 AM
Post #15


W.R. Private First-Class
Group Icon

Group: Members
Posts: 253
Joined: 30-August 07
From: Vienna, Austria
Member No.: 586



That's what I mean!

And I've just encountered another problem.

This post has been edited by temhawk: Oct 12 2007, 06:15 AM


--------------------
Go to the top of the page
 
+Quote Post
temhawk
post Jul 10 2008, 02:59 PM
Post #16


W.R. Private First-Class
Group Icon

Group: Members
Posts: 253
Joined: 30-August 07
From: Vienna, Austria
Member No.: 586



Alright Marc, now I need to reverse all these steps. I want to/am using MAMP and when I tell it to stop apache, I can still go to http://localhost/ and run PHP files. And there was also this website that showed me how to make apache automatically start on login or system boot (so I don't have to type "sudo apachectl graceful" every time) and I think I should probably reverse that configuration as well. Essentially I want to reset my Mac's apache and PHP settings to their original state, because that's what MAMP assumes to work properly.

Problem is I am afraid of playing with Terminal on my own, and I would be happy if someone could find that link/site that I used to make a small edit in some configuration file to auto-start apache. I remember that site was very blue!

Edit: I found the link: http://b.lesseverything.com/2007/8/17/apac...re-s-how-to-fix (the site isn't as blue as it was back then wink.gif )

This post has been edited by temhawk: Jul 10 2008, 03:16 PM


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
Tags
No Tag inserted yet

1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

RSS Lo-Fi Version Time is now: 8th January 2009 - 07:10 AM
Contact Us
Web Design Forum | Web Development Forum | Web Help | WordPress Help