PHP setup on MAC OSX 10.5.8

Discussion in 'Web Design and Development' started by lawsonium, May 29, 2010.

  1. lawsonium macrumors newbie

    Joined:
    May 29, 2010
    #1
    Hello,

    I am somewhat of a mac noob but am learning.

    I am running OSX 10.5.8 on a G5

    I am trying to get PHP to run through the standard mac/apache web server.
    I can bring up the default index.html page from http://localhost/~myusername/
    but when I try to run a .php file from this location I get:

    Safari can’t open the page “http://localhost/~myusername” because Safari can’t connect to the server “localhost”.


    I have followed some instructions online (http://www.devarticles.com/c/a/Apache/Using-Apache-and-PHP-on-Mac-OS-X/) and have so far managed the following:


    In this location: /private/etc/Apache2/users
    I have two files httpd.conf and myusername.conf

    the latter of which contains the following:
    <Directory "/Users/myusername/Sites/">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    </Directory>


    I edited the file: httpd.conf

    Un-commented these lines

    LoadModule php4_module libexec/httpd/libphp4.so
    AddModule mod_php4.c


    These lines were already un-commented

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




    As per instructions online (http://foundationphp.com/tutorials/php_leopard.php), in this location: /private/etc I copied 'php.ini.default' to 'php.ini'

    then I edited the php.ini file and changed: error_reporting = E_ALL & ~E_NOTICE to this: error_reporting = E_ALL


    I think I've recalled everything I have done here. Obviously I have restarted the Web Service however, on all the examples I have seen this service is called 'Personal Web Sharing' and in my service list I only have 'Web Sharing'. Don't know if that makes any difference.


    I'd really like to get this working as I am trying to develop a couple of sites and am fed up of ftp'ing every change to the server just to test it.

    If anyone can help me sort this I would appreciate it very much.

    Kindest Regards,

    Matt.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Looks like you hit the main things. Some of the tutorials are for different versions of OSX, so some settings names will be different for you. I have OSX 10.6 and mine list PHP5 rather than PHP4 in the httpd.conf file. Seems like a weird error you're getting. Sounds like the web server isn't fully starting. Might want to give your machine a reboot to see if that helps.

    If you can't get the built-in server going, I recommend trying out MAMP, which sets up very easy. It also gives you MySQL if you ever end up needing it.
     
  3. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #3
    Thanks for your reply. I have some extra info if it helps clarify anything:

    Some extra info:

    I tried to tail the error_log by typing this into the terminal: 'tail /var/log/httpd/error_log'
    It didn't work because the system said the file didn't exist. I tried to find the folder but that didn't exist in this route.

    I did however find an error_log file in: /private/var/log/Apache2/

    I interrogated this and found some entries like this:
    [Sat May 29 18:39:44 2010] [error] [client ::1] File does not exist: /Library/WebServer/Documents/favicon.ico, referer: http://localhost/~mattmoo/phpinfo.php
    [Sat May 29 18:39:44 2010] [error] [client ::1] File does not exist: /Library/WebServer/Documents/favicon.ico, referer: http://localhost/~mattmoo/phpinfo.php
    [Sat May 29 18:39:44 2010] [error] [client ::1] File does not exist: /Library/WebServer/Documents/favicon.ico, referer: http://localhost/~mattmoo/phpinfo.php
    [Sat May 29 18:43:14 2010] [notice] caught SIGTERM, shutting down


    This is strange because I have been trying to run 'phpinfo.php' all evening and this shows that it made it as far as the error_log several hours ago but after some of the changes I have made to my configuration it has stopped logging it here.
    I'm wondering if it is either; not logging errors at all now or; logging them somewhere else?

    I have also found a httpd.conf file in: /private/etc/Apache2/

    I have found in this file the lines:

    LoadModule php5_module libexec/apache2/libphp5.so
    LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so

    which I have un-commented.

    I will try rebooting the mac and post back.



    I am so confused by this. Please help if you can.

    Regards,

    Matt.
     
  4. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #4
    rebooted but no joy :-(

    This should be such a simple thing to do.
     
  5. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #5
    Well something's not right. If you've got Leopard you should have PHP 5 installed, not 4. At any rate, I just enabled PHP on my MBP using the following method:

    Make sure Web Sharing is checked in your Sharing Preference Pane, then in Terminal
    Code:
    sudo vi /etc/apache2/httpd.conf
    Uncomment the following line
    Code:
    LoadModule php5_module        libexec/apache2/libphp5.so
    Also
    Code:
    sudo cp /etc/php.ini.default php.ini
    (I made no changes to php.ini to get it running, but I may make changes later)

    Then run
    Code:
    sudo apachectl restart
    I've seen the same how-tos you have, and I know you were following directions, but there seem to be too many steps to those methods. What I did worked flawlessly.
     

    Attached Files:

  6. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #6
    Hi there,

    Thanks for your reply, I will follow your steps and check my files. I'll report back.

    Re: PHP 4/5.
    The mac I am working on belonged to my friend and I think it has been upgraded to it's current OS version, so there might be PHP4 remnants. As I mentioned in my last but one post I have found this conf file: /private/etc/Apache2/httpd.conf

    In it I have found the lines reffering to PHP5:

    LoadModule php5_module libexec/apache2/libphp5.so
    LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so


    I have un commented these lines already.

    However, as I said, I'll check through the steps you have listed and report back.

    Thanks,

    Matt.
     
  7. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #7
    Hi guys,

    I just went through the steps listed by Darth.Titan and made sure my setup matches (which it does). Still no joy :-(

    Still no change to my error_log either.


    I know I can install MAMP but I'd like to get the supposedly 'simple' built in Apache working. It's very frustrating.

    Is there anything else I could post here which might help you work out what is wrong?

    Kind Regards,

    Matt.
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    There could be a typo in the httpd.conf file. It can be very finicky where a single stray space can cause problems.

    When you tried the restart command given by Darth.Titan, did it give any messages? That would be a place where it would mention any issues with the httpd.conf file.

    Is it still the case where you can open .html files fine, just not .php ones? Have you tried another browser than Safari? Maybe there is a cache issue.
     
  9. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #9
    Hi. Same behavior from Firefox too.

    This is what happens from a browser...

    file:///Users/mattmoo/Sites/phpinfo.php
    entering this in the address line just brings up the PHP code, it doesn't render it, just treats it like a text file.


    file:///Users/mattmoo/Sites/index.html
    entering this in the address line and the html page is displayed correctly.


    Now the really odd behavior...

    http://localhost/~mattmoo/
    If I enter this into the address line in a browser the 'index.html' page is rendered correctly.


    http://localhost/~mattmoo/index.html
    If I specify it like this then I get a 'Safari can’t connect to the server' error.


    http://localhost/~mattmoo/phpinfo.php
    Same error message with a php file.


    There shouldn't be any typo's as I haven't been fiddling with the conf files. Only un-commenting the relevant php lines.

    This is the line where I restarted Apache from Terminal:
    JJH-G5-2:~ mattmoo$ sudo apachectl restart

    No messages at all.


    So frustrated. I have exhausted my MAC/Apache knowledge.

    Thanks again for trying to help, hopefully we'll get to the bottom of it.

    Matt.
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    It seems I forgot you need to use the -t argument on the apachectl command to get messages as this thread reminded me.
    Code:
    sudo apachectl -t
    Also check out post 15 on this thread that deals with manually creating a folder as root (sudo mkdir /private/var/log/apache2).
     
  11. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #11
    Hi,

    Ok, I just ran the command you suggested and now get this report:

    JJH-G5-2:Apache2 mattmoo$ sudo apachectl -t
    Password:
    httpd: Syntax error on line 455 of /private/etc/apache2/httpd.conf: Syntax error on line 15 of /private/etc/apache2/extra/httpd-userdir.conf: Syntax error on line 207 of /private/etc/apache2/users/httpd.conf: Cannot load /usr/libexec/httpd/mod_log_config.so into server: dlopen(/usr/libexec/httpd/mod_log_config.so, 10): image not found


    Does this mean anything to you?

    Thank you.

    Matt.
     
  12. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #12
    Fix the syntax errors and comment out the line loading mod_log_config and you should be good to go.
     
  13. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #13
    How do I know what the syntax errors are?

    These are the relevant lines in each file that has thrown an error.


    Syntax error on line 455 of /private/etc/apache2/httpd.conf:
    line 454 & 455 is:
    # User home directories
    Include /private/etc/apache2/extra/httpd-userdir.conf


    Syntax error on line 15 of /private/etc/apache2/extra/httpd-userdir.conf:
    line 15 is:
    Include /private/etc/apache2/users/*.conf


    Syntax error on line 207 of /private/etc/apache2/users/httpd.conf:
    line 207 is:
    LoadModule config_log_module libexec/httpd/mod_log_config.so


    I haven't changed any of these.

    Thanks.

    Matt
     
  14. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #14
    You obviously have a syntax error in the files that those lines include. And just comment out line 207.
     
  15. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #15
    Ok, but as you can see, the lines the errors are referring to don't look syntactically incorrect. What about them needs correcting?

    Also, I don't like to just blindly comment something out, just because it's throwing an error. What exactly is 'mod_log_config.so' and why is it currently not commented out? Why is it not loading? Is it needed?

    Kind Regards,

    Matt.
     
  16. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #16
    On that module that won't load, I notice in my httpd.conf file it's named differently,
    Code:
    LoadModule log_config_module libexec/apache2/mod_log_config.so
    For the syntax error messages, do the files it mentions exists? I don't think they do for older versions of OSX, so if you've upgraded, they may not have gotten created during the upgrade.

    There could also be an issue of the permissions of the files. You need to make sure they are owned by the system rather than yourself. This generally means opening the files with the sudo prefix. This thread discussed a similar problem to yours.
     
  17. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #17
    They do exist:

    JJH-G5-2:Apache2 mattmoo$ cd /private/etc/apache2/extra
    JJH-G5-2:extra mattmoo$ ls
    httpd-autoindex.conf httpd-info.conf
    httpd-mpm.conf httpd-userdir.conf
    httpd-dav.conf httpd-languages.conf
    httpd-multilang-errordoc.conf httpd-vhosts.conf
    httpd-default.conf httpd-manual.conf
    httpd-ssl.conf


    JJH-G5-2:users mattmoo$ cd /private/etc/apache2/users/
    JJH-G5-2:users mattmoo$ ls
    httpd.conf mattmoo.conf


    As for the spelling, I'll try and change it.

    Thanks again,

    Matt.
     
  18. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #18
    Oddly, the areas from either your version or my version of that line exist on this system.

    libexec/httpd/mod_log_config.so
    libexec/apache2/mod_log_config.so

    How do I search the system for the file: mod_log_config.so?

    I now get this:

    JJH-G5-2:users mattmoo$ sudo apachectl -t
    [Mon May 31 23:15:08 2010] [warn] module log_config_module is already loaded, skipping
    [Mon May 31 23:15:08 2010] [warn] module mime_module is already loaded, skipping
    [Mon May 31 23:15:08 2010] [warn] module negotiation_module is already loaded, skipping
    httpd: Syntax error on line 455 of /private/etc/apache2/httpd.conf:
    Syntax error on line 15 of /private/etc/apache2/extra/httpd-userdir.conf:
    Syntax error on line 213 of /private/etc/apache2/users/httpd.conf: Cannot load /usr/libexec/httpd/mod_include.so into server: dlopen(/usr/libexec/httpd/mod_include.so, 10): image not found

    The error seems to have moved from line 207 to 213 after changing the line to match yours (even though I couldn't CD to the location from your line???


    Kind Regards,

    Matt.
     
  19. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #19
    Ok, I have done some more digging around on the net and feeling my way with the OSX/Apache system and I think I have found a possible cause of the problem.

    A lot of the modules in my httpd.conf file are either replaced, removed completely or have had their names changed by some past update of the OS and/or Apache.
    This is very annoying because as a fix them (either removing them or changing names) it then uncovers more and more problems with the file. It looks like a massive job to manually change httpd.conf, save it, restart apache and then get the '-t' report to see what the next error is.
    I don't even have a guarantee this will solve my problem but quite clearly it IS a problem.

    Why is Mac OSX so poor at stuff like this?

    I'll report back if it works or not.

    Matt.

    P.S.
    Although not quite the same situation this article(http://golem.ph.utexas.edu/~distler/blog/archives/000698.html) seems to cover the same alterations to the httpd.conf file that I am currently making.
     
  20. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #20
    Ok, a total mess. Got rid of all errors and suddenly realised that there was a much neater and up-to-date version of httpd.conf in the apache2/original/folder.

    It seems like I'm trying to run a system which is half apache1 and half apache2 and it just isn't happening.

    How do I scrap the whole thing and start from scratch?

    Thanks,

    Matt.
     
  21. lawsonium thread starter macrumors newbie

    Joined:
    May 29, 2010
    #21
    OMG!!!!!!!!! I fixed it.

    I was right to copy the newer version of the httpd.conf file into /private/etc/apache2/ but that threw up litterally thousands of errors and warnings.

    The problem was that there was a rogue copy of httpd.conf in /private/etc/apache2/users/
    which was being picked up along with my own .conf due to the file /private/etc/apache2/extra/httpd-userdir.conf specifying this folder to include all (*.conf) files.

    Deleted the rogue file and checked I had copied the correct version from /private/etc/apache2/Original/ to /private/etc/apache2/ and it fired up straight away.

    Thank you so much everyone for your patience and help. You pushed me in the right direction and I managed to get a grip of the system in the end. I've learned a lot which should stand me in good stead for the future.

    The reason I want to set this up on my desktop is to work out why I can't get server session variables to persist after a page refresh on my web server!!!
    Hopefully now I can work on that. If not I'm sure I'll be back to pick your brains.

    Right, I'm off to bed. Thanks again :)

    Matt.
     

Share This Page