First, you will need to install PEAR via apt-get to get the necessary package and distribution system that both PEAR and PECL use. From a shell prompt enter:
sudo apt-get install php-pear
You will be prompted to confirm the install. Just press “y” and enter. If all goes well you should see it download and install the php-pear package.
Now you will need to install the php-dev package to get the necessary PHP7 source files to compile additional modules. Enter the following from a shell prompt:
sudo apt-get install php-dev
If you do not install the php-dev package and try to install a PECL extension using “pear install”, you will get the following error:
sh: phpize: not found
ERROR: `phpize’ failed
The PECL_HTTP extension requires an additional dependency package to be installed. You can probably skip this for other extensions:
sudo apt-get install libcurl4-openssl-dev
Now we are finally ready to actually install the extension. From a shell prompt enter following:
sudo pecl install ds
The installer may ask you about some specific options for the extension you are installing. Just accept the defaults and go ahead.
Once the install is complete, it’s time to enable the extension.
First, edit the following file (create it if it does not exist already):
sudo vi /etc/php/7.0/mods-available/ds.ini
and change it’s contents to:
; configuration for php ds module
Than check and remove any symbolic links to 20-ds.ini file, such as:
sudo rm /etc/php/7.0/fpm/conf.d/20-ds.ini
sudo rm /etc/php7.0/apache2/conf.d/20-ds.ini
sudo rm /etc/php7.0/cli/conf.d/20-ds.ini
You need to remove above listed symlinks because of bug: there is hard dependency on the json extension. DS extension shouldn’t try to implement JsonSerializable if the json extension is not loaded, but actually do it and it will complain with exception if it is not found:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/ds.so'
- /usr/lib/php/20151012/ds.so: undefined symbol: php_json_serializable_ce in Unknown on line 0
That’s why we removed 20-ds.ini symlinks and specified ds.so to load after json is already enabled.
Now, disable and then re-enable the extension:
sudo phpdismod ds
sudo phpenmod ds
You may need to restart your HTTP server:
# If you are on apache
sudo service apache2 restart
# if you are on nginx
sudo service nginx restart