An "issue" after ppa:ondrej/php5 deprecation - php

Today I was upgrading PHP 5.5 on my LEMP stack to version 5.5.35. After upgrading I received an on-screen message that the repo ppa:ondrej/php5 is deprecated and if I want to continue receiving php updates I should move onto ppa:ondrej/php which now includes PHP 5.5, PHP 5.6 and PHP 7.0 in one place. Previously these versions were in different repos.
I followed Ondřej's advice and I run:
sudo add-apt-repository ppa:ondrej/php
And then:
sudo apt-get update
sudo apt-get upgrade --show-upgraded
All went fine, except that two packages were held back: php-pear and pkg-php-tools. That of course happens from time to time when package dependencies change so I run:
sudo apt-get install php-pear pkg-php-tools
Then, I got a message that additionaly the following packages will be installed:
php-cli php-common php-xml php7.0-cli php7.0-common php7.0-json php7.0-opcache php7.0-readline php7.0-xml
Immediately I felt that something is wrong here. Why the hell I need PHP 7.0 packages when I'm running PHP 5.5? However I went with option YES and apparently everything went fine. The server is running, no errors or confilcts that I'm aware of. Then I was curious and I checked what version of PHP am I running?
php -v
The output was:
PHP 7.0.6-1+donate.sury.org~trusty...
What the hell happened here? How did I ended up installing PHP 7.0 and why the server/site isn't crashing? Since I use nginx with php-fpm, by examining the nginx.conf I can clearly see that nginx is pointing to php5-fpm.sock so I definitely run php5-fpm here. Plus the site is up, and there are no PHP errors in the log.
I also went and I've uploaded a phpinfo file. The file shows I'm using PHP 5.5.35. So there are two conflicting messages where command via ssh shows that the PHP version is 7.0.6, while the phpinfo file shows that the server is using PHP 5.5.35.
So I run:
sudo apt-get remove php7.0-common
All previously added php7.0 packages were removed and also those two that were initially being held back.
Now, after checking the PHP version via SSH it showed correctly 5.5.35. While all this was happening the server had no trouble whatsoever. The status at this moment is that I don't have php-pear and pkg-php-tools packages, but if I try to install them all those php7.0 packages will have to be installed too.
I've also examined /etc/php5 and /etc/php folders. In this second folder there is 7.0 folder where cli and mods-available folders with mods inside reside.
Can someone explain to me what is happening here and what should I do? Are php5 and php7.0 simultaneously running on the server? Do I need those two packages that were held back in LEMP + Wordpress stack?

php-pear and pkg-php-tools must depend on PHP CLI for default PHP version and that's PHP 7.0. Installing php-cli pulls php7.0-cli that will install /usr/bin/php7.0 and registers it as alternative with highest (70) priority to provide /usr/bin/php.
Installing PHP CLI binary is mostly harmless unless you need to run PHP scripts locally using command line. I could recommend two approaches:
Rewriting those scripts to specify required version, e.g. changing php <script> to php5.6 <script>, or
Use update-alternatives to switch /usr/bin/php to your desired PHP version: a) switch to specific version update-alternatives --set php /usr/bin/php5.6 or b) update-alternatives --config php configure the version by hand
More thorough version of the migration guide is located in DEB.SURY.ORG Wiki.
To use the new PHP FPM packages, you need to install:
sudo apt-get install php5.5-fpm # for PHP 5.5
sudo apt-get install php5.6-fpm # for PHP 5.6
sudo apt-get install php7.0-fpm # for PHP 7.0
and adjust the socket accordingly, look into default FPM configuration:
sudo editor /etc/php/X.Y/fpm/pool.d/www.conf
for the socket location (it's /run/php/phpX.Y-fpm.sock by default).

Related

how to upgrade from php 7.0 to php 7.3 on Debian 9.1

I have a Debian 9.1 droplet on DigitalOcean. 1GB Memory, 30GB Disk.
I've previously installed php 7.0 using
apt install php php-fpm
I also ran the following commands to install php modules:
apt-get install php-mysql
apt-get install php-curl
apt-get install php-zip
apt-get install php-apcu
apt-get install php-xml
How do I now upgrade from 7.0 to 7.3?
Just to give you an idea of how you can do it:
Basically, you need to follow two steps:
Install the 7.3 version as you did for 7.0 (you can pass the version number to install the exact version number)
You need to configure your PHP CLI to use the new version 7.3 instead of 7.0.
The above steps can be done for every version.
Here is documentation of how you can do it in case of migration from 7 to 8.
NOTE: The documentation will help you to install a version of PHP and configure CLI so you need to make sure to do the updates as per 7.3.
sudo-apt update
sudo apt-get install php-fpm
This will go try to update it if see you already have php-fpm...
Your repository should be updated to understand there is new version of php that is available for download
you can also remove & purge it and try to download it again...
but also consider some services needs to be updated and set to use last version of php that is currently installed...
Like Nginx ,in that you should update for .conf file to read php 7.3 or any installed versions
you can also check how many versions php do you have by going to directory by this command cd /etc/php and do ls

"Gitpod" Downgrade default PHP v7.4.3 to 7.1.3 or 7.2

The error I'm facing is on Gitpod with PHP version, so the question is, how can I delete PHP completely from the workspace or replace it? Basically, I want to downgrade it.
I want to replace PHP with an older version. Unfortunately, I’m not able to get rid of the default PHP version 7.4 of the MySQL workspace.
I tried nearly every style of removing it in my .gitpod.Dockerfile file.
I activated the Feature Preview to have sudo support and I uninstalled every PHP version via gitpod dockerfile and ran
sudo apt-get purge ‘php*’
in the command line. It just says that no PHP is installed, but
whereis php
still gives me the output.
php -v
always gives me PHP v7.4
To install another php version is possible (e.g. with brew) but without removing the old one, I don’t know how I could use the new one.
Could someone please tell me, how can I downgrade this PHP version in "GITPOD" by replacing it or some other way?
Edit:
this was the code I was trying to run:
FROM gitpod/workspace-mysql
USER root
RUN sudo add-apt-repository ppa:ondrej/php
RUN sudo apt-get -y update
RUN sudo apt-get -y install php7.2
RUN sudo update-alternatives --set php /usr/bin/php7.2
RUN sudo a2dismod php7.4 RUN
sudo systemctl restart apache2
USER gitpod
Thanks in advance.
Best Regards
The problem is the install command. because of the script that runs in the background.
So the solution is running the following command instead of running apt-get install
install-packages php7.2
details of the answer could be found in the following thread:
Downgrade default PHP v7.4.3 to 7.1.3 or 7.2

`phpize' failed, while installing Imagick [duplicate]

I have been meaning to install ffmpeg as an extension to my PHP setup. So before I can install it, I need to phpize it. I installed php5-dev by sudo apt-get install php5-dev. But now when I run phpize I get the following error :
phpize
Cannot find config.m4.
Make sure that you run '/usr/bin/phpize' in the top level source directory of the module
The location of my php.ini is /usr/local/zend/etc/php.ini
From another online resource I tried this
sudo apt-get install autoconf automake libtool m4
But all of them are already installed.
Locate config.m4 didn't return anything.
Any pointers here how I can get phpize and thus, ffmpeg up and running?
For recent versions of Debian/Ubuntu (Debian 9+ or Ubuntu 16.04+) install the php-dev dependency package, which will automatically install the correct version of php{x}-dev for your distribution:
sudo apt install php-dev
Older versions of Debian/Ubuntu:
For PHP 5, it's in the php5-dev package.
sudo apt-get install php5-dev
For PHP 7.x (from rahilwazir comment):
sudo apt-get install php7.x-dev
RHEL/CentOS/yum
yum install php-devel # see comments
For PHP7 Users
7.1
sudo apt install php7.1-dev
7.2
sudo apt install php7.2-dev
7.3
sudo apt install php7.3-dev
7.4
sudo apt install php7.4-dev
If not sure about your PHP version, simply run command php -v
Ohk.. I got it running by typing /usr/bin/phpize instead of only phpize.
Under Redhat Enterprise / CentOS, use yum to install the php-devel module:
yum install php-devel
For PHP 7, you need:
yum install php70-php-devel
Step - 1: If you are unsure about the php version installed,
then first run the following command in terminal
php -v
Output: the above command will output the php version installed on your machine, mine is 7.2
PHP 7.2.3-1ubuntu1 (cli) (built: Mar 14 2018 22:03:58) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.3-1ubuntu1, Copyright (c) 1999-2018, by Zend Technologies
Step 2: Then to install phpize run the following command, Since my php version is 7.2.3. i will replace it with 7.2, so the command will be,
sudo apt-get install php7.2-dev
Step 3: Done!
Alternate method(Optional):
To automatically install the phpize version based on the php version installed on your machine run the following command.
sudo apt-get install php-dev
This command will automatically detect the appropriate version of php installed and will install the matching phpize for the same.
Hmm... actually i dont know how this solved it? But the following steps solved it for me:
find / -name 'config.m4'
Now look if the config.m4 is anywhere in a folder of that stuff you want to phpize. Go to that folder and run phpize directly in there.
For ubuntu 14.04LTS with php 7, issue:
sudo apt-get install php-dev
Then install:
pecl install memcache
In Ubuntu 16.04, you can install phpize with the command
aptitude install php7.1-dev // for php 7.1
which is equivalent to
apt-get install php7.1-dev // for php 7.1
If you're having problems with phpize not found on CentOS7.x after you have installed the relevant devel tools for your version/s of PHP, this path finally worked for me:
For PHP 7.2.x
/opt/cpanel/ea-php72/root/usr/bin/phpize
For PHP 7.3.x
/opt/cpanel/ea-php73/root/usr/bin/phpize
For PHP 7.4.x
/opt/cpanel/ea-php74/root/usr/bin/phpize
Run this in your folder containing the downloaded PHP extension, for example in line 3 below:
Example based on installing the PHP v7.3.x Brotli Extension from https://github.com/kjdev/php-ext-brotli
git clone --recursive --depth=1 https://github.com/kjdev/php-ext-brotli.git
cd /php-ext-brotli
/opt/cpanel/ea-php73/root/usr/bin/phpize
./configure --with-php-config=/opt/cpanel/ea-php73/root/usr/bin/php-config
make
make test
Install from linux terminal
sudo apt-get install <php_version>-dev
Example :
sudo apt-get install php5-dev #For `php` version 5
sudo apt-get install php7.0-dev #For `php` version 7.0
Of course in PHP7.2
sudo apt-get install php7.2-dev
This might help someone on ubuntu. No promises.
sudo apt-get install libcurl3 php5-dev libcurl4-gnutls-dev libmagic-dev
sudo apt-get install php-http make
sudo pecl install pecl_http
And adding "extension=http.so" to php.ini (Normally located at /etc/php5/apache2/php.ini)
Then restart Apache (sudo service apache2 restart).
If in doubt, check your apache logs:
sudo su --
cd /var/log/apache2
tail -25 error.log
Is http.so starting or failing?
For instance, if you wanted to use the "phpize" command for PHP 5.6, you would use the full path:
Code:
/opt/cpanel/ea-php56/root/usr/bin/phpize
For ubuntu with Plesk installed run apt-get install plesk-php56-dev, for other versions just change XX in phpXX (without the dot)
Go to the downloaded folder and there you find config.m4. Open the terminal and run phpsize.
I had this exact problem on macOS in 2018.
For me, first running brew install php before sudo pecl install mongodb did the trick.
You didn't specify what operating system you're using, and 90% of the answers assume Ubuntu/Debian Linux because of the apt-get install autoconf automake libtool m4 command that you posted (and over half expect you to be running CPanel), so I'm giving you a slightly more generic solution which ought to work on any Un*x clone (including Microsoft's WSL!).
You will need at least a few prerequisites:
A working C/C++ compiler — GCC or clang being the most popular options these days.
A 'developer edition' of PHP, which some package managers call 'development headers'. In the case of aptitude, as shown on the other answers, you ought to be fine with just sudo apt install php-dev. Beware of the mentioned caveats: you might end up with a slightly more unstable version of PHP which might not be updated correctly with future versions.
These days (that's late 2021 for me!), for those running Ubuntu, and wishing to seriously tinker with PHP, the recommendation is to use Ondřej Surý's personal package archive for PHP. Ondřej keeps his PPA always up to date, sometimes within a few hours after release; he keeps up with the latest four Ubuntu distributions and all the currently supported PHP versions that haven't reached end-of-life status yet (sorry, PHP5 is considered completely obsolete and plagued with unpatched bugs and security issues, so it's not supported — for very good reasons!); and he provides a lot of PHP extensions, too. Sadly, ffmpeg-php is not one of them...
There is a good reason for the overall lack of support of ffmpeg-php. Allegedly, the original repository for that was hosted at Sourceforge but has been abandoned in 2007. The recommended package these days is PHP-FFMpeg which is constantly being updated, and ought to be easily installed using composer — get it before starting your compilation!
Alternatively, instead of relying on an external non-official PHP extension (albeit one that is both popular and updated regularly!), you ought to launch the ffmpeg binary using shell_exec(). This is the officially recommended approach, mostly because converting videos always takes a long time, and the authors of that recommendation suggest a simple architecture where the PHP script basically launches ffmpeg in the background, accepting batches of videos for processing. The page is a bit old, but the technique shown is sound.
I am using XAMPP on Linux mint and it is by default installed if your don't have
sudo apt-get install php7.0-dev
// or
sudo apt-get install php-dev
know more

Difficulty loading pecl stats module w/ php 5.6 fpm

Experiencing difficulty getting PECL stats module loaded in Vagrant dev environment.
Dev Env: Ubuntu 14.04, Nginx 1.4.6, PHP 5.6.24.
Production copy running successfully.
Prod Env: Ubuntu 14.04, Nginx 1.4.6, PHP 5.5.9.
We need to migrate the application to a new server. New server node is the same env setup as the Dev/Vagrant box listed above. Only environment change between current node & new node is PHP version.
PHP5.6-FPM service is running as expected in Vagrant. The application works as expected, until attempting to run any php stats methods, for example stats_standard_deviation().
PECL stats 1.0.5 has been installed & verified.
Confirmed the correct php.ini via phpinfo() prior to adding stats extension.
Confirmed the stats.so extension exists.
I've restarted services, restarted the Vagrant box. I've confirmed stats module is loaded in production via phpinfo() & am using the same method to confirm it is NOT loading in dev. Just can't seem the get the extension loaded.
Any help is greatly appreciated !
This was a two-part issue.
An incorrect PECL dependency was installed. php5-dev was the pkg installed, which directed the PECL installer to use PHP API 20121212
PECL config looks for standard PHP 5 install by default, v. 5.5.9. That needed to reflect the correct settings. Possibly using either pkg-config or autoconfig packages would rectify this hiccup by assisting PECL in the PHP detection process.
Solution
Clean out the PECL stats module, as well as the php dev package.
Set PECL config.
Then re-install correct versions.
# Clean out previous ver.
$ pecl uninstall stats-1.0.5
$ apt-get remove --purge php5-dev
# Install correct PECL dependency
$ apt-get install php5.6-dev
# Set PECL config to correct PHP install
$ pecl config-set php_bin /usr/bin/php5.6
$ pecl config-set php_ini /etc/php/5.6/fpm
# Re-install PECL package & restart PHP-FPM service
$ pecl install stats-1.0.5
$ service php5.6-fpm restart

How to install V8js on PHP5.5?

I want to install the v8js extension for PHP5.5 on Ubuntu 12.04 but can't make it working.
When I try to install the v8js extension version 0.2.0 (latest) with PECL, I have this message:
configure: error: libv8 must be version 3.24.6 or greater
ERROR: `/tmp/pear/temp/v8js/configure --with-v8js' failed
If I try to install an old version, I have a compilation error. This message is very similar to my issue: Install v8js for php on ubuntu
How can I fix this issue?
EDIT: I couldn't install it on Ubuntu 14.04 with PHP5.5, even with a PHP downgrade with PHPbrew to PHP 5.4. However, using Ubuntu 12.04 with PHP 5.4 works great. I didn't try the downgrade from PHP 5.5 to 5.4 on Ubuntu 12.04.
in case you can't find libv8-dev or libv8-dbg, you can find the correct version by run command
~$ apt-cache search libv8
libv8-3.14-dbg - V8 JavaScript engine - debugging symbols
libv8-3.14-dev - V8 JavaScript engine - development files for 3.14 branch
libv8-3.14.5 - V8 JavaScript engine - runtime library
libv8-dev - V8 JavaScript engine - development files for latest branch
then you can run
~$ sudo apt-get install libv8-3.14-dev libv8-3.14-dbg g++ cpp
then you can try to install v8js via pecl by running
~$ sudo pecl install v8js-0.2.0
if that command return error like this
configure: error: libv8 must be version 3.24.6 or greater
ERROR: `/tmp/pear/temp/v8js/configure --with-v8js' failed
you can try to install v8js-0.1.3 instead by running
~$ sudo pecl install v8js-0.1.3
then edit your php.ini to add v8js extension
~$ echo "extension=v8js.so" >> /etc/php5/cli/php.ini
Open your terminal/console
sudo apt-get install libv8-dev libv8-dbg g++ cpp
Make an update sudo apt-get update
Try sudo pecl install v8js-0.2.0 (or other version i.e.: sudo pecl install v8js-0.1.3)
Edit your php.ini (Check: Where is my php.ini file?) file by adding: extension=v8js.so.
Restart server
If it the extension still doesn't work, try to edit /etc/php5/conf.d/v8js.ini and add extension=v8js.so and restart server again.
Hope this helps.
These other answers work well and I used v8js-0.1.3 for the past 1.5 years but after needing to upgrade to PHP 7 I needed a better solution as v0.1.3 doesn't compile with PHP 7 (something to do with php_smart_str being renamed to php_smart_string).
After a couple hours of frustrating research and compiling libv8 myself, I didn't want to have to go through this whole process on every server I provisioned.
Anyway, I found this site which points you to a launchpad PPA site that provides a couple different ubuntu packages with the 5.1 and 5.2 libv8 libraries.
I ran these commands (please don't add repositories of 3rd party devs without understanding the risks).
sudo apt-add-repository ppa:pinepain/libv8-5.2
sudo apt-get update
sudo apt-get install libv8-5.2-dev
sudo pecl install v8js-1.1.0
(Thanks #JeyKeu for suggesting to add "apt-get update" to these commands)
I couldn't get v8js-1.3.0 or 1.2.0 to build, but 1.1.0 worked well. I checked the changelog and found that the latest updates are not necessary in my circumstance anyway.

Categories