Yosemite / El Capitan php-gd + mcrypt installation
Asked Answered
E

4

51

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.

Espadrille answered 21/10, 2014 at 18:32 Comment(6)
GD should be installed by default with PHP on Yosemite, I believe. Do you have multiple copies of PHP? Can you check with a phpinfo() on your webserver which 'php' is being used and compare it with the output of which php?Disfranchise
hello, that line outputs /usr/bin/phpEspadrille
So, Apple installed GD (and you're using their build of PHP, which is fine), but did not include support for PNG. Let me see if I can make it work.Disfranchise
Yes, I am using Apples PHP out of box + installed/compiled in mcrypt using this tutorial coolestguidesontheplanet.com/…Espadrille
Yes, I was going to propose a similar solution. However, since GD is already builtin you cannot recompile the extension and load it dynamically. I'm afraid you'll have to recompile PHP from source.Disfranchise
try github.com/phpbrew/phpbrewSoupspoon
C
81

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!

Chemisorb answered 22/10, 2014 at 10:37 Comment(20)
How do I install/compile in mcrypt?Espadrille
@Kyslik, have a look at these two answers to a corresponding question: https://mcmap.net/q/298117/-installing-mcrypt-on-osx-10-8-2-php-5-3-15-with-homebrew https://mcmap.net/q/298117/-installing-mcrypt-on-osx-10-8-2-php-5-3-15-with-homebrewChemisorb
I did it easily with one line command "brew install php55-mcrypt"Espadrille
I don't call this quick and simple at all! And not transparent as well. Only for PNG.Popele
@Sanne: if you down-vote me I would appreciate, if you were able to also provide a quicker, simpler and more transparent solution (using your terms). There are many systems out there that definitely need PNG generation, so an "only for PNG" does not help the OP or anybody else.Chemisorb
Anyone know why apple chose not to install PNG support?Rodroda
@donatJ: Considering the Apple target group this is really hard to understand. I guess they simply "forgot it" and will add it back in a future update of Yosemite.Chemisorb
@Chemisorb Any other ideas why its not working? Is there a command that will tell me if I installed it correctly?Ocam
@vinylDeveloper: Did you try brew list to see which packages have been installed? This is the minimum that should be in your list for PHP5.5: freetype, icu4c, libpng, php55m, zlib, gettext, jpeg, libtool, unixodbc. Otherwise there are many good Homebrew tutorials out there. Google will help.Chemisorb
@Chemisorb Got it thanks... I overlooked commenting out the Yosemite LoadModule line... oh, the power of a "#" !!! Thanks for the helpOcam
@Chemisorb The function I am trying to use is imagettfbbox(). The error is "Call to undefined function". I followed step by step your instructions just in case they did it for me too. But it still is not working. I opened a new case. I'd feel really grateful if you (or anyone) could take a look: #29403142. Thank you!Conversational
Hi @ElPiter! Check my answer to your other posting. Obviously you have GD active but are missing FreeType. FreeType and imagettfbbox() are both available in my PHP incarnation, which I created using the above instructions. Are you sure you implemented each single step? You might want to try brew install freetype.Chemisorb
Hi @Jpsy. I commented your comment in the other post. There is something I am clearly missing. But I followed each single step. :(Conversational
Ok! Finally accepting the answer. I haven't linked properly the new php module in httpd.conf. Thanks a lot!Conversational
Thanks for the tip, but php is not loaded at all after completing these steps. The binary is in the given directory, other php module requiries are commented. :(Greatgrandaunt
@banesto: Did you add the LoadModule line as described? Have you verified that the path to the PHP module is correct in that line (it contains the PHP version number!)? Have you checked the apache error log after restart?Chemisorb
I've decided to go with Vagrant box instead and I'm happy I did it :)Greatgrandaunt
If you installed PHP5.6 add the following in httpd.conf (php56 instead of php55) LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.soPillion
Thanks @biko, I just updated my answer to remove that ambiguity.Chemisorb
Would you update for Sierra? Should be simple just add --with-apache flag I guess; can not test since I am still on 10.10Espadrille
C
21

The answer from @Jpsy is good, but there's another option, from the guys from liip, here. This is a PHP package that comes pre-built for Yosemite (older versions works too) but it 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. The configuration that cames with that installation is well suited for Symfony 2 development, but it should work just fine with other use cases.

Finally, if you need to use the updated PHP CLI, too, but you don't want to use the PHP version that comes with the OS, then you could also add to your .bash_profile or similar this line of code:

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

Creed answered 25/10, 2014 at 5:20 Comment(4)
Thanks, simple fast and worked solution that is exactly what I need.Regnant
My pleasure. I think the solution above is good too, but it is too much complication for something so simple to do. Plus, this solution also came with a default configuration suitable for most web development projects...Beam
This did not fix the problem for me, I still had a missing mcrypt extensionLowbrow
How does one remove this package and revert to brew's version?Importunate
D
3

I don't have enough rep to make a comment, but if you're 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

mine looks like this now and confirmed it is working 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
Dietitian answered 5/1, 2015 at 20:10 Comment(0)
B
0

Standard Apache coming with Yosemite the file to update after

sudo brew install php55

is in /etc/apache2/httpd.conf

Note that location of php.ini is also changed. The standard one coming with Yosemite is in /etc/php.ini, the one with homebrewed version is in /usr/local/etc/php/5.5/php.ini

Brookbrooke answered 10/1, 2015 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.