PHP 5.3 can't find normalizer_normalize() - php

I am trying to use the normalizer_normalize() function introduced in PHP 5.3 (says the doc), however I can't use it:
$ php -r 'echo normalizer_normalize("tést");'
PHP Fatal error: Call to undefined function normalizer_normalize()
in Command line code on line 1
I've checked my PHP version but it's 5.3:
$ php --version
PHP 5.3.6 (cli) (built: Sep 12 2011 18:02:42)
I don't understand why PHP can't find it?

Normalizer is part of the intl extension. While it's built by default, that does not necessarily mean that the specific version of PHP that you are using has it installed or enabled by default.
If you're getting your PHP version from your operating system, check to see if the package manager has a package named php-intl. If not, check for php-pecl-intl. If you're using RHEL/CentOS/Scientific Linux 5.x, also look for php53-intl.

I wanted to give a modern, up-to-date answer, as things seem to have changed a bit since 2012. Using Ubuntu 20.04 and PHP8.1, I was able to get this to work with just...
sudo apt-get install php8.0-intl
Don't forget to do a full apache restart afterwards (either one of these should do it)...
systemctl restart apache2
/etc/init.d/apache2 restart
In addition, this automatically installed the updated 8.1-version...
root# dpkg --list | grep 'intl'
ii php8.0-intl 1:8.0.21-2+ubuntu20.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP
ii php8.1-intl 8.1.8-1+ubuntu20.04.1+deb.sury.org+1 amd64 Internationalisation module for PHP

Related

Ubuntu 18.04 using PHP version that is not installed as a module

Using the commmand php -v on a Ubuntu 18.04 server is displaying PHP version 8.1.14, but no PHP8.* module is installed.
I have tried running the command: sudo update-alternatives --config php which displays:
Available PHP versions
Disabling the PHP8.1 module will show me that the module is not installed:
module not installed
While php -v is really showing me PHP8.1:
PHP version
I have tried to purge the PHP 8 version with the following command:
sudo apt-get purge php8.*
It showed me 0 modules were marked for removal, just to be sure I also ran autoremove & autoclean commands.
When I display the PHP info, it also shows the 8.1 version:
PHP info
I need to get the server back to version 7.4 to make some installations function properly, I have tried all options above but did not succeed. How can I downgrade to PHP Version 7.4?
While I was installing the PHP Selector add-on for DirectAdmin, I noticed Zend modules were being installed for 7.4. Perhaps these were missing for the server to switch back to version 7.4. Problem solved!

Ubuntu/Apache2 Change PHP Version

I'm trying to use pthreads but for this i hafe to install the pthread php extention.
My server is already setup with php 7.0 and as I read whats the best way to use it is i found this https://gist.github.com/emiglobetrotting/4663ffc4484e9384a261#file-php7_zts_pthreads-sh-L95
This is a manual how to compile ur own php version with Thread Safety enabled
i did this and now if I run
php -v
it show me the correct php version:
PHP 7.3.0-dev (cli) (built: May 7 2018 09:54:09) ( ZTS DEBUG )
but if i run phpinfo on my Apache I found:
PHP Version 7.0.28-0ubuntu0.16.04.1
So now i look for a way to change this in my apache config but what ever i try it leads me to the same problem:
I need a module that i can enable.
So my question is how could i change my apache to the correct version or how can i create/install a module to use the new php version?
You can do this by following commands.
sudo a2dismod php7.3.0-dev ; // To disable a PHP 7.3.0-dev version
sudo a2enmod php7.0 ; // To enable a PHP 7.0 version
sudo service apache2 restart // then restart apache

XDEBUG installation reading wrong PHP version

I have an Ubuntu 16.04 vagrant box running on php 7.1. When I try to build xdebug by running ./configure in xdebug-2.6.0 I get
Check for supported PHP versions... configure: error: not supported. Need a PHP version >= 7.0.0 and < 7.3.0 (found 5.5.9-1ubuntu4.24)
PHP -v yields
Xdebug requires Zend Engine API version 320170718.
The Zend Engine API version 320160303 which is installed, is outdated.
PHP 7.1.15-1+ubuntu14.04.1+deb.sury.org+2 (cli) (built: Mar 6 2018 11:27:08) ( NTS )
So the system is running 7.1, but for some reason the configure script thinks we're still on 5.5.9
I've hit google pretty hard, but still can't find a way to update the Zend engine either.
Any ideas?
It happens because you're configuring with default settings and that is different from the PHP version you're trying to configure.
Just like you saw the PHP version using the php -v command, check the php-config version using the php-config --version command, it should be the same as php -v, but in your case, it would be different and hence this issue.
Now let's talk about how we can solve it. Since you need a different version of config, you should point that to the configure command.
For example, in your case, you need php-config7.1 (because you're using PHP v7.1, similarly for 7.2 you have php-config7.2 and so on)
To point the configure command to a specific PHP version you need to specify that as a flag called with-php-config and the value should be the location of the php-config file, a sample would be
./configure --with-php-config=/usr/bin/php-config7.1
Hope this solves the problem.
I assume you run phpize before running ./configure. Instead you need to run phpize7.1 and then ./configure
if you don't have phpize7.1 installed you can install it via:
sudo apt install apt install php7.1-dev

Install PHP stats library on Ubuntu 16

I'm trying to install the PHP statistics package on my Ubuntu 16.04 LTS server, and I'm stuck.
First off, config stuff:
$ apache2 -v
Apache/2.4.18 (Ubuntu)
$ php -v
PHP 7.0.15-0ubuntu0.16.04.4 (cli) ( NTS )
$ pear -V
PEAR Version: 1.10.1
I have successfully added pear using apt-get as well as php-all-dev.
When I try to install the stats package with pecl, I get the following:
$ pecl install stats
pecl/stats is already installed and is the same as the released version 1.0.5
I have also added extension=stats.so to my php.ini and restarted apache.
But when I try to run any of the stats functions, I get the following error:
Fatal error: Uncaught Error: Call to undefined function stats_standard_deviation() in /var/www/html/testing/stats_library.php:14 Stack trace: #0 {main} thrown in /var/www/html/testing/stats_library.php on line 14
What am I missing?
I was able to successfully add the extension by adding the version to the install command like this:
$ pecl install stats-2.0.3
I then added extension=stats.so to my php.ini and restarted apache. Everything works now!
So, first of all there is 2 PHP versions.
The CLI (command line) and the FPM used by your server.
The php stats module is a C library so we need to compile it, usually this is done with the PECL tool.
Check if PECL is working
pecl list
Install the stats module, if you use PHP7+ you should specify the package version as by default it pull the PHP5 version from the repo. Here is the repo https://pecl.php.net/package/stats
pecl install stats-2.0.3
This will compile and install the stats module. If you have an error check that you have the php-dev installed. On ubuntu
[Optionnal - adapt to your php version]
sudo apt-get install php7.2-dev
Then run again pecl install and it should work.
Activate the extension.
Now we need to active the extension, and here is the catch. You need to edit both php.ini to have it work on CLI and FPM
For the CLI it's easy just do php -ini to find the path of the .ini file.
For FPM, to be sure you can run <?php phpinfo(); ?> on your serveur and check the Loaded Configuration File.
Then edit both file adding
extension=stats.so
usualy this will probably be :
/etc/php/7.2/fpm/php.ini
/etc/php/7.2/cli/php.ini
And now (the ultimate trap!) don't forget to restart Apache AND FPM
sudo service apache2 restart
sudo service php7.2-fpm restart
Now you can check with the CLI with php -m and should see the stats module activated. For FPM just check in your phpinfo();
I hope this can help !

php56 - CentOS - Remi Repo

I just installed php 5.6 on a test box, and the normal cli php interpreter doesn't appear to exist:
$ -> php -v
-bash: php: command not found
$ -> php56 -v
PHP 5.6.13 (cli) (built: Sep 3 2015 13:41:04)
If I try to do a yum install php --enablerepo=remi then it tries to install php 5.4.
So it's obvious that php56 is a cli interpreter, but I've always been used to just typing php vs php56. Is this the new norm, or is there another step for installing php56 on CentOS (6.7)? Is it as simple as creating a symlink? ln -s /usr/bin/php56 /usr/bin/php
Steps to upgrade:
$ -> yum remove php* --enablerepo=remi
$ -> yum install php56* --enablerepo=remi
Thx to Remi for the push in the right direction, here's what my repo config looks like:
[upstream_remi54]
name=Remi - CentOS - $releasever/$arch
baseurl=http://mirrors.mediatemple.net/remi/enterprise/$releasever/remi/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://rpms.famillecollet.com/RPM-GPG-KEY-remi
[upstream_remi56]
name=Remi - CentOS - $releasever/$arch
baseurl=http://mirrors.mediatemple.net/remi/enterprise/$releasever/php56/$basearch/
enabled=0
gpgcheck=1
gpgkey=http://rpms.famillecollet.com/RPM-GPG-KEY-remi
This works well if you want to completely replace existing PHP, vs running versions in parallel. I have to keep PHP 5.4 in place for Roundcube and Postfix Admin, as some of the modules necessary for those to work have not yet been ported, so that server has to stay 5.4 for now.
php-* are base packages, 1 repository per version
"remi" => php 5.4
"remi-php55" => php 5.5
"remi-php56" => php 5.6
"remi-php70" => php 7.0 (Release Candidate, not ready for prod)
php56-* packages are Software Collections, parallel installation allowing to run multiple versions of PHP.
See : http://blog.remirepo.net/pages/English-FAQ
So, if you only want a single php version 5.6
yum --enablerepo=remi-php56 install php-cli (and other needed modules)
And you can also enable the repository for future update (as the "remi-php56" is safe and only provides php 5.6 and its extension)
yum-config-manager --enable remi-php56

Categories