Installing phpredis on Ubuntu 14.04 for PHP 7.1 - php

My php -v
PHP 7.1.15-1+ubuntu14.04.1+deb.sury.org+2 (cli) (built: Mar 6 2018
11:51:39) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine
v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
with Zend OPcache v7.1.15-1+ubuntu14.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies
I have tried both the pecl way
sudo pecl install redis
sudo service php7.1-fpm restart
And the manual way from https://github.com/phpredis/phpredis
phpize
./configure [--enable-redis-igbinary]
make && make install
I made sure to put
extension=/usr/lib/php/20170718/redis.so
into the php.ini file as shown when I run echo phpinfo();
e.g.
/etc/php/7.1/cli/php.ini
When I run the inbuilt web server I get
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php/20170718/redis.so' - /usr/lib/php/20170718/redis.so:
undefined symbol: zend_empty_string in Unknown on line 0
Strangely PHPStorm autocompletes the PHP Redis class, so
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379);
I can click into the Redis class and see it is the correct one.
I wonder if it is a version difference? Maybe because I am using 32-bit?
Another strange thing is, if I just put
extension=redis.so
in php.ini, it seems to be looking for an older build
PHP Startup: Unable to load dynamic library
'/usr/lib/php/20160303/redis.so' - /usr/lib/php/20160303/redis.so:
cannot open shared object file: No such file or directory in Unknown
on line 0
When I run
sudo apt-get install php-redis
it installs and means that no start up error shows, but the web page still shows a
Class 'Redis' not found
One other thing I notice is that in Apache, there is no error, and the class is found. But when I run php's inbuilt web server, the not found error shows up.

May you just need to install this using a ppa package like:
sudo apt-get install php7.1-redis

Ok so I noticed that phpinfo showed
PHP API 20160303
which means that the earlier error makes sense. The PHP version of the web server is 7.1, however, when running the phpredis phpize it shows the one for 7.2.
So I just made sure to remove php7.2-dev and re-install php7.1 via apt-get, then re-run the github repo steps above.

Related

Install xdebug on specific php version

I'm trying to install xdebug.
I've already seen some issues about it (like this one : Installing xdebug with PHP 5.5 ) but it seems outdated and not corresponding to my issue).
When I try
sudo pecl install xdebug
I'm getting the following error
WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update
downloading xdebug-2.8.0.tgz ...
Starting to download xdebug-2.8.0.tgz (238,122 bytes)
.................................................done: 238,122 bytes
69 source files, building
running: phpize
sh: 1: phpize: not found
ERROR: `phpize' failed
It seems that means phpize isn't installed in my php version
php -v
PHP 7.2.24-0ubuntu0.19.04.1 (cli) (built: Oct 24 2019 11:49:39) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.24-0ubuntu0.19.04.1, Copyright (c) 1999-2018, by Zend Technologies
So, some topics seems to tell me to change my php version to download a version with phpsize included. But I was more looking for a way to add phpsize to my current php version but I don't know how to do that.
Thanks for your assistance
If Ubuntu first you need install php dev version:
sudo apt install php7.x-dev
And then:
sudo pecl install xdebug
I had some problems with xdebug version too.
I had to install an specific version for php7.1 using PECL,
I don't really know if your question is already solved but let me share you this webpage, it's the compatibility graph to know wich version works with an specific php versions:
https://xdebug.org/docs/compat
As far as I know if you want to install the latest xdebug version you can use the repo, but if you need an old version you'll be forced to install it using PECL.
Hope you find this answer usefull!

Why is php zip extension not working on ubuntu though it's installed?

I'm on Ubuntu 16.04 and I'm trying to install prestashop e-commerce CMS that requires php zip extension to unzip the main CMS folder.
I have installed php-zip and php7.2-zip and I also restarted the web server (apache2) but the CMS still displays the following message
An error has occured:
You must install PHP zip extension first
Here's the result of my installed php zip packages and my current php version:
eljaouhari#eljaouhari-HP-350-G1:/var/www/html$ php -v
PHP 7.2.5-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: May 5 2018 04:59:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.5-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
eljaouhari#eljaouhari-HP-350-G1:/var/www/html$ apt list --installed | grep php | grep zip
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
php-zip/xenial,xenial,now 1:7.2+60+ubuntu16.04.1+deb.sury.org+1 all [installé]
php7.2-zip/xenial,now 7.2.5-1+ubuntu16.04.1+deb.sury.org+1 amd64 [installé]
I spent an hour and a half trying to figure out whether I need to activate the extestion on the php.ini file and also installing and reinstalling and restarting the web server but nothing seems to work.
I have tried a few solutions on the web that used to work for me but I can't seem to find a good solution.
Please help me with your experience!
I've found the solution after I printed the results of the phpinfo() function.
It seems that the version of php printed with the "php -v" command is not the version that actually apache is using. Apache ended up using the 7.0 version.
Thanks everyone.

PHP 7.2 memcached extension on Mac OS

I am trying to setup php memcached extension on mac OS High Sierra. I am running php 7.2
Output of php -v:
PHP 7.2.6 (cli) (built: May 25 2018 06:18:43) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.6, Copyright (c) 1999-2018, by Zend Technologies
I installed memcached via pecl without any error:
pecl install memcached
It is enabled in php.ini file:
extension="memcached.so"
When I run <?php echo phpinfo();?> on my Apache server. I can see session configured:
session.save_handler memcached memcached
My symfony application gives me still this error:
(1/1) ClassNotFoundException
Attempted to load class "Memcached" from the global namespace.
Did you forget a "use" statement?
EDIT:
My apache is running a different version of php (PHP Version 7.1.16) I don't know why but I think this cannot be a problem.
In info file I can see in the CORE section that php extension dir is "/usr/local/lib/php/pecl/20170718". When I open that directory there is memcached.so file. The path is correct.
EDIT 2:
In my apache logs I see warning:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/pecl/20170718/memcached.so' - dlopen(/usr/local/lib/php/pecl/20170718/memcached.so, 9): Symbol not found: _zend_empty_string\n Referenced from: /usr/local/lib/php/pecl/20170718/memcached.so\n Expected in: flat namespace\n in /usr/local/lib/php/pecl/20170718/memcached.so in Unknown on line 0
So. Apache and SLI php version use diferent php.ini files.
For examle on my Debian 9 it use /etc/php/7.2/apache2/php.ini and /etc/php/7.2/cli/php.ini
I believe your problem is that you are using a different version of PHP.
Just try comands below:
$sudo a2dismod php7.1
$sudo a2enmod php7.2
$sudo service apache2 restart
If you still get same Error try create info.php in your www root dir thich conteint next code:
<?php
phpinfo();
And check Memcache are loaded.

Configuring Xdebug debugger on PhpStorm w/ Laravel, Vagrant

Trying to configure my Vagrant server to use Xdebug. Read that it comes with Xdebug, but I checked this and doesn't seem to be true.
SSH into Vagrant machine,
$ php -v
reveals that machine is using
PHP 7.2.0-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Nov 30 2017 13:58:33) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.2.0-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies with blackfire v1.18.0~linux-x64-non_zts72, https://blackfire.io, by SensioLabs
No xdebug. So I tried installing xdebug with
$ brew install homebrew/php/php72-xdebug
Seemed to work. But then I tried finding the path to xdebug.so:
$ locate xdebug.so
/usr/lib/php/20131226/xdebug.so
/usr/lib/php/20151012/xdebug.so
/usr/lib/php/20160303/xdebug.so
Tried putting all of these into php.ini, and they all failed.
Tried installing via
$ sudo apt-get install php7.2-xdebug
E: Unable to locate package php7.2-xdebug
So, I searched, and found:
$ apt search xdebug
Sorting... Done
Full Text Search... Done
php-xdebug/xenial,now 2.5.5-3+ubuntu16.04.1+deb.sury.org+1 amd64 [installed] Xdebug Module for PHP
What am I doing wrong to get Xdebug and php configured on my remote machine?
I was testing with Postman using the mapped domain.. Using the actual server IP works.
So, instead of "restfulapi.dev", hit "128.153.123.21" or whatever it is.
Very silly.

Fatal error: Call to undefined function: imagecreate()

I'm trying to put some graphics on a web page and at my prototype at the computer it's all working fine at the localhost. But now I uploaded the files to a server and I'm having a problem to plot some graphics. In my computer they are plotted, but on the server they are not.
I'm getting this error
Fatal error: Call to undefined function ImageCreate() in /home/t1g01/phplot.php on line 248
Line 248
$this->img = ImageCreate($this->image_width, $this->image_height);
I'm using phplot, and I uploaded the files form phplot too. Can anyone help me ?
Sorry for any mistake in English and thank you in advance.
This means your installation of php doesn't have the gd library installed/enabled.
http://www.php.net/manual/en/image.installation.php
If you are using a Linux machine then execute this command from console:
sudo apt-get install php5-gd
to install the php_gd2.dll extension. It will then work after an Apache restart.
PS: should first check your current php version
php -v
In My Case:
PHP 7.3.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 3 2019
10:00:24) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine
v3.3.5, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache
v7.3.5-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by
Zend Technologies
So, my PHP version is 7.3, so, the command for my version is :
sudo apt-get install php7.3-gd
Your server most like does not have GD (the built in PHP image processing library) enabled. You can check this by looking for "GD" in the output of :
<?php
phpinfo();
?>
If not, check the PHP docs on how to enable it: http://www.php.net/manual/en/book.image.php
For Fedora, CentOS
dnf install php-gd
systemctl restart httpd.service
On Ubuntu
apt-cache search php*-gd
apt-get install php<version>-gd
systemctl restart apache2.service
Windows users see: http://php.net/manual/en/image.installation.php
Copy the file php_gd2.dll from your PHP's ext/ directory to where
you have your php extensions. (No need to copy if php_gd2.dll is in the extension
dir already. Look in php.ini for 'extension_dir' directive to
find what is your current extension directory)
Modify your php.ini and change the following line:
;extension=php_gd2.dll
to:
extension=php_gd2.dll
It seems that your GD library is not being used. Double check your php.ini file.
for any php version the command for ubuntu installation is
apt-get install php-gd
it will install the version that matches your php version, and it will be later updated with you php version.
I know this is an old thread but I've just recently came across this same Fatal error: Call to undefined function: imagecreate() issue while doing some QR coding using a fresh Xampp install on Windows.
I resolved the issue by first looking in the php.ini file for the GD extension and fixed the issue by uncommenting
;extension=gd
Afterwards QR code was generated to the browser as expected.
NOTE: Don't forget to restart Apache to make the change stick.
For Ubuntu 16.04:
sudo apt-get install php7.0-gd
Stop and then restart Apache Server.
PS: should first check your current php version
php -v
In My Case:
PHP 7.3.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 3 2019
10:00:24) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine
v3.3.5, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.5-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
So, my PHP version is 7.3, so, the command for my version is :
sudo apt-get install php7.3-gd
Update for PHP 7.4.0 >
You should not install any external libraries !
As stated in PHP docs:
As of PHP 7.4.0, --with-png-dir and --with-zlib-dir have been removed. libpng and zlib are required.
PHP 7.4.0 and newer versions comes bundled with libpng and zlib by default.
So all you merely need to do is to uncomment gd extension in php.ini file:
;extension=gd -> extension=gd
Problem solved :)
Dont forget restart apache or php-fpm if not running after installation

Categories