# php won't display in furefox



## michaelf1 (Sep 7, 2006)

hello,

i've recently started learning php4 with mysql and have also migrated from windows to mac os x (10.3). the problem i'm having is getting php to work in my browser, at the moment all php is either not displayed at all or everything between the php tags just displays on the screen as plain text.

eg.
<?php
echo "hello world";
?>

this script saved with .php extension just displays - 

<?php
echo "hello";
?>

and

<?php
echo "hello world";
?>

saved as html displays nothing at all.

the problem isn't just limited to my default browser (firefox) as the same thing happens in safari.

i'm sure it must be something reallt straight forward that i'm missing. any help much appreciated.

regards,

Mike.


----------



## lurk (Sep 7, 2006)

Um, PHP is handled on the server and not the browser.  So you need to look into why your server is not properly processing the file.  By the time it gets to the browser it is just boring normal html.


----------



## macworks (Sep 7, 2006)

You'll need to edit the config file for Apache to tell Apache to run PHP files through the PHP engine.

To do this: open up /etc/httpd/httpd.conf and take the # off the front of the following two lines:

LoadModule php4_module        libexec/httpd/libphp4.so

AddModule mod_php4.c

Then save the file. You'll have to either restart Apache or the entire computer to make the change effective.


----------



## macworks (Sep 7, 2006)

And BTW: Congrats on switching to the Mac platform! Mac OS X is a web developer's dream come true with Apache, PHP and MySQL installed. I've been developing sites for 10 years and I'm still absolutely thrilled about what Mac OS X does for me as a web developer!


----------



## michaelf1 (Sep 8, 2006)

christopher,

thanks so much for your help and yes, you're right, moving to Mac was definately a good idea.

unfortunately i'm having further trouble, whenever i select "personal web sharing" in system preferences it won't stay selected when i shift the emphasis to another window. this means i can't access my home directory.

any ideas?

thanks in advance,

mike.


----------



## macworks (Sep 8, 2006)

Mike: Ideally, you wouldn't use your "sites" folder in your home folder as your development environment. Instead, place your site files in Hard Drive > Library > WebServer > Documents then simply point your browser to "localhost".

That being said, you might have a problem with the Apache config file -- that's why Apache (web sharing) won't start up. If you're familiar/confortable with the Terminal, open it up and type "apachectl configtest". Apache will look at your config file and see if it finds any errors.

If you're not comfortable with the terminal, you should start getting to know it because there's a lot available to a web developer "under-the-hood". I recommend the following book: Learning Unix for Mac OS X Tiger by Dave Taylor. You won't likely need to learn everything in the book, but the first few chapters will teach you a lot.


----------



## michaelf1 (Sep 8, 2006)

i tried running "apachectl configtest" in the terminal and it says "syntax ok". i also tried putting localhost in the address bar but i just get can't establish connection. i tried this in firefox and safari and got the same result so pretty sure it's not the browser.

do you think it might be worth me reinstalling apache? i presume it's quite a long winded process. can't think what else will cure it.

it's starting to worry me a bit now and i'm getting way behind schedule...

i'll look into getting that book, my terminal skills are quite limited but i think you're right i do seem to be required to do quite alot of command line tasks.

thanks again,

mike.


----------



## macworks (Sep 8, 2006)

If you open the terminal and type "sudo pico /etc/hostconfig" (you'll have to enter your admin password), look for a line that says "WEBSERVER=-YES-
". If it doesn't say "YES" change it to say "YES". This will tell the computer to launch Apache everytime it starts up.

Once you've made your edit, hold CTRL and press X to exit the pico edit, it will prompt you to ask if you want to save changes, type "y" and press enter.

To get Apache started from the command line, type "apachectl start". To get a complete list of options for apachectl simply type "apachectl" and press return.

To see if apache is already running, type "ps -aux | grep httpd" and press return. You should get something like this:

root       351   0.0  0.0    56968    176  ??  Ss   Wed08PM   0:01.33 /usr/sbin/httpd
www        353   0.0  0.0    47324    884  ??  S    Wed08PM   0:00.02 /usr/sbin/httpd
www       1628   0.0  0.0    47324    492  ??  S     4:06PM   0:00.00 /usr/sbin/httpd
chrisr    1640   0.0  0.0    27712    276  p1  R+    4:08PM   0:00.00 grep httpd

Also go to /Library/WebServer/Documents on your computer (you can go there in the finder) and make sure there's an index.html document there. Edit the index.html doc to output something simple then point your browser to "localhost" again.

I'm available in iChat if you want to contact me. Visit my web site http://www.macworks.biz/ to find the link to my iChat.


----------



## michaelf1 (Sep 9, 2006)

i looked for that line of syntax in hostconfig and it already exists, so presumably apache is trying to start when my comp does.

I also tried "ps -aux | grep httpd" and got this:

Michael-Fowdreys-Computer:~ michaelfowdrey$ apachectl start
fopen: Permission denied
httpd: could not open error log file /var/log/httpd/error_log.
/usr/sbin/apachectl start: httpd could not be started
Michael-Fowdreys-Computer:~ michaelfowdrey$

also added an index file but it still won't display anything when i type localhost.

i'll try to contact you via ichat.

thanks for your help.

mike.


----------



## lurk (Sep 9, 2006)

Are you using the apache that comes as part of the base OS or did you install your own.  It looks like you have an odd permission problem.  Apache should start up as root and should not have any problem opening /var/log/http/error_log

Is there anything in the system log?


----------



## michaelf1 (Sep 10, 2006)

The error log's blank.

I'm wasting loads of time now, do you think it might best if I just did a clean install? If so is there a way I can do this without having to reinstall all of my files and appz? I have backups of the essential stuff.

Mike.


----------



## macworks (Sep 10, 2006)

Mike, if you're on iChat now, I'm available.


----------

