Two versions of PHP - Mountain Lion - macos

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.

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

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.

OSX Apache using wrong version of PHP

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

Installing php-module using port on osx lion

I am trying install php5-intl on my osx lion.
I did install also Xcode.
When I run the command to install the module I get the following message.
> sudo port install php5-intl
---> Computing dependencies for php5-intl
---> Cleaning php5-intl
> locate *intl*|grep so\$
/opt/local/lib/php/extensions/no-debug-non-zts-20090626/intl.so
> sudo apachectl restart
My question is:
Is the php5-intl module installed and ready to be used in my apache?
P.S.:
If I look to my phpinfo() I don't see any reference to php-intl. Is it normal?
If I run
> php -m | grep intl
PHP Warning: Module 'intl' already loaded in Unknown on line 0
intl
Then If I try to use it in Synfony2 I get the following error:
The Symfony\Component\Locale\Stub\StubLocale::getDisplayLanguage() is not implemented.
Please install the 'intl' extension for full localisation capabilities
If I look to my phpinfo, no trace of php5-intl.
If it's not listed in phpinfo() (or php -m on the command line) then no, the module isn't enabled.
If I were you I'd get this working on the command line first, since if I remember right Port uses it's own version of PHP (and Apache?), which could cause confusion.
You'll need to enable the module with extension=php5-intl.so in your php.ini file, after adding that php -m should include intl, and you know the extension is working on the command line.
Edit:
PHP Warning: Module 'intl' already loaded in Unknown on line 0
This sounds like you maybe have the module enabled twice, though I don't think that's necessarily your problem.
Try running a simple command line script that calls an intl function, it sounds to me like it's enabled for the command line but not for apache.

Trouble with PHPUnit on Zend Server CE - MacOSX

I've installed Zend Server CE on my MacOS Lion, and everything is running smooth except from PHPUnit.
My installation of PHPUnit was made from the PERL that comes with Zend Server CE.
Here is the output from when I run phpunit through the console:
Failed loading ”/usr/local/zend/lib/php_extensions/xdebug.so”: dlopen(”/usr/local/zend/lib/php_extensions/xdebug.so”, 9): image not found
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/zend/lib/php_extensions/mcrypt.so' - dlopen(/usr/local/zend/lib/php_extensions/mcrypt.so, 9): Library not loaded: /usr/lib/libltdl.3.dylib
Referenced from: /usr/local/zend/lib/php_extensions/mcrypt.so
Reason: image not found in Unknown on line 0
PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0
PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::getInstance() in /usr/local/bin/phpunit on line 39
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/phpunit:0
Does anybody know what the problem or problems could be?
Thanks and regards!
Ok, this is my first answer. So go easy on me.
Tonight I had the very same issues with Zend Server CE on OSX Lion. In order to solve them, you'll have to install xcode as the unix development tools are required.
Let's get started, you have two issues: xdebug.so and libltdl.3.dylib
First xdebug.so is not found, to install it you should run the following from the command line:
sudo su -
It will ask you for you password (if you don't have one just press the enter key). Then:
export CFLAGS="-arch i386 $CFLAGS"
export CCFLAGS="-arch i386 $CCFLAGS"
export CXXFLAGS="-arch i386 $CXXFLAGS"
export LDFLAGS="-arch i386 $LDFLAGS"
/usr/local/zend/bin/pear config-set php_ini /usr/local/zend/etc/php.ini
/usr/local/zend/bin/pecl install xdebug
The first four lines, force the compiler to generate a 32 bit binary, as Zend Server is a 32 bit binary and OSX Lion is a 64 bit operating system.
Alright, now you should have xdebug.so installed on */usr/local/zend/lib/php_extensions*, just make sure that your /usr/local/zend/etc/php.ini file loads xdebug with the following line after all other extensions and before the [zend] section:
zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so
Here's the fragment from my php.ini:
...
;extension=odbc.so
;extension=imagick.so
zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so
[zend]
zend_extension=/usr/local/zend/lib/ZendExtensionManager.so
...
If it doesn't please add it manually, then check if your php.ini file contains the following line and delete it as xdebug must me loaded as a Zend extension.
extension=xdebug.so
Second, as soon as you install xcode, libltdl.dylib will be available in /usr/lib, so you can create a symbolic link to it with the following command:
sudo ln -s /usr/lib/libltdl.dylib /usr/lib/libltdl.3.dylib
Next time you run phpunit everything should go smoothly (haven't tested any mcrypt functions though).
I just ran into the problem with the mcrypt, when I tried to start the phpunit.
The warning does not appear, if you run phpunit with sudo :)
sudo ./phpunit --version
PHPUnit 3.6.6 by Sebastian Bergmann.

Resources