OSX Apache using wrong version of PHP - macos

I followed a guide which used home-brew to install the lastest version of php (5.4.8) on OSX Mountain Lion.
I then followed a guide which showed me how to setup and use the pre-installed apache on OSX.
However when I try running up a base Symfony 2 project I get a bunch of errors relating to missing date.timezone in the php.ini.
However I have this correctly setup the php.ini but doing a quick phpinfo() in the Symfony project shows that its using the old preinstalled version of php (5.3) rather than the new one.
In terminal if I type which php & php -v, It shows the correct new version is being used.
But the phpinfo() shows

Did you follow all the instructions provided in the Caveats?
Run brew info php54 to see them again.
Especially the line:
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php5_module /usr/local/Cellar/php54/5.4.8/libexec/apache2/libphp5.so

Apache is not aware of the homebrew version of PHP (i.e. /usr/bin/php). You see it on the command line because you've likely modified your PATH (i.e. /usr/local/bin/php).
You can modify this in your httpd.conf file.
I am not a fan of homebrew or other package libraries. Primarily because Mac OS X is built atop Unix. Furthermore, all but MySQL are installed natively. Here's an article on installing Apache, MySQL, and PHP on Mac OS X.
Disclaimer: I wrote that article.

Today I have same issue for updating php 7.2 to 7.3 as requirement of Laravel 6. Here is my solution.
Open your httpd.conf file in "/etc/apache2/http.conf"
Search (Ctrl + w) for "LoadModule php"
Uncomment that row
Restart your apache with "sudo apachectl restart"
Then, your php version in local web server (apache2) will be updated

Related

MacOS MAMP and php 8.1

I am trying to get MAMP runing with PHP 8.1 but what I see as latest version for MacOS is 8.0.8, is there a way to run 8.1 ?
I have gone thru many tutorials in which they explain on how to switch from one of the installed versions but I can't seem to find a way to install additional PHP versions.
following up relating to #Quink's answer
8.1.0 is available in the dropdown (not in the picture because I already downloaded it)
then quit and restart mamp
then you can find the folder by opening phpinfo page and seeing the path
not sure if this is needed, but at this point I copied the folder and pasted it in the main MAMP/conf directory where all the other PHP versions are
I was looking for this myself. I found out that the easiest way to do this is to start your trial version of the pro. There you have the option to download/ install the php8.1 version. After this I switched back to the basic MAMP and everything is working properly
Install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
get latest php version i.e. 8.1 for now
brew install php
Verify php
which php
php -version
now go to to /usr/loca/Cellar/php, copy php version folder you want i.e. 8.1 for now
go to Application/MAMP/bin/php and paste this folder
rename your folder like others i.e. "8.1.10_1" to "php8.1.10" in my case
at this point you can quite the mamp and reopen it and you will see php8.1 version in your mamp php version's dropdown
now go to your terminal and
/Applications/MAMP/Library/bin/apachectl start
and you will see an error i.e. Syntax error on line 160 of /Applications/MAMP/conf/apache/httpd.conf... in my case
to resolve this go to /usr/local/lib/httpd/ and copy the "modules" folder
now past it in /Applications/MAMP/bin/php/php8.1.10/
YOUR MAMP IS ALL SET BUT if you try to reach phpadmin you will see an error, for that
go to /Applications/MAMP/bin/phpMyAdmin5 and edit config.inc.php.
Locate this text: $cfg['Servers'][$i]['host'] = 'localhost' and change it to ``$cfg['Servers'][$i]['host'] = '127.0.0.1'`
Restart your server.
HOPE THIS HELP YOU
This YouTube Video answers this perfectly, and then follow this SO answer
You might also want to change your local connection host from localhost to 127.0.0.1
PS: Copy /usr/local/Cellar/php/8.<version_number>/lib/httpd/modules/libphp.so to /Applications/MAMP/bin/php/php8.<version_number>/modules/libphp.so

Issue in installing Mcrypt extension in mac OS 10.13

I am trying to run codeigniter project on mac but it is showing "The Encrypt library requires the Mcrypt extension." error.I have tried many solutions to install Mcrypt extension but every time i am getting errors.I have tried to install it using homebrew using brew install php5-mcrypt command but getting No available formula with the name "php5-mcrypt" error everytime.Issue is i am new to mac so now I am stuck because i don't know how to solve this issue. Can anyone help me and give me guidance that exactly what should i do to install Mcrypt extension? I am using PHP version 7.2.4 and macOS 10.13: High Sierra (Lobo).
I would recommend you try MacPorts. It's like Homebrew but I've had better luck recently. There is a port for php72-mcrypt if that's the one you are after. There are many others available as well. The MacPorts home page, found here gives instructions for loading MacPorts and also has a list of available ports.
mcrypt has been removed from PHP core since 7.2. To install mcrypt in PHP 7.2, you have to install via PCEL. The command is:
sudo pecl install mcrypt-1.0.1
You might want to read the official installation documentation as well.
For mac users install MAMP pro and select a php version that has mcrypt.
That is to say any version before php 7.2 .
Start the servers and voila you’re good to go.

The MongoDB PECL extension has not been installed or enabled in MAC YOSEMITE

I am trying to install mongo on mac os X yosemite, i have already installed the current version of PECL mongo db ad mongo extension files mongo.so, but still this error The MongoDB PECL extension has not been installed or enabled comes when i open any kind of localhost page, please help i have been stuck in this situation since a week, also i have tried other versions of mongo too but the error appears to be the same.
Okay i finally found the solution.
I used homebrew to install pecl extension.
then actually i was using
sudo vi php.ini
command to edit and insert the mongo.so extension
but later i downloaded sublime text edited the note and inserted the extension manually and restarted xampp

Install fpm separately for PHP 5.5.8

I'm doing a manual LAMP setup to learn more about working with the terminal and network configuration, and upon installing the latest version of PHP (5.5.8) I realised that I missed installing fpm. I've been trying to install the extension by itself but I'm not sure how to.
Running php-fpm -v tells me I have version 5.4.17, should fpm's version be the same as PHP in order to work together?
If you are using the manual configure option, ensure you have set the --prefix=/path/to/php-5.5.8 and --enable-fpm. And you can run /path/to/php-5.5.8/bin/php after installation.

Two versions of PHP - Mountain Lion

I have somehow got 2 versions of php installed on my machine (Mac OSx 10.8.3 Mountain Lion). The locations of the 2 versions are -
/opt/local/bin (version 5.3.26)
/usr/bin (version 5.3.14)
Right now, 'php -v' in the terminal returns, 5.3.26 but a simple php test page with the following code
phpinfo();
return 5.3.15.
Because of this mix-up i cant get php to load the mongodb extension. I'd want to work with version 5.3.26.
How do i get Apache to load this version of php ?
Your Apache is including libphp5.so of the wrong/the other installation.
Option 1:
See if you can find a libphp5.so file for your other PHP installation and point the Apache config to it (just put the whole path in the LoadModule line and restart Apache). If you cannot find such a file, the Apache module wasn't compiled for that PHP version. Compiling that may be a bit complicated, so in that case:
Option 2:
Figure out which PHP you're executing on the command line using which php and then just use the other one using the full path, e.g. instead of $ php ... use $ /usr/bin/php .... Note that you may still have different PHP configuration files for Apache and the CLI.

Resources