My system is Ubuntu 12.04, PHP 5.3, and I'm trying to run some basic Intl code like this:
<?php
$coll = collator_create('en_US');
$result = collator_compare($coll, "string#1", "string#2");
and it outputs
PHP Fatal error: Call to undefined function collator_create()
Wasn't Intl extension supposed to be bundled with PHP since version 5.3?
PHP was installed via apt-get with this command line (I don't use Apache):
apt-get install php5 php5-cli php5-mysql php5-cgi php5-fpm php5-curl php-apc php5-memcache php5-memcached php5-common php5-gd php-xml-parser php-pear php5-imap php5-mcrypt php5-xdebug php5-suhosin
And here is what php -v produces:
PHP 5.3.10-1ubuntu3.5 with Suhosin-Patch (cli) (built: Jan 18 2013 23:40:19)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
with Suhosin v0.9.33, Copyright (c) 2007-2012, by SektionEins GmbH
You have specify --enable-intl when installing to use the bundled version of intl, or you can install it via PECL. See: http://www.php.net/manual/en/intl.installation.php
apt-get install php5-intl will also work.
Add php5-intl to the list of things you install.
It looks like it's just not part of the core PHP5 release, even though it is an option to be included, similar to how php-apc is now a standard part of PHP, though you have to explicitly install it.
Try in php.ini uncomment extension intl "extension = php_intl.dll", should be removed ";" before "extension", and then restart the server.
Related
I have Centos 7 and Virtualmin installed, with the tipycal php-fpm 5.4, 7.0, 7.1 that you can choice between the versions you prefer on every virtualhost via Virtualmin control panel, and everything works well.
But when I access to the server via SSH and check php -v I get this:
PHP 5.4.16 (cli) (built: Oct 30 2018 19:30:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
How can I select another php default/base version for the shell system?
When you issue the php command on the shell it uses the default php version on the server which in your case is php-5.4.16
To use another php version, you have to check where the binaries for those php versions are and invoke them with their full path rather than just typing php.
For example, on CentOS, for PHP 7.2 for example, the full path of the php binary is: /opt/rh/rh-php72/root/usr/bin/php
root#virtualmin /root
ยป /opt/rh/rh-php72/root/usr/bin/php -v
PHP 7.2.24 (cli) (built: Nov 4 2019 10:23:08) ( 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, Copyright (c) 1999-2018, by Zend Technologies
Install versions of PHP in centos 7
Setup Yum Repository
First of all, you need to enable Remi and EPEL yum repositories on your system. Use the following command to install EPEL repository on your CentOS and Red Hat 7/6 systems
Use this command to install EPEL yum repository on your system
sudo yum install epel-release
and now execute one of the following commands as per your operating system version to install the Remi repository.
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Install PHP 7 on CentOS
Your system is prepared for the PHP installation from yum repositories. Use one of the following commands to install PHP 7.4 or PHP 7.3 or PHP 7.2 or PHP 7.1 on your system based on your requirements.
Install PHP 7.4
yum --enablerepo=remi-php74 install php
Install PHP 7.3
yum --enablerepo=remi-php73 install php
Install PHP 7.2
yum --enablerepo=remi-php72 install php
.
Check version PHP install
php -v
.
PHP 7.4.1 (cli) (built: Dec 17 2019 16:35:58) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Install PHP Modules
You may also need to install additional PHP modules based on your application requirements. The below command will install some more useful PHP modules.
For PHP 7.4
yum --enablerepo=remi-php74 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
For PHP 7.3
yum --enablerepo=remi-php73 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
For PHP 7.2
yum --enablerepo=remi-php72 install php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt
I tried many times to update PHP from 5.5 to 7 on CentOS 7 but always unsuccessful. The installation seems always going well but when I checked php-v it is always:
PHP 5.5.7 (cli) (built: Jul 5 2017 12:03:23)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
Any idea how can I update?
Base repository of CentOS has no php7 packages.
You can use remi repo to install php7 on your CentOS 7.
Why Remi?
PHP package installed from remi repo will work as drop-in replacement for your current php5 binaries.
Remi repo is managed by one of PHP internals
Why not?
To install the Remi repository, we need to enable the EPEL repository first.
sudo yum install epel-release yum-utils
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
Then Enable php 7.0 (You can use php 7.1+ too)
sudo yum-config-manager --enable remi-php70
Now it's time to install php7
yum install php php-common php-cli php-mysql
Great!!!
Now you have php7 on your system. You can confirm with :
php -v
Details Instruction on how to setup php on different OS : https://rpms.remirepo.net/wizard/
I'm trying to install the yaml extension on Ubuntu.
I have PHP 7.1 on my server.
ubuntu#www1:~$ php -v
PHP 7.1.15-1+ubuntu14.04.1+deb.sury.org+2 (cli) (built: Mar 6 2018 11:27:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.15-1+ubuntu14.04.1+deb.sury.org+2, Copyright
(c) 1999-2018, by Zend Technologies
I was following another SO post that said to run
sudo apt install libyaml-dev php-dev php-pear
When I do that, the installer says, in part:
The following extra packages will be installed:
dh-php php7.2-cli php7.2-common php7.2-dev php7.2-json php7.2-opcache
php7.2-readline pkg-php-tools xml2
Suggested packages:
dh-make
The following NEW packages will be installed:
dh-php php-dev php7.2-cli php7.2-common php7.2-dev php7.2-json
php7.2-opcache php7.2-readline pkg-php-tools xml2
0 upgraded, 10 newly installed, 0 to remove and 85 not upgraded.
Need to get 3,073 kB of archives.
After this operation, 18.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] n
Abort.
So, why would the installer install PHP 7.2 extensions on a PHP 7.1 server?
I aborted the install and came here to ask:
How do I force my server to stay at PHP 7.1 and install the yaml extension?
Have you tried
sudo apt-get install -y php7.1-yaml
I have an error saying MongoClient class is not found.
I've tried both the instructions on the MongoDB website and these answers.
Upon php -v there is
PHP Startup: Unable to load dynamic library '/usr/lib/php/20131226/mongo.so'
PHP 5.6.30-1+deb.sury.org~trusty+1 (cli)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans
with sudo grep -rnw /etc -e "mongo.so"
I have
/etc/php/5.6/fpm/php.ini:2033:extension=mongo.so
/etc/php/5.6/cli/php.ini:2032:extension=mongo.so
/etc/php/5.6/apache2/php.ini:2033:extension=mongo.so
Then I tried the manual installation.
When I run phpize
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
At the make test output I get
PHP Warning: PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20121212
PHP compiled with module API=20131226
How do I compile the correct module?
I've removed php 7 entirely
sudo apt-get purge php7.*
I guess you had installed the wrong extension for your system.
I suggest to start fresh and use pecl to install and compile mongo extension properly.
Install pecl (assuming that you are using Debian-based distribution with correct apt repos, pecl comes bundled with php-pear)
sudo apt-get install php5-dev php-pear
Install the legacy mongo driver from pecl
sudo pecl install mongo
Add extension=mongo.so on php.ini
sudo su
echo "extension=mongo.so" >> /etc/php5/mods-available/mongo.ini
ln -rs /etc/php5/mods-available/mongo.ini /etc/php5/cli/conf.d/30-mongo.ini
ln -rs /etc/php5/mods-available/mongo.ini /etc/php5/fpm/conf.d/30-mongo.ini
ln -rs /etc/php5/mods-available/mongo.ini /etc/php5/apache2/conf.d/30-mongo.ini
Note that the legacy driver is not compatible with PHP 7+ and the lastest version of MongoDB one can use with this driver is 3.0. See the compatibility chart from MongoDB Docs.
Whenever I try to run this code
example#testserver:~$ sudo apt-get install php5-xdebug
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package php5-xdebug
I get this error "E: Unable to locate package php5-xdebug"
Please help
Thanks
If you're running the default apt installation of PHP on Ubuntu 16.04, then it should be PHP7. If I had to guess from php5-xdebug, then I'd say you were using a command intended for Ubuntu 14.04 or older where the default PHP installation was PHP5. You can verify your PHP version with:
php --version
This is what I see:
PHP 7.0.8-0ubuntu0.16.04.2 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.2, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
At any rate, you should be able to search available packages for your configuration with:
apt search xdebug
From my relatively fresh Ubuntu 16.04 install without any added PPA's, I get one result:
php-xdebug - Xdebug Module for PHP
So you can install this package by name (note the missing "5" from your command):
sudo apt install php-xdebug
You might also have to restart your webserver. If you're running the stock build of Apache for Ubuntu 16.04:
sudo service apache2 restart