PHP not working in OS X Server

Discussion in 'Mac OS X Server, Xserve, and Networking' started by J. J., Oct 6, 2013.

  1. J. J. macrumors regular

    J. J.

    Oct 15, 2012
    I have a server running OS X 10.8.2. I wanted to install PhpMyAdmin, so I have installed MySQL and PHP (through MacPorts) too. Then I put the PhpMyAdmin folder in the root of my webserver, but when I surf to http://SERVERADDRESS/PhpMyAdmin on any web browser on any device I get the source code of the index.php file instead of the page loaded (see screenshot). I have already uncommented out the line
    #LoadModule php5_module libexec/apache2/
    in the file httpd.conf and added the following lines:
    AddHandler php5-script .php
    AddType text/html .php
    . I have also configured the file php.ini so I can't really understand what I'm doing wrong. (Note: I have obviously restarted Apache after changing the files.) Can you help me please?


    Attached Files:

  2. bevel macrumors newbie

    Jul 18, 2009
    Hi there Jaggions. Try adding this to you apache config:

    <IfModule mod_php5.c>
    AddType  application/x-httpd-php         .php
    AddType  application/x-httpd-php-source  .phps
    Also, if you installed the php5 package through macports you probs installed apache2 as well. If so, you may have 2 versions of apache installed. Macports installs a version into /opt/local and the os x version is in /usr/sbin.

    If you want to use the OSX apache with the macports php you will need to specify a full path to the macports php5 shared object from your OSX httpd.conf:

    LoadModule php5_module /opt/local/apache2/modules/
    BTW I haven't tested this^ and it may not work :). You're probs better off either using the OSX version of PHP with the OSX version of apache, or using the macports version of apache2 with the macports php5. The latter would require reconfiguring macports apache to use php. The macports apache config file is located at /opt/local/apache2/conf/httpd.conf. You can get the macports version of apache to load by stopping the OSX version then running

    sudo port load apache2
    This will mean apache and php can both be kept up to date using macports, and any future dependencies will be handled for you by macports.
  3. J. J. thread starter macrumors regular

    J. J.

    Oct 15, 2012
    Thank you for your exhaustive answer. Well this didn't work :mad:

    I didn't install Apache2 through MacPorts; I'm using the OS X one. About PHP: I didn't know it was already installed in OS X; that's why I have downloaded it. So... what's next?
  4. bevel macrumors newbie

    Jul 18, 2009
    I just ran the OSX version of apache in OS X 10.7.5, and made the same changes as you described to my httpd.conf - and php worked fine??

    Maybe the PHP module isn't being loaded for some reason on your machine. This command will give you a list of every module running in apache:

    apachectl -M
    If PHP is running you should be able to see this line:

    php5_module (shared)
    Can you post the output?
  5. alexrmc92 macrumors regular

    Feb 7, 2013
    Loading a MacPorts installed version of PHP is not the same as loading the built in module. Theres quite a bit of custom configuration involved.

    Try enable PHP in server admin
  6. J. J. thread starter macrumors regular

    J. J.

    Oct 15, 2012
    Here it is:
    servertoshiba:~ jaggions-osx86$ apachectl -M
    WARNING: MaxClients of 150 exceeds ServerLimit value of 133 servers,
     lowering MaxClients to 133.  To increase, please see the ServerLimit
    Loaded Modules:
     core_module (static)
     mpm_prefork_module (static)
     http_module (static)
     so_module (static)
     authn_file_module (shared)
     authn_dbm_module (shared)
     authn_anon_module (shared)
     authn_dbd_module (shared)
     authn_default_module (shared)
     authz_host_module (shared)
     authz_groupfile_module (shared)
     authz_user_module (shared)
     authz_dbm_module (shared)
     authz_owner_module (shared)
     authz_default_module (shared)
     auth_basic_module (shared)
     auth_digest_module (shared)
     cache_module (shared)
     disk_cache_module (shared)
     mem_cache_module (shared)
     dbd_module (shared)
     dumpio_module (shared)
     reqtimeout_module (shared)
     ext_filter_module (shared)
     include_module (shared)
     filter_module (shared)
     substitute_module (shared)
     deflate_module (shared)
     log_config_module (shared)
     log_forensic_module (shared)
     logio_module (shared)
     env_module (shared)
     mime_magic_module (shared)
     cern_meta_module (shared)
     expires_module (shared)
     headers_module (shared)
     ident_module (shared)
     usertrack_module (shared)
     setenvif_module (shared)
     version_module (shared)
     proxy_module (shared)
     proxy_connect_module (shared)
     proxy_ftp_module (shared)
     proxy_http_module (shared)
     proxy_scgi_module (shared)
     proxy_ajp_module (shared)
     proxy_balancer_module (shared)
     ssl_module (shared)
     mime_module (shared)
     dav_module (shared)
     status_module (shared)
     autoindex_module (shared)
     asis_module (shared)
     info_module (shared)
     cgi_module (shared)
     dav_fs_module (shared)
     vhost_alias_module (shared)
     negotiation_module (shared)
     dir_module (shared)
     imagemap_module (shared)
     actions_module (shared)
     speling_module (shared)
     userdir_module (shared)
     alias_module (shared)
     rewrite_module (shared)
     php5_module (shared)
     hfs_apple_module (shared)
    Syntax OK

    I downloaded PHP because I thought it wasn't installed on OS X by default; should I uninstall it? And since OS X 10.7 there is no Server Admin app ;)
  7. theluggage macrumors 68040

    Jul 29, 2011
    The MacPorts PHP won't do any harm - it lives in its own little world under /opt/local.

    ISTR that the way to turn on PHP in Lion Server and later is to enable blogs/wikis in the Server app. Obvious, really :confused:

    Unless you're using other OSX Server features, I'd switch to the MacPorts versions of Apache2 and PHP - much easier to add the PHP modules you want.

Share This Page