Installing multiple PHP versions on Ubuntu Server - php

Initial Situation:
I have an Ubuntu 12.04 Server hosting 3 Websites (with Apache 2.2.22)
How can I install a different PHP version for only one of the Websites?
(The other 2 should remain as they are)
Current PHP Version: PHP 5.3.10
Desired PHP Version: PHP 5.6.16
What i have done/understood until now:
I have already tried out PHPBrew:
http://phpbrew.github.io/phpbrew/
I managed to install PHP 5.6.16 for the command line (with PHPBrew) but the Apache still uses PHP 5.3.10.
I understood that i should end up with an *.so file which i need to place in /etc/apache2/httpd.conf file. (this file is empty at the moment)
(via LoadModule...)
But: I don't have any *.so files.
I installed PHPBrew like this:
phpbrew install 5.6.16 +default +mysql +mcrypt
I think I should have added +apxs2=/usr/bin/apxs2 but if I do this i get the error "Exception: apxs binary is not executable: /usr/bin/apxs2".
How can i fix this?
Or is there a better way to run different PHP versions on one Server?
What is the best way?

Double check the .so files, they should be in `/usr/lib/apache2/modules/``
Then you should edit your /etc/apache2/mods-enabled/php5.load and specify the .so file that corresponds to your installation, in your case:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.6.16.so
An alternative solution for running multiple PHP versions on the same box is using Docker, see my answer in another thread: Multiple PHP versions on the same box
Note that with this solution different PHP versions will be available on different ports.

Related

How to change PHP version in XAMPP?

I've downloaded XAMPP ver. 7.2.10 which supposedly has the PHP ver. 7.2.10.
But when I run a composer update on cmd, it says that my PHP version is 7.0.21. I need to have a PHP 7.1.3 in order to run my frameworks.
Is there a way to change the PHP version without installing a new XAMPP? Because I already have the latest version installed and the PHP versions stated in the XAMPP and CMD are different.
Change you Xampserver you can't change php version inside xampserver
you can download from below link
Download xampserver
You can also do it in another way.
Download your desired version of php here and then go to XAMPP folder (most likely C:\xampp).
There, extract the downloaded php file and name it php (paste it in C:\xampp) Then, copy all files from your old php folder and paste it in the new php folder.
Do not replace any files, just copy missing files and if your php version is less than 7, don't forget to edit your httpd-xampp.conf file.
Restart your Apache server and, hopefully, it will work.
Maybe you are using another version of php, check if you have another version installed and see environment variables and path there should tell you the php path used, or maybe you have an apache running, to stop it enter services and stop apache24.
Your Bash/Terminal runs in it's own PHP world.
You can upgrade it with apt-get on XAMPP VM
see here:
https://die-schwarzwald-werbeagentur.zazudesign.de/internet-programmierung/a-working-typo3-9-4-x-composer-installation-on-xampp-osx-php7-2-imagemagick-mariadb.html
After upgrading PHP to 7.2 composer will work. For some reason composer uses the bash PHP-version and not the Apache2-PHP-Version

Lampp PHP doesn't work like environment in PHP

I'm using LAMPP (XAMPP on Linux) to operate my server.
LAMPP has its own php binaries /opt/lampp/bin/php, which is different from the php version I have in /usr/bin/php. That is, when I've installed extensions using the command line, they've been successfully added to the original /usr/bin/php, but the php version which is associated with Lampp didn't recognized these extensions.
The question is, how to get these extensions into work with Lampp?
I can change my original php to the one in Lampp (so I can normally install extensions) or I can change the PHP associated with Lampp to be the original one but I don't know the way to do this.

Different versions of PHP on OS X 10.9

I am trying to get the Symphony framework installed on my laptop (running OS X 10.9 Mavericks), so far I can't even get it started because of error messages
The first thing not being an error but it seems that I have multiple versions of PHP running and I would like to remove everything except the latest version (5.5.12). Can someone please tell me how I can achieve this?
I compiled and built the newest version of PHP from source and installed it (which should replace the original version), however I am seeing 2 different versions when using phpinfo() from a webpage and php -v from the command line:
phpinfo(): PHP Version 5.4.24
php -v: PHP 5.5.12 (cli) (built: May 29 2014 11:21:46)
I compiled and built the newest version of PHP from source and
installed it (which should replace the original version), however I am
seeing 2 different versions when using phpinfo() from a webpage and
php -v from the command line:
PHP from the command line is 100% different from PHP as loaded via an Apache module. So wiping out the old version won’t solve this issue & might cause other issues. Don’t ever attempt that. Instead just install the version of PHP you want to run and edit your Apache config to load the proper libphp5.so PHP 5.5.12 module.
In my Mac OS X 10.9.3 install the default system Apache config is located here:
/private/etc/apache2/httpd.conf
And in there is a commented out line—might be uncommented in yours—that reads:
#LoadModule php5_module libexec/apache2/libphp5.so
So you need to just make sure you create a similar line to the libphp5.so PHP 5.5.12 module like so:
LoadModule php5_module /path/to/the/new/version/of/php/libphp5.so
Making sure to change that /path/to/the/new/version/of/php/ to match your actual libphp5.so PHP 5.5.12 module.
Then restart the Apache web service & all should be good.
Remember this: When it comes to Unix/Linux tools & configurations, you never have to forcefully uninstall components to solve issues like this. It’s all about getting the configuration straight.
All that said, you might make your live easier by running MAMP instead of compiling from source like this. MAMP is a self-contained LAMP stack for MAMP that has the latest versions of PHP installed. And since it runs as an application, none of the issues you are facing compiling from source will ever happen when you use MAMP.
Thanks for your help. I realized that I had installed so many things with MacPorts (programming my Arduino among other things) that I just decided to wipe my drive and reinstall OS X 10.9
Then I just followed this tutorial and finally got everything working properly
http://dab.io/posts/install-symfony-on-os-x-mavericks.html

How to install pthreads on a phpfarm php installation

Documenting my struggles to help others and hopefully get some feedback on how I could have done it better.
The command pecl install pthreads fails due to the php installed on my ubuntu 13.04 box not having zts configured.
Options:
1) The ubuntu respository does not have a php package with zts enabled. As of this post, ubuntu only has php 5.4.9 in it's repository (Released: 22 Nov 2012). It is possible to compile a php version from source - which I eventually did (see below), but..
2) I .. ALSO .. wanted to use phpfarm for the ability to run different versions of PHP on my local setup. On github, there is Christian Weiske's original contribution here (phpfarm) and a fork that he has contributed to, by François Poirotte - also called phpfarm. Francois' fork has a few more options to configure ('post-install customization') but I was not able to make that work with a PECL extension. I'm curious to know if misunderstood how to do that, because it looks to me that it just simply does not take PECL commands.
3). Prior to recompiling php from source, I loaded phpfarm (tried both versions), enabled php-fpm (FastCGI) and was able to get my apache2 server to use a phpfarm version (5.5.10) which showed up in a phpinfo() output. But the php-cli always showed the original php version (5.4.9) in the cli (run: php -v). Running (run: php -i | grep php.ini) showed /etc/php5/cli but I had previously removed php5 and aptitude show php5 returned a state of 'not installed.' I even renamed the /etc/php5 directory to see if I could force the system to use the phpfarm php version. Obviously, this is incorrect thinking and I went on to simply compile php 5.6 from source. But, is there something more to do to get a phpfarm php to be used in the cli? I read that the cli loads it's configuration file on a per command basis, unlike the apache2. If I could have run the 5.5.10 version (configured with zts) then I could have then done pecl install pthreads and then re-complied the phpfarm 5.5.10 version with pthreads enabled. Although it appears I will be able to run various versions of php in the apache server, will I ever be able to switch-phpfarm to another version and see it working in the php-cli? Also, I was uncertain on where I could have loaded a pthreads file for the phpfarm compile process to find and use it; could I have done it that way?
4) This stackoverflow post, essentially posted by Joe Watkins - the developer of pThreads is a perfect how-to on getting pThreads installed on a Ubuntu system that has had php configured with zts (Zend Thread Safety). (Thanks Joe!)
A nice tutorial on using phpfarm configured with fast-cgi and the apache server to help run websites under different php configurations.
So what gives with php, php-cli and the phpfarm?
I'm not sure about phpfarm, but do know of another solution ...
Multi
A tool for maintaining multiple installations of PHP in multiple configurations
https://github.com/datingvip/multi
This is a bit more user orientated, will allow you to build many configurations and versions of php, any tagged release of php, and any patched version from any fork of php-src.
In addition, because I wrote it, it will install pthreads for you.
git clone https://github.com/datingvip/multi
cd multi
VERSION=5.5.10 DBG=no-debug ZTS=zts ./php.multi
The above commands will yield an installation of PHP (in one suitable configuration, of one version) in /opt/php.
Look at php.defaults for configuration options and adjust before building
Should configuration fail on, for example, something related to a library like libxml2, it will usually be the case that
sudo apt-get install library-dev
Where library is replaced with the name of the library holding up the build, will fix the problem for you. If it does not, a quick google should get you going again.
Once the build is complete
source /path/to/multi/php.env 5.5.10
Note: multi will always install pthreads for any zts version automatically
I hope that gets you somewhere ...

CentOS - Mongo class not found in PHP

I need the MongoDB PHP driver on my CentOS 5.4 machine. My PHP version is 5.1.6. I downloaded the RPM and installed it. That created several files in /usr/bin directory. I copied
/usr/bin/mongo
to
/usr/lib/php/modules
which was what extension_dir showed on doing phpinfo();.
I also added
extension=mongo.so
in /etc/php.ini.
However on executing my PHP script, i still get
Mongo class not found.
What's going wrong here ?
Also, my phpinfo() shows PHP version 5.1.6 whereas running PHP from command line shows 5.3.3. Could anything be wrong with that ?
Thanks in advance.
You're saying your webserver and command line PHP report different versions. These are going to be installed in different locations, and their extensions are API incompatible with each other.
When you installed the php_mongo extension, it may have used the command line php to determine the directory to install the extension to.
Make sure you have the correct php_mongo for the php version of your webserver, and it is in the correct extensions directory. (get the directory from the php.ini returned by phpinfo())
I hope you realise PHP 5.1 is also many years out of date. Unless you have a specific reason to use a version that old, you should also look at upgrading to a more recent version.
Edit:
Just read your comment "I must also mention that /usr/bin/mongo is a binary executable file but its not having a .so extension. Im copying it as is to /usr/lib/php/modules"
No no no! :)
This is the mongo command line client. This is not the PHP extension!
You can run a find /* -name "mongo.so" to see where the installer put the file, this will probably also give you an indication of which version of PHP it was installed for.
It looks as though you are confusing the RPM-packages for the MongoDB server with the requirements to install the MongoDB PHP driver. The PHP driver provides access to the server from your PHP applications, and does not install any command line tools.
restart httpd !
yum service httpd restart

Categories