Wrong PHP version running and cannot stop brew service [duplicate] - php

On my mac I've got php installed and working fine. I recently wanted to install mcrypt, so I did so using brew. Although it seemed to install fine, it doesn't show up in my phpinfo(). So I think that the php that brew installed mcrypt in, isn't the php that apache uses.
Does anybody know how I can:
check whether there is a difference between the php installed by brew and the php which Apache uses?
make apache use the php that brew installed?
All tips are welcome!

According to the contributors of the Homebrew php formula...
The contributors of the Homebrew php formula give the following instructions. The exact instructions reproduced here install php7.4. Substitute the php version you need.
(Avoid "special" ways of accomplishing your objective; they are often problematic. "Official" approaches are more likely to give you a predictable, maintainable setup.)
$ brew search php // since php can be installed by homebrew but be missing from your PATH, review the list of php versions available through homebrew; a checkmark next to a version indicates one is installed
$ brew install php#7.4
$ echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> ~/.zshrc // add the alias to your path (issues you are using zsh, the default now for macOS); see comments output during installation
$ source ~/.zshrc // reload . zshrc to use the new settings immediately
The contributors of the formula also provide the following instructions for enabling PHP in Apache:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>`
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.4/
These instructions for enabling PHP in Apache appear in stdout when you install php. Alternatively in Terminal use brew info php or visit the Homebrew PHP formula page

You have to make your Apache use the PHP that you just downloaded.
Open your httpd.conf (mine is at /etc/apache2/httpd.conf) and look for the line that loads the PHP module, something like:
LoadModule php5_module path/to/php
Then, make it point to the PHP that brew installed for you with mcrypt support. Mine was at this path. Yours can vary depending on the PHP version that you installed.
/usr/local/Cellar/php54/5.4.21/libexec/apache2/libphp5.so
Finally you will need to restart your Apache server to load the new configuration:
sudo apachectl restart

Can't comment on stackoverflow yet due to my lack of experience but to add to the above answer is correct. Just an additional comment to find the correct path:
run:
brew info php54
or which ever version u have installed and it will show you the path:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/opt/php54/libexec/apache2/libphp5.so

brew install php installs php 7.3 at the moment, versions below are keg-only
You can make aliases for versions below by adding this to:
~/.profile
alias php#5.6='$(brew --prefix php#5.6)/bin/php'
alias php#7.0='$(brew --prefix php#7.0)/bin/php'
alias php#7.1='$(brew --prefix php#7.1)/bin/php'
alias php#7.2='$(brew --prefix php#7.2)/bin/php'
~/.bashrc
source ~/.profile
~/.zshrc
[[ -e ~/.profile ]] && emulate sh -c 'source ~/.profile'
Then you can:
php#5.6 -v
php#7.0 -v
php#7.1 -v
php#7.2 -v
If you use composer and the platform php is not set in your project then this can be handy:
~/.profile
alias composer#5.6='php#5.6 $(which composer)'
alias composer#7.0='php#7.0 $(which composer)'
alias composer#7.1='php#7.1 $(which composer)'
alias composer#7.2='php#7.2 $(which composer)'
If you use artisan a lot (artisan maps to php which is 7.3) then this can be handy:
~/.profile
alias artisan#5.6='php#5.6 artisan'
alias artisan#7.0='php#7.0 artisan'
alias artisan#7.1='php#7.1 artisan'
alias artisan#7.2='php#7.2 artisan'

I would create an alias to it so you don't disturb the system PHP install.
brew info php71
Brew installs into /usr/local/Cellar so you can add the following to your ~/.bash_alias or ~/.profile.
alias php7='/usr/local/Cellar/php71/7.1.10_21/bin/php'

Try: brew link php71 --force to use brew specific php version.
It worked for me.

As of 2021, all you need is
brew install php
then
brew link php
This will give you php 8.0 and setup your symlinks.

Related

How to upgrade php7.1 to 7.3 on Mac

I have macOS 10.14.6 Mojave. It had installed php 7.1.33 initially.
I would like to upgrade php 7.3 using brew install.
I executed brew instal php#7.3 and it was succeed.
However the original php7.1.33 is sticked in /usr/bin/php.
I tried remove or rename the php with sudo mv php php_org.
But it does not work. Operation not permitted.
What is wrong?
Please tell me some advice.
Finally I put next script in .bash_profile.
export PATH="/usr/local/Cellar/php#7.3/7.3.16/bin:$PATH"
It worked.
in your .bash_profile add:
export PATH="/usr/local/bin:$PATH"
open a new terminal window and verify the path setting
php -v
Also, if you use apache, update /usr/local/etc/http/httpd.conf , update to
LoadModule php7_module /usr/local/opt/php#7.3/lib/httpd/modules/libphp7.so
then
sudo apachectl -k restart

MacOS Catalina: Class 'ZipArchive' not found

Upgrading to 10.15.1 (19B88) Mac OS Catalina broke my PHP 7.3.9 development environment.
$zip = new \ZipArchive;
Yields Exception 'Error' with message 'Class 'ZipArchive' not found'
zip and unzip are installed at Terminal command line.
Trying to use PECL failed. Trying to use Homebrew failed.
Do you know how to properly install ZipArchive manually on MacOS?
I had the same problem and this is what helped me.
Basically what I did is I just installed php using brew and then linked the php that I have installed using brew inside of httd.conf file. Here are the steps:
Install php using home brew
brew install php#7.3
This will install php. Now we need to link it
brew link php#7.3
If the command above wont work because of the missing directories, then just create them using mkdir and run it again.
Link you php in httd.conf file
Open the httpd.conf file which is located here /private/etc/apache2/httpd.conf
Open it and change this line
LoadModule php7_module libexec/apache2/libphp7.so
to this:
LoadModule php7_module /usr/local/Cellar/php/7.3.11/lib/httpd/modules/libphp7.so
What this basically dow is it just makes apache to use php that is installed using homebrew. Hope this was helpful to you.
Here is a link where it is better described how to connect homebrew installed php:
How to use the php that brew installed?
What I did was the following,
brew install php#7.3
php version 7.3.19 was installed.
Then edited my httpd.conf using
sudo nano /private/etc/apache2/httpd.conf
The following line in http.conf
LoadModule php7_module libexec/apache2/libphp7.so
was replaced with
LoadModule php7_module /usr/local/opt/php#7.3/lib/httpd/modules/libphp7.so
Added the following to http.conf right after modules block
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
In nano I searched for DirectoryIndex using ctrl+W
added index.php to finally make it
DirectoryIndex index.php index.html
Then I updated my PATH variable using
echo 'export PATH="/usr/local/opt/php#7.3/bin:$PATH"' >> /Users/<your user>/.bash_profile
echo 'export PATH="/usr/local/opt/php#7.3/sbin:$PATH"' >> /Users/<your user>/.bash_profile
Then I made a new directory sbin as following,
sudo mkdir /usr/local/sbin
Changed ownership to current user,
sudo chown -R $(whoami) /usr/local/sbin
Linked brew
brew link php#7.3 --force
Restarted Apache
sudo apachectl restart
Please Note: You do not have to probably do all of the steps or do it in same order, I only wanted to share what I did and worked for me.

Install postgresql with apache on Mac OSX

I am trying to make postgresql work with apache on my Mac OSX. I use homebrew to manage all my dev features, so I replace the default php version provided by apache and download a homebrew version, this part works really fine. The problem is when I want to install the postgresql extension..
I have done this :
brew install postgresql
brew install php55 --with-postgresql
brew install php55-pdo-pgsql
And then edit the /etc/apache2/httpd.conf file to replace LoadModule php5_module libexec/apache2/libphp5.so by LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so.
Then when I exec the phpinfo() command, I can't see the postgresql extension installed in the PDO section. I only have this :
If anyone can help ;) Thank you all !
Possible solution :
- First install all packets like this : brew install postgresql php55 php55-pdo-pgsql
- Then brew reinstall php55 --with-postgresql
And it works.. I did this before (maybe not the same order) and it didn't work, I do not know why it works now !
Solution
When you watch the phpinfo() result, you should see something something like Loaded Configuration File and *Scan this dir for additional .ini files *. The thing is there is a global php.ini file and a .ini file per extension you install.
The value for *Scan this dir for additional .ini files * is where the .ini file for the extension must be located. So just need to create a ext-pdo_pgsql.ini and load the extension with extension="path to your/pdo_pgsql.so" (mine was /usr/local/opt/php55-pdo-pgsql/pdo_pgsql.so).
And for the installation just need brew install php55 php55-pdo-pgsql postgresql
Run php -m | grep pgsql to know if pgsql exists
Follow the example in this answer. Jump to note if you have a problem with the instruction there corresponding to number 4 here.
Enter ./configure --with-pdo-pgsql="path to postgres" and return. Mine is at "/usr/local/bin".
Enter make && sudo make install and return.
Add the extension to php.ini with sudo echo "extension=pdo_pgsql.so" >> path to php.ini. Find the path using php -i | grep php.ini
That should install pdo driver for postgres
Note
It is possible that sudo make install doesn't work. It might be due to an OSX feature known as csrutil. Reboot your machine and hold down cmd + R. From the recovery inteface run csrutil disable from terminal.
Reboot again and perform the make install. Repeat same process as in the paragraph above to enable csrutil by running csrutil enable at the recovery interface's terminal.

Installing mcrypt extension for PHP on OSX Mountain Lion

Apologies in advance for the potential n00b questions, I am trying to install the mcrypt extension for PHP on my OSX Mountain Lion machine.
The following steps in terminal is what I have done so far to achieve my PHP install
cd /path/to/downloaded/php-5.3.21/ext/mcrypt/
/usr/bin/phpize
./configure
cd /path/to/downloaded/php-5.3.21
./configure --with-config-file-path=/private/etc/php.ini --with-apxs2=/usr/sbin/apxs
make
sudo make install
Which seems to work well and installs PHP 5.3.21 fine. I have then done
sudo nano /private/etc/php.ini
And included
extension=mcrypt.so
Along with an Apache restart, phpinfo() doesn't show that the mcrypt extension is loaded.
I then tried to specify the extension_dir inside php.ini, again with no luck.
I have done
locate mcrypt.so
/opt/local/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so
/usr/local/Cellar/php53-mcrypt/5.3.18/mcrypt.so
And tried both directories as the extension_dir, with no luck.
I have also tried the following, after much Googling
./configure --with-config-file-path=/private/etc/php.ini --with-apxs2=/usr/sbin/apxs --with-mcrypt
Which seems to work OK, but then upon "make", it returns
ext/mcrypt/mcrypt.o: No such file or directory
ext/mcrypt/mcrypt_filter.o: No such file or directory
Again, no success.
What am I doing wrong? It seems like the physical compile of mcrypt.so is not happening, or is compiling incorrectly as I would suspect there to be another mcrypt.so found under locate?
Anyone please help? I've gone through pages upon pages of Google searches with no luck!
I tend to use Homebrew on Mac. It will install and configure all the stuff for you.
Link
Then you should be able to install it with brew install mcrypt php53-mcrypt and it'll Just Work (tm).
You can replace the 53 with whatever version of PHP you're using, such as php56-mcrypt or php70-mcrypt. If you're not sure, use brew search php.
Do also remember that if you are using the built in Mac PHP it's installed into /usr/bin you can see which php you are using with which php at the terminal and it'll return the path.
I just went through this on Mountain Lion. Homebrew blocked on libiconv which it thought was missing but was actually up to date. After an hour of trying to get it to recognize libiconv, I gave up and installed it the old fashion way, which took all of five minutes...
(download your php version)
$ wget http://www.php.net/get/php-5.3.21.tar.gz/from/a/mirror
$ tar -xvzf php-5.3.21.tar.gz
$ cd php-5.3.21/ext/mcrypt
$ phpize
$ ./configure
$ make
$ make test
$ sudo make install
mcrypt.so is now in your PHP ext dir (/usr/lib/php/extensions/no-debug-non-zts-20090626/ in my case), now you need to add to php.ini as a module
$ vi /etc/php.ini
$ (insert) extension=mcrypt.so
$ sudo apachectl restart
Done - no brew necessary. HTH someone.
Installing php-mcrypt without the use of port or brew
Note: these instructions are long because they intend to be thorough. The process is actually fairly straight-forward. If you're an
optimist, you can skip down to the building the mcrypt extension
section, but you may very well see the errors I did, telling me to
install autoconf and libmcrypt first.
I have just gone through this on a fresh install of OSX 10.9. The solution which worked for me was very close to that of ckm - I am including their steps as well as my own in full, for completeness. My main goal (other than "having mcrypt") was to perform the installation in a way which left the least impact on the system as a whole. That means doing things manually (no port, no brew)
To do things manually, you will first need a couple of dependencies: one for building PHP modules, and another for mcrypt specifically. These are autoconf and libmcrypt, either of which you might have already, but neither of which you will have on a fresh install of OSX 10.9.
autoconf
Autoconf (for lack of a better description) is used to tell not-quite-disparate, but still very different, systems how to compile things. It allows you to use the same set of basic commands to build modules on Linux as you would on OSX, for example, despite their different file-system hierarchies, etc. I used the method described by Ares on StackOverflow, which I will reproduce here for completeness. This one is very straight-forward:
$ mkdir -p ~/mcrypt/dependencies/autoconf
$ cd ~/mcrypt/dependencies/autoconf
$ curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-latest.tar.gz
$ tar xzf autoconf-latest.tar.gz
$ cd autoconf-*/
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
Next, verify the installation by running:
$ which autoconf
which should return /usr/local/bin/autoconf
libmcrypt
Next, you will need libmcrypt, used to provide the guts of the mcrypt extension (the extension itself being a provision of a PHP interface into this library). The method I used was based on the one described here, but I have attempted to simplify things as best I can:
First, download the libmcrypt source, available from SourceForge, and available as of the time of this writing, specifically, at:
http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2/download
You'll need to jump through the standard SourceForge hoops to get at the real download link, but once you have it, you can pass it in to something like this:
$ mkdir -p ~/mcrypt/dependencies/libmcrypt
$ cd ~/mcrypt/dependencies/libmcrypt
$ curl -L -o libmcrypt.tar.bz2 '<SourceForge direct link URL>'
$ tar xjf libmcrypt.tar.bz2
$ cd libmcrypt-*/
$ ./configure
$ make
$ sudo make install
The only way I know of to verify that this has worked is via the ./configure step for the mcrypt extension itself (below)
building the mcrypt extension
This is our actual goal. Hopefully the brief stint into dependency hell is over now.
First, we're going to need to get the source code for the mcrypt extension. This is most-readily available buried within the source code for all of PHP. So: determine what version of the PHP source code you need.
$ php --version # to get your PHP version
now, if you're lucky, your current version will be available for download from the main mirrors. If it is, you can type something like:
$ mkdir -p ~/mcrypt/php
$ cd ~/mcrypt/php
$ curl -L -o php-5.4.17.tar.bz2 http://www.php.net/get/php-5.4.17.tar.bz2/from/a/mirror
Unfortunately, my current version (5.4.17, in this case) was not available, so I needed to use the alternative/historical links at http://downloads.php.net/stas/ (also an official PHP download site). For these, you can use something like:
$ mkdir -p ~/mcrypt/php
$ cd ~/mcrypt/php
$ curl -LO http://downloads.php.net/stas/php-5.4.17.tar.bz2
Again, based on your current version.
Once you have it, (and all the dependencies, from above), you can get to the main process of actually building/installing the module.
$ cd ~/mcrypt/php
$ tar xjf php-*.tar.bz2
$ cd php-*/ext/mcrypt
$ phpize
$ ./configure # this is the step which fails without the above dependencies
$ make
$ make test
$ sudo make install
In theory, mcrypt.so is now in your PHP extension directory. Next, we need to tell PHP about it.
configuring the mcrypt extension
Your php.ini file needs to be told to load mcrypt. By default in OSX 10.9, it actually has mcrypt-specific configuration information, but it doesn't actually activate mcrypt unless you tell it to.
The php.ini file does not, by default, exist. Instead, the file /private/etc/php.ini.default lists the default configuration, and can be used as a good template for creating the "true" php.ini, if it does not already exist.
To determine whether php.ini already exists, run:
$ ls /private/etc/php.ini
If there is a result, it already exists, and you should skip the next command.
To create the php.ini file, run:
$ sudo cp /private/etc/php.ini.default /private/etc/php.ini
Next, you need to add the line:
extension=mcrypt.so
Somewhere in the file. I would recommend searching the file for ;extension=, and adding it immediately prior to the first occurrence.
Once this is done, the installation and configuration is complete. You can verify that this has worked by running:
php -m | grep mcrypt
Which should output "mcrypt", and nothing else.
If your use of PHP relies on Apache's httpd, you will need to restart it before you will notice the changes on the web. You can do so via:
$ sudo apachectl restart
And you're done.
Why You're Getting This Error
PHP complains if one of the files like mcrypt.so is included using the syntax extension="mcrypt.so" but the file is not in the extension_dir path ( use <?php phpinfo(); ?> or php -i to check that).
It will also tell you which php.ini config file is being loaded so you will know where the settings are coming from. Most likely it will be something like /usr/local/etc/php/5.4/php.ini if you are using the homebrew version.
Take note of the part under it that says something like "Scan this dir for additional .ini files" because what that means is it gives you a place to put your own file, like tweaks.ini that is loaded after the main configuration file so that you can make changes and keep up with them easily. Also remember that all the files in this directory get loaded in alphabetical order, so if you have one called adjustments.ini that contains mcrypt directives, and there is a mcrypt.ini, most likely your settings will be overridden.
One alternative to specifying extension="mcrypt.so" is to specify the full path to the mcrypt.so file. The other option is to edit the extension_dir setting.
What worked for me
On Mavericks I didn't have to do either. I did a fresh install of homebrew and then added the josegonzalez tap using:
brew tap josegonzalez/homebrew-php
(My other laptop was running Mountain Lion and was also using homebrew in this setup.)
After you've tapped that awesome repo you can install php and mcrypt using something like:
brew install php54 php54-mcrypt
What if this doesn't work (and why should I use homebrew anyway?)
I would highly advise trying this route before downloading and building it from source. It's not hard to build from source - but I don't want to have to maintain that. It's one of the reasons to use homebrew in the first place - it's a package manager (with a HUGE community).
There is a lot of development on the homebrew project and - if you have problems I'd suggest checking out their issues page
So yes you can build it from source and that might seem like a good option right now if you just want mcrypt to work but you may hate yourself for doing this later...
If you don't want to be using php54 there is also the php53 branch. They have some instructions at the repo about how to use both of them / switch between them.
If you're new to homebrew you should know that you check out what else is available using brew search php54, which gives something like:
php54 php54-lzf php54-snappy
php54-amqp php54-mailparse php54-solr
php54-apc php54-mcrypt php54-ssh2
php54-apcu php54-memcache php54-stats
php54-boxwood php54-memcached php54-svm
php54-chdb php54-midgard2 php54-tidy
php54-couchbase php54-mongo php54-timezonedb
php54-dbase php54-msgpack php54-tokyotyrant
php54-ev php54-mysqlnd_ms php54-twig
php54-gearman php54-oauth php54-uploadprogress
php54-geoip php54-opcache php54-uuid
php54-gmagick php54-parsekit php54-varnish
php54-graphdat php54-pcntl php54-wbxml
php54-http php54-pdflib php54-xcache
php54-igbinary php54-phalcon php54-xdebug
php54-imagick php54-proctitle php54-xhgui
php54-inclued php54-pspell php54-xhp
php54-intl php54-pthreads php54-xhprof
php54-ioncubeloader php54-raphf php54-xmldiff
php54-jsmin php54-redis php54-yac
php54-judy php54-riak php54-yaf
php54-leveldb php54-runkit php54-yaml
php54-libevent php54-scrypt php54-yaz
php54-libvirt
TLDR
You should use homebrew to install mcrypt if at all possible
If you're getting errors it's probably because your configuration file(s) are messed up. Check the extension_dir path and figure out where the mcrypt.so file is and see if there is a discrepancy (or specify the full path)
For me, on Yosemite
$ brew install mcrypt php56-mcrypt
restart computer
did the trick.
Solution with brew worked only after the following:
in your php.ini
nano /private/etc/php.ini
add this line:
extension="/usr/local/Cellar/php53-mcrypt/5.3.26/mcrypt.so"
Warning! Set the correct PHP version.
I would recommend installing everything via homebrew if you have the option. I went in circles for a while, but installing php 5.x via brew and then the neccessary modules worked a treat. I was working with php 5.4 and used this to get going initially:
https://github.com/josegonzalez/homebrew-php
and then installed the additional modules with:
brew install php54-redis
brew install php54-xdebug
brew install php54-mcrypt
...
Another possibility for those who want to keep OS X as clean as possible, is to use vagrant [1] to define a php development environment. Vagrant can use VirtualBox [2] in headless mode (~3% of CPU on my 13-inch, Mid 2009 MacBook Pro) to run a virtual machine with the webserver and php and all.
To easily create the vagrant environment you can use this great tool https://puphpet.com/
http://www.vagrantup.com/
https://www.virtualbox.org/
I'd create a shell script to install mcrypt module for PHP 5.3 without homebrew.
The scripts install php autoconf if needed and compile module for your php version.
The link is here: https://gist.github.com/lucasgameiro/8730619
Thanks
Nothing worked and finally got it working using resource #Here and Here; Just remember for OSX Mavericks (10.9) should use PHP 5.4.17 or Stable PHP 5.4.22 source to compile mcrypt. Php Source 5.4.22 here
Brew base solution worked for me
Install these packages
$brew install brew install mcrypt php54-mcrypt
Copy default php.ini.default to php.ini
$sudo cp /private/etc/php.ini.default /private/etc/php.ini
Add this line to php.ini file extension section - please verify extension path with install location in your machine
extension="/usr/local/Cellar/php54-mcrypt/5.3.26/mcrypt.so"
Restart your apache server
$apache restart
This is what I did:
$ wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
$ tar xzvf libmcrypt-2.5.8.tar.gz
$ ./configure
$ make
$ sudo make install
$ brew install autoconf
$ wget file:///Users/rmatikolai/Downloads/php-5.4.24.tar.bz2
$ tar xjvf php-5.4.24.tar.bz2
$ cd php-5.4.24/ext/mcrypt
$ phpize
$ ./configure # this is the step which fails without the above dependencies
$ make
$ make test
$ sudo make install
$ sudo cp /private/etc/php.ini.default /private/etc/php.ini
$ sudo vi /private/etc/php.ini
Next, you need to add the line:
extension=mcrypt.so
$ sudo apachectl restart
mycrypt.o and mcrypt_filter.o are in the ext/.libs of your php downloaded directory. Just copy the files to ext/mcrypt, then run make && make install again.
With recent changes in brew (deprecation of homebrew/php) you now install php with mcrypt with the following.
brew install php#5.6 -with-mcrypt=mcrypt
You may have to uninstall previous installs of php
So after running brew install mcrypt php, I had to install php-mcrypt via pecl:
pecl install mcrypt-1.0.1
At the time of writing, mcrypt does not have a stable pecl release, 1.0.1 being the current release for php 7.2 and 7.3, and brew install php will install php 7.2.
sudo apt-get install php5-mcrypt
ln -s /etc/php5/mods-available/mcrypt.ini /etc/php5/fpm/conf.d/mcrypt.ini
service php5-fpm restart
service nginx restart

can't find mcrypt => Call to undefined function Laravel\mcrypt_create_iv()

Trying to set up Laravel and keep getting hit with this error. I installed mcrypt through brew and it is located in /usr/local/Cellar. Any thoughts? .. It's not showing up in terminal command php -m either, if that matters. I'm running Mountaion Lion with macs native web server.
Ubuntu or any Debian based Linux users can install the required package with apt-get:
sudo apt-get install php5-mcrypt
Remember to restart the web server afterwards:
sudo service apache2 restart
If it still doesn't work, try to link the configuration file to the appropriate configuration folder for the web server. Thanks to dave1010 for this hint in the comments.
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/apache2/conf.d/ # for Apache
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/cli/conf.d/ # for CLI
And again, restart the web server:
sudo service apache2 restart
Perhaps, if not working yet, you need also the line showed by #RahulPrasad, with php5enmod mcrypt.
You need to enable it in your php.ini file as well and probably restart Apache.
In php.ini you will find ;mcrypt.so and remove the ; from it.
Or, if it's not in there, just add mcrypt.so somewhere.
Also the salt option has been deprecated as of PHP 7.0.0. It is now preferred to simply use the salt that is generated by default.
Try sudo php5enmod mcrypt && sudo service apache2 restart
You've installed mcrypt when you actually wanted the php56-mcrypt php module.
You stated in your question that you can see mcrypt installed in /usr/local/Cellar and that you're using OSX. So, the easiest way to install the mcrypt PHP module on OSX using Homebrew is:
// assuming you have php56
brew install php56-mcrypt
If homebrew can't find the correct package you may need to tap the PHP repositories found on GitHub:
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
Now when you issue the command brew search mcrypt, you should see something like:
libtomcrypt mcrypt php53-mcrypt php54-mcrypt php55-mcrypt php56-mcrypt
Several other posters have mentioned the need to edit your php.ini file. This will be unnecessary as homebrew will take care of activating the module for you. It places the configuration file at /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini
You don't have the mcrypt PHP extension installed.
For a Mac, I followed these instructions:
mcrypt on Mac 10.7 or 10.8.
They look like a lot, but it's not, it's very easy to follow in it works!
You may have installed mycrypt but not have the php_mcrypt module installed / enabled.
Just a note for people who have recently upgraded to PHP 7 - The MCRYPT library has been deprecated. If you upgraded to PHP 7 and are now seeing this error, that is why. You should switch to an alternative library, some alternatives are mentioned in this thread.
Go to the CLI folder in your php instalation, and find php.ini in there and enable mcrypt. Terminal sometimes uses another php.ini, which is usually in the CLI folder.
I installed php and mcrypt with Homebrew, but I still experienced this error after doing brew update a few times. I think my setup has just gotten a bit borked over time.
It turns out my php was being configured from /private/etc/php.ini, not /usr/local/etc/php/5.4/php.ini as Homebrew recommends. Mcrypt is not even being included from /usr/local/etc/php/5.4/ext-mcrypt.ini which doesn't make a lot of sense considering php -i produces this for me:
Configuration File (php.ini) Path => /usr/local/etc/php/5.4
Loaded Configuration File => /usr/local/etc/php/5.4/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/5.4/conf.d
Additional .ini files parsed => /usr/local/etc/php/5.4/conf.d/ext-mcrypt.ini
My solution:
Edit /private/etc/php.ini as a superuser
Add extension="/usr/local/Cellar/php54-mcrypt/5.4.28/mcrypt.so" and save
Restart Apache with sudo apachectl restart
This is what finally worked for me:
brew reinstall --with-homebrew-curl --with-httpd php56
brew reinstall --build-from-source php56-mcrypt
I also had to do sudo chmod 777 /usr/local/etc/php/5.6/conf.d because I got errors when the second brew reinstall tried to add the ext-mcrypt.ini to that directory.

Categories