Install Yosemite / El Capitan php-gd + mcrypt

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

note that the following steps install the new PHP 5.5.x

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




Gd

So, Apple installed GD (and you use their PHP build, which is good), but did not include PNG support.

You definitely miss the "full" gd (with png support) if: The imagecreatefrompng () function is missing.

"Call to undefined function imagecreatefrompng()"

enter image description here




Mcrypt

install brew using the accepted answer and skip the install part of gd (if you don't need it) and use the following steps:

  • do a search - $ brew search mcrypt
  • choose the version of PHP you want
  • install - $ brew install php55-mcrypt
  • confirm with $ php -m | grep mcrypt $ php -m | grep mcrypt



Want to switch between PHP versions?

Check brew-php-switcher and follow the instructions.

+49
php homebrew osx-yosemite osx-elcapitan php-gd
Oct 21 '14 at 18:32
source share
4 answers

You are right, Yosemite inline PHP comes without PNG and FreeType support.
2015/10 Update for El Captian:. With OS X 10.11, support for ElGlanguage PNG has returned, but FreeType is still missing.

Decision

Use the Homebrew package manager to seamlessly create and install full PHP and replace it in your Apache configuration. The whole process takes about ten minutes if you follow these steps.

A quick (but complete) walk around

(Note 1: here I use Homebrew, the package management system for OS X. If you are familiar with MacPorts - another package manager - you can get the same results with this system. It is also possible to use my Homebrew solution in parallel with the existing MacPorts installation on your computer .)
(Note 2: If you want to read all the details of the installation process, see the basic Homebrew installation and information on the PHP home installation , but you won’t need it if you follow these steps.)

Now let go ...

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

Now you need to install the Xcode command line tools. To do this, open a terminal and enter:

 xcode-select --install 

The following 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.

The following command to enter is a kind of system state test:

 brew doctor 

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

Now configure the homebrew / dupes keyword, which has the necessary dependencies:

 brew tap homebrew/dupes 

Install a homebrew / version tap that also has the necessary dependencies:

 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 can do one of the following:

 brew options php55 brew options php56 

But I was fine using the default settings.
To do this, enter ONE of these two, depending on your needs:

 brew install php55 brew install php56 

(It will take some time, please be patient!)

there is an error installing php56 (5.6.x) on Yosemite (10.10.5), see this issue on github, use brew install php56 --without-ldap instead.

If you get the error “Cannot find OpenSSL”, you did not install the Xcode command line tools, as I told you at the beginning .;) Go ahead, install them and run the last command.

PHP is now built, and the script will contain some information on how to use it:

Open httpd.conf (should be located in / private / etc / apache 2 / httpd.conf) and enable PHP by adding ONE of these two lines, depending on which version of PHP 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 

Do not forget to comment on any existing line LoadModule php5_module ..., which may be present in the native version of PHP Yosemite!

Restart apache

 sudo apachectl restart 

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

Enjoy it!

+78
Oct 22 '14 at 10:37
source share

The answer from @Jpsy is good, but there is another option, from the guys from liip, here . This is a PHP package that ships in advance for Yosemite (older versions also work), but this is just one line of code:

curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5

After that, everything is ready to work, as expected. A configuration that matches this setting is well suited to developing Symfony 2, but it should work fine with other use cases.

Finally, if you also need to use the updated CLI for PHP, but you do not want to use the version of PHP supplied with the OS, then you can also add to your .bash_profile or similar line of code

export PATH=/usr/local/php5/bin:$PATH

+21
Oct 25 '14 at 5:20
source share

I do not have enough comments to make a comment, but if you are using OS X Server for Yosemite (version 4 from the App Store), the file to edit is:

/library/server/web/config/apache2/httpd_server_app.conf

my view now looks and confirmed that it works after using php 5.6 from homebrew.

 #LoadModule php5_module libexec/apache2/libphp5.so LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so 
+3
Jan 05 '15 at 20:10
source share

The standard Apache that ships with Yosemite, the file for updating after

 sudo brew install php55 

located in /etc/apache2/httpd.conf

Please note that php.ini location has also been changed. The standard one included in Yosemite is in /etc/php.ini, the one that has a home version is in /usr/local/etc/php/5.5/php.ini

0
Jan 10 '15 at 16:53
source share



All Articles