Hector Ordonez Hector Ordonez - 2 years ago 151
PHP Question

Apache 2.4 not loading php5.5 with Mac OS 10.8

I am trying to use Apache 2.4.7 with php5.5 in my Mini Mac with Mac Os 10.8.5

Apache 2.4.7 installed following instructions in here

Run apachectl -v, shows

Server version: Apache/2.4.7 (Unix)
Server built: Mar 4 2014 19:23:56

PHP5.5 installed following instructions in here

Run php -v, shows

PHP 5.5.8 (cli) (built: Jan 12 2014 18:50:29)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans

I added in the apache http.conf file the following line

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

But it does not seem to work, as when I try to start the server with

sudo apachectl start

It produces the following error

httpd: Syntax error on line 151 of /usr/local/apache-2.4.7/conf/httpd.conf:
Cannot load /usr/local/php5/libphp5.so into server:
dlopen(/usr/local/php5/libphp5.so, 10): Symbol not found:
Referenced from: /usr/local/php5/libphp5.so
Expected in: /usr/local/apache-2.4.7/bin/httpd in /usr/local/php5/libphp5.so

As suggested in the tutorials I have linked, I modified my bash profile with

export PATH=~/bin:/usr/local/php5/bin:$PATH
export MANPATH=/usr/local/apache/man:$MANPATH

I have been trying for hours different solutions, and this is as far as I got.

If someone can give me some hints I would be very happy, I am quite desperate...!

Answer Source

After hours and hours of try this and do that, I managed to make it work.

I will describe what I did, in order to help other people save those hours!

Be aware that this solution works for the MAc OS X 10.8.5. It might not work for you!

The following is to have apache 2.4.7 with php 5.5 working

  1. Update and download tools you need.

    1.1 - XCode. Get it from Apple Store for free.

    1.2 - XCode command line. Go to XCode, Preferences, Downloads, and get the command line.

    1.3 - Homebrew. Use the following command:

    ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

    See the website for more info.

  2. Several checks

    2.1 - Check that there is no current apache or php instalation annoying around. To do so I deleted them and hunted down config files, just in case, with the commands

    find /usr -name "apache"
    find /usr -name "httpd"
    find /usr -name "php

    2.2 - Use brew doctor to confirm no configs are annoying the setup.

    brew doctor

    2.3 - Check that you did it right by confirming that following commands do not work

    php -v
    apachectl -v
    httpd -v
  3. Install apache

    3.1 - Use the homebrew apache2 from djl.

    brew tap djl/homebrew-apache2
    brew install djl/apache2/apache24

    3.2 - Modify your .bash_profile in order to make the /usr/local/bin the priority folder (so the system gets the apache and php from there instead other folder like /usr/sbin)

    echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile

    3.3 - Confirm that apache works. To do this, start the service and go to localhost where "It works" appears. Then shut it down to proceed with php.

    sudo apachectl start
    (Go to browser and open localhost)
    sudo apachectl stop
  4. Install php

    4.1 Use the homebrew php from josegonzalez

    brew tap homebrew/dupes
    brew tap homebrew/versions
    brew tap josegonzalez/homebrew-php
    brew install php55

    4.2 In case it did not work because of the following error :

    cannot open /usr/share/httpd/build/config_vars.mk: No such file or directory at /usr/sbin/apxs line 217.

    ... create a symlink this way:

    cd /usr/share/
    sudo ln -s /usr/local/Cellar/apache24/< apache version installed >/ httpd

    ... and execute the install again.

    < apache version installed > will depend on the version installed. At the moment of this writing, it is 2.4.10

  5. Tell Apache about its new friend.

    5.1 Modify the httpd.conf. First open the file.

    cd /usr/local/etc/apache2/
    sudo nano httpd.conf

    ... then add the php module in the LoadModule section (search for LoadModule)

    LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so

    ... and add the php type in the mime_module. Search for mime_module and, in that section, search for # Filters

    ... add the next line under them.

    # process php type files using apache php module
    AddType application/x-httpd-php .php

    that tells Apache to run the file through it's php processor prior to sending it to the client.

    ... save and exit.

  6. OPTIONAL, if you want to store the Sites in your User folder instead of WebService.

    6.1 Modify again the httpd.conf. Open the file.

    cd /usr/local/etc/apache2/
    sudo nano httpd.conf

    And add the following lines at the end of the file, replacing with your username.

    ServerName dev.local
    User <username>
    Group staff
    DocumentRoot "/Users/<username>/Sites"
    ErrorLog "/usr/local/var/log/apache-error.log"
    CustomLog "/usr/local/var/log/apache-access.log" common
    <Directory "/Users/<username>/Sites">
      Options All
      AllowOverride All
      IndexOptions NameWidth=*
      Require all denied
      Require host localhost
      Require host
  7. Finish it!

    7.1 Start apache service

    sudo apachectl start

    7.2 Create a php file in the root of your Sites folder (If you did step 6, create it in /Users//Sites/test.php)

    7.3 Open it.

    Go to Browser and localhost/test.php

Good luck.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download