Apache 2.4在Mac OS 10.8上无法加载php5.5

5
我正在尝试在我的Mini Mac中使用Mac Os 10.8.5和php5.5的Apache 2.4.7.
我按照这里的说明安装了Apache 2.4.7.
运行apachectl -v,显示如下:
Server version: Apache/2.4.7 (Unix)
Server built:   Mar  4 2014 19:23:56

按照这里的指示安装了PHP5.5。

运行php -v,显示如下:

 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

我在apache http.conf文件中添加了以下行:
LoadModule php5_module /usr/local/php5/libphp5.so

但似乎无法正常工作,因为当我尝试使用以下命令启动服务器时:
sudo apachectl start

它产生以下错误。
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:
            unixd_config\n
Referenced from: /usr/local/php5/libphp5.so
Expected in: /usr/local/apache-2.4.7/bin/httpd in /usr/local/php5/libphp5.so

如我所链接的教程所建议的那样,我修改了我的bash配置文件:

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

我已经尝试了几个小时不同的解决方案,但是这是我能做到的最好程度。

如果有人能给我一些提示,我会非常高兴,因为我已经感到绝望了...!

3个回答

7

经过数个小时的尝试和实践,我终于成功了。

为了帮助其他人节省时间,我将描述我所做的事情!

请注意,此解决方案适用于Mac OS X 10.8.5。它可能不适用于您的系统!

以下是让apache 2.4.7php 5.5正常工作的步骤:

  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 127.0.0.1
    </Directory>
    
  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
    

祝你好运。


1
我们深刻地感受到您的挫败感。我们也尝试过与您同样的方法,但失败了,于是决定尝试Brew。Brew 抱怨 MacPorts 仍然安装着,“which port” 命令向我们展示了需要删除的文件位置。准备好开始使用 Brew 了……接下来出现了一个编译错误。我们需要从 /usr/local/apache/bin 复制 apsx 到 /usr/sbin,然后 Brew 就完成了安装和编译。但是没有 PHP 解析。起初 MIME 的问题让我们感到困惑,因为我们认为这与将文件发送到浏览器有关(即发送 mp3 文件会在计算机上打开 mp3 播放器),但是按照您的指示,PHP 得以解析。我们也修改了那一部分以帮助您! - Steve Wasiura
很高兴它有所帮助!当然欢迎贡献。希望它也能帮助其他人。 - Hector Ordonez
我不太理解第4.2步骤,我应该将指向包含“config_vars.mk”的文件夹的符号链接添加到httpd的二进制文件夹还是apxs的二进制文件夹? - Fractaliste
进入Apache的文件夹。 - Hector Ordonez

0

我猜你在加载libphp5.so时,遇到了apache2中的zend_parse_parameter错误:

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:

请查看./configure输出。如果您收到类似以下消息的警告:

configure: warning: bison versions supported for regeneration of the Zend/PHP parsers: 1.28 1.35 1.75 1.875 2.0 2.1 2.2 2.3 2.4 2.4.1 (found: none).

请尝试安装bison:sudo apt-get install bison

然后执行make distclean,接着./configure ... 最后执行make -i install


感谢您的帮助,不幸的是它没有解决问题。 - Hector Ordonez
1
很遗憾听到这个消息 :( - mahmoud nezar sarhan

0

这份指南非常好,除了第4.1步骤,你需要像这样安装php:

brew install php55 --homebrew-apxs

这一行将自动将“LoadModule php5_module…”放入httpd.conf中,因此如果有人完成了上面的其他步骤,只需使用以下命令删除php:

brew remove php55

然后使用以下命令安装PHP:

brew install php55 --homebrew-apxs

然后就没有问题了!


这确实会使步骤5变得不必要。对答案的很好贡献 - 但本身并不是一个答案。 - Hector Ordonez

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接