douweng3564 2014-10-21 18:32
浏览 28
已采纳

Yosemite / El Capitan php-gd + mcrypt安装

How to install/enable php-gd and mcrypt in Yosemite 10.10 - PHP 5.5.14 build?

note that following steps install newest PHP 5.5.x

To check if you have gd and mcrypt installed use $ php -m to display compiled in modules, continue if you are missing desired modules and please see accepted answer.


GD

So, Apple installed GD (and you're using their build of PHP, which is fine), but did not include support for PNG.

You are definitely missing "full" gd (with png support) module if: imagecreatefrompng() function is missing.

"Call to undefined function imagecreatefrompng()"

enter image description here


Mcrypt

install brew using accepted answer and omit part with gd installation (unless you need it), and use following steps:

  1. do search - $ brew search mcrypt
  2. pick the version of PHP you want
  3. install - $ brew install php55-mcrypt
  4. confirm using $ php -m | grep mcrypt

Want to switch between PHP versions?

Check out brew-php-switcher and follow instructions.

  • 写回答

4条回答 默认 最新

  • dongmi5015 2014-10-22 10:37
    关注

    You are right, Yosemite's built-in PHP comes without PNG and FreeType support.
    Update 2015/10 for El Captian: With OS X 10.11 El Capitan PNG support is back, but FreeType is still missing.

    Solution

    Use the Homebrew package manager to painlessly build and install a complete PHP and replace it in Apache's config. The whole process only takes about ten minutes if you follow the steps below.

    A quick (but complete) walk through

    (Note 1: I use Homebrew here, a package management system for OS X. If you are acquainted with MacPorts – another package manager – you can acchieve the same results with that system. It is also possible to use my Homebrew solution in parallel to an existing MacPorts installation on your machine.)
    (Note 2: If you want to read all the details about the installation process, have a look at the Homebrew basic installation and the Homebrew PHP installation information. But you really won't need that if you follow these steps.)

    Now let's go...

    First install Xcode from App Store. If you already have it, check App Store again, to make sure you've got the latest version!

    Now you need to install the Xcode Command Line Tools. To do so, open a Terminal and enter:

    xcode-select --install
    

    The next command will install the Homebrew package manager system:

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    

    The script explains what it will do and then pauses before it does it.

    The next command to enter is a kind of system status test:

    brew doctor
    

    This checks the basics of the Homebrew installation.
    I got a warning "You have MacPorts or Fink installed: /opt/local/bin/port ..." which I ignored successfully. ;)

    Now setup the homebrew/dupes tap which has dependencies we need:

    brew tap homebrew/dupes
    

    Setup the homebrew/versions tap which also has dependencies we need:

    brew tap homebrew/versions
    

    Then run the following command:

    brew tap homebrew/homebrew-php
    

    Now you are ready to finally build PHP. For a list of available configuration options you may run one of these:

    brew options php55
    brew options php56
    

    But I was fine just using the defaults.
    To do so enter ONE of these two, depending on your needs:

    brew install php55
    brew install php56
    

    (This takes a while, please be patient!)

    while installing php56 (5.6.x) on Yosemite (10.10.5) there is a bug please see this issue on github. use brew install php56 --without-ldap instead.

    If you get an error of type "Cannot find OpenSSL's " you have not installed the Xcode Command Line Tools as I told you in the beginning. ;) Go ahead, install them and re-run that last command.

    PHP is built now and the script will end with some details about how to use it:

    Open httpd.conf (should be located at /private/etc/apache2/httpd.conf) and enable PHP by adding ONE of these two lines, depending on which PHP version you just installed:

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

    Don't forget to comment out any existing LoadModule php5_module... line that might be present from Yosemite's own PHP version!

    Restart Apache

    sudo apachectl restart
    

    Your new php.ini file can be found in: /usr/local/etc/php/5.5/php.ini

    Enjoy!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀