Enable PHP on a Mac

Discussion in 'Mac OS X Server, Xserve, and Networking' started by patmalt, Mar 15, 2011.

  1. macrumors newbie

    Joined:
    Jan 24, 2010
    #1
    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.
     
  2. macrumors G5

    Consultant

    Joined:
    Jun 27, 2007
    #2
    Probably need to use sudo texteditor to open the file.

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

    dmmcintyre3

    Joined:
    Mar 4, 2007
    #3
    Run in terminal:
    sudo nano /private/etc/apache2/httpd.conf
    to edit the httpd.conf
     
  4. thread starter macrumors newbie

    Joined:
    Jan 24, 2010
    #4
    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:
     
  5. macrumors 6502

    blaster_boy

    Joined:
    Jan 31, 2004
    Location:
    Belgium
    #5
    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 ?

    Code:
    <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.
     
  6. macrumors newbie

    Joined:
    Oct 29, 2010
    #6
    Help please (anyone who can help me get php working!)

    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.
     
  7. macrumors 6502

    Joined:
    Jul 23, 2002
  8. macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    #8
    The file you need to edit is located at
    Code:
    /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:
    Code:
    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.
     
  9. macrumors 6502

    JavaTheHut

    Joined:
    Aug 15, 2010
    #9
    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!
     
  10. macrumors 6502

    JavaTheHut

    Joined:
    Aug 15, 2010
    #10
    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)
    Code:
    # 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
    Code:
    <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
    Code:
    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!
     
  11. macrumors newbie

    Joined:
    Nov 5, 2004
    #11
    Enabling PHP

    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.
     

Share This Page