Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP on Mac OS X Leopard not recognizing php code 2

Status
Not open for further replies.

jclark6

MIS
Sep 12, 2008
3
US
I've got Apache and MySQL running on my MacBook Pro laptop, and I want to run PHP as well. I have them all installed. When I try to execute the php file, all I get is a display of the php code. I know the PHP code itself works, because I can run it on my isp's servers, so I'm assuming my something in my PHP setup is incorrect. I'm not sure how to debug this, can someone please give me a hand?
Thanks in advance!
 
It looks like mamp installs everything, I've already got MySQL, Apache, & PHP installed. Do I need to uninstall everything, and if so how do I do it? The mamp site also recommends OS X Server, which I'm not running. Does this work with OS X Leopard?
 
you do not need OSX server. no. yes. MAMP installs everything you need and does so in userspace. you do not need to uninstall anything, MAMP uses alternative ports. if you want to save memory/battery then just turn off web sharing in system preferences.

alternatively, as I said, if you want to use the versions that come with leopard then add a php handler to httpd.conf (or in fact enable the library since leopard uses an apache handler) (it's here for leopard; /etc/apache2/httpd.conf). remember that you will need to edit it with sudo privileges (open terminal and type sudo pico /etc/apache2/httpd.conf).

you will need to uncomment this line

Code:
[red][s]#[/s][/red]LoadModule php5_module        libexec/apache2/libphp5.so

then restart the web server (system preferences, uncheck the web sharing box, wait half a minute and then check it again. all should then be well.

you may get permission issues if trying to manipulate files in userspace. i do (and use sqlite so this is a real drag), hence why I use MAMP. there are ways round this in the native install, but frankly MAMP is so much easier.
 
jpadie,
What do you mean by "userspace"? If I don't uninstall these things, won't I have a lot of unneeded files laying around? In my version of Leopard, the httpd.conf file is located in the /private/etc/apache2 directory. Is that a problem? Also, I found no php5_module entry in the httpd.conf file, so I'm assuming my installation is incomplete or corrupted. At this point, I'll probably take your advice and try mamp.
 
did you install apache yourself? or are you using the plain version that comes with leopard?

i have apache configs in both /private/etc and /etc. i'm not sure why. Quite possible that one is a master and one a user specific version?

yes - you will have unnecessary files lying around but that's no big deal. these files are only 200k in total and i'm assuming that there is only one set of compiled binaries knocking around. i've not checked.

if your installation does not have that line in it, then add it to the bottom of the loadmodule declarations. check first that the libphp5.so is in your installation. It should be in /usr/libexec/apache2.
 
I'm a bit curious here, jpadie. Since OSX is based on Unix, do you have to chmod a PHP script before you can execute it like you have to perl scripts on Linux? It's been so long since I've done PHP on Linux that I can't remember if I had to do that to my scripts there or not. I'm thinking not, but that may be because I called the interpreter explicitly and didn't rely on a #! line.
 
nope (at least not traditionally), because you don't execute a php script per se. you execute the CGI/CLI whatever and pass the script as an argument (so to speak). so the cgi/cli needs to have execute permissions but the scripts do not.

Code:
php -f filename.php

and you don't actually need to pass a filename at all

Code:
php -r  'echo "hello world";'

will work fine.

however you _can_ execute a php file directly by including a sha-bang at the start of the script and setting the execute bit.

Code:
#!/usr/bin/php
<?php
echo "hello world\r\n";
?>

works just fine too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top