PDA

View Full Version : Enable PHP on a Mac




patmalt
Mar 15, 2011, 12:51 PM
I googled how to enable PHP for snow leopard, but I cannot figure this out. I am trying to uncomment the php line of /private/etc/apache2/httpd.conf, but I get an 'MacOS Error -5000' when trying to save the file in TextWrangler. I looked up the error code and it said that I do not have permission to edit the file. However, I am the only user account on this Mac and I am an admin. How do I save this file? Thanks.



Consultant
Mar 15, 2011, 02:38 PM
Probably need to use sudo texteditor to open the file.

For web testing only, you are better off with MAMP.

dmmcintyre3
Mar 15, 2011, 04:00 PM
Run in terminal:
sudo nano /private/etc/apache2/httpd.conf
to edit the httpd.conf

patmalt
Mar 15, 2011, 05:44 PM
I uncommented the PHP line in httpd.conf file in Terminal, but when i go to http://localhost/xyz.php in my browser, it is still just printing my PHP code.

I turned web sharing on/off and restared my computer but PHP still does not work!!!:mad:

blaster_boy
Mar 16, 2011, 02:42 PM
Just enabling the php5 library to load in Apache is not enough. You also need to tell Apache what to do with any .php file that is served to the user.

Check your apache config file to see if this code is in there - perhaps it is commented out ?

<IfModule mod_php5.c>

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>

</IfModule>

It lets Apache know what to do with any php file.

jbutler404
Aug 4, 2011, 01:24 PM
Just enabling the php5 library to load in Apache is not enough. You also need to tell Apache what to do with any .php file that is served to the user.

Check your apache config file to see if this code is in there - perhaps it is commented out ?

<IfModule mod_php5.c>

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>

</IfModule>

It lets Apache know what to do with any php file.

I am a newbie to php, my OS is 10.6.8. I have done all the steps put up by everyone on the web but have the same problem as others in that the code is just printed instead of being parsed. I've tried your code (the line isn't in my file so I typed it in) but to no avail but this is probably because I don't understand it and need to. Can anyone help me to get my php loaded and working please? Thanks.

ryanide
Aug 5, 2011, 09:17 AM
http://www.mupromo.com/deal/1592/7024/mamp-pro

Darth.Titan
Aug 5, 2011, 11:30 AM
The file you need to edit is located at
/etc/apache2/httpd.conf

While there is an httpd.conf in the /private directory, I've never messed with that one.

Just uncomment the line:
LoadModule php5_module libexec/apache2/libphp5.so
and restart Web Sharing, and that's all there is to it. The <IfModule> block that blaster_boy referred to is already present.

JavaTheHut
Aug 5, 2011, 07:47 PM
http://www.mupromo.com/deal/1592/7024/mamp-pro

You can grab this deal but its limited time $25 if you run out of time you will need to pay more $50. You can also get the free version which works well and gives you a good start at managing Apache/mySQL/php at a nice price!

JavaTheHut
Aug 5, 2011, 08:35 PM
I am a newbie to php, my OS is 10.6.8. I have done all the steps put up by everyone on the web but have the same problem as others in that the code is just printed instead of being parsed. I've tried your code (the line isn't in my file so I typed it in) but to no avail but this is probably because I don't understand it and need to. Can anyone help me to get my php loaded and working please? Thanks.

Just my laymen observation but the code that was supplied by blaster_boy looks like its from a http://www.entropy.ch/software/macosx/php/ install this would have been downloaded and installed other than the original OSX php config?

The complete code looks like this (it may differ on others installs):
/usr/local/php5/entropy-php.conf (this is an alias in /private/etc/apache2/other/+entropy-php.conf)

# Additional PHP Apache directives,
# part of the entropy.ch PHP package for Mac OS X
#
# For more information, go to http://www.entropy.ch/software/macosx/php/
#

LoadModule php5_module /usr/local/php5/libphp5.so

<IfModule mod_php5.c>

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<IfModule mod_dir.c>
DirectoryIndex index.html index.php
</IfModule>

</IfModule>

The standard php config file in OSX is:
/private/etc/apache2/other/php5.conf
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>


The file & line you need to uncomment is
/private/etc/apache2/httpd.conf
LoadModule php5_module libexec/apache2/libphp5.so

You need to use something like textwrangler(free) to save over the files with admin privileges or unlock the files using info in finder unlock them make them writable to user and lock them when your done your edits. I realize an adapt IT could do this all in terminal commands, and I certainly respect that fact but I went the visual route and it worked.
Hope this helps -- we've all been there -- enjoy!

asmiller
Aug 6, 2011, 04:04 PM
You also need to make sure permissions are correct. There is plenty of information out there about how to do this correctly. Typically they are set to 644 or 755 and you have to make sure the enclosing directory has correct permissions.