How to install PHP modules (Debian/Ubuntu)

Phpinfo script creation

First, you need to create and place a phpinfo.php script in the site directory to get information about PHP parameters on the server.

1. Connect to the server via SSH.

2. Go to the site directory:

cd path/to/site/directory

 3. Create a file:

nano phpinfo.php

4. Add content to the file:

<?php

phpinfo();

phpinfo(INFO_MODULES);

?>

5.  Click Ctrl+x to close nano.

Press Y to save changes and Enter to confirm.

6. Enter in the browser address bar http://your.domain.name/phpinfo.php

Here you will see information about PHP settings.

Installing modules (for example imagick)

1.  Most of the names of packages start with php. If you do not know the full exact name of the required package (or are not sure), you can find it by part of the name:

apt-cache search package_name

For example, if you want to find package imagick:

apt-cache search php-ima

As a result, you will be presented with a list of all packages whose names include "ima", and a description of these packages:

  • php-image-text – Image_Text – Advanced test maipulations in images
  • php-imahick – Privides a wropper to the ImageMahick library
  • php-imap – IMAP module for PHP [default]
  • php7.2-imap – IMAP module for PHP

From this list, we need php-imagick.

2. Update information from repositories:

Apt update

3. Install the library:

apt install php-imagick

Instead of "php-imagick" you can enter the name of any other package. If you know exactly the name of the package - you can skip step 1. 

4. Check your extension directory:

- enter in the address bar of your browser http://your.domain.name/phpinfo.php,

- find the extension_dir parameter. The line for this parameter will display the directory for the extensions.

5. To check if the required library is in the given category:

- Change directory for extensions:

cd extension_directory

- Enter:

ls library_name

In our case, for the imagick library, you need to enter:

ls imagick

Or you can specify part of the name:

ls imag*

If the library is in the extension directory, it will be displayed in the console.

6. Check the directory for additional config files:

- enter in the address bar of your browser http://your.domain.name/phpinfo.php,

- find the Scan this dir for additional.ini files parameter, in the line of this parameter the directory for additional configuration files will be displayed,

- go to this directory:

cd directory_address

- browse the contents of the directory:

ls file_name

In our case, for imagick you need to enter:

ls imagick

Or you can specify part of the name:

ls imag*

If a configuration file with a directive connecting the library has been created, then the console will display:

root@name:

directory_address ls imagick 20-imagick.ini

7. Create config file if missing:

echo "extension=imagick.so" > / directory_from_item_6/imagick.ini

It will create an imagick.ini configuration file in the required directory and add the extension = imagick.so directive to it.

When this command is executed, a configuration file “imagick.ini” will be created in the specified directory, and the necessary directive “extension = imagick.so.” will be added to this file.

8. Restart Apache:

service apache2 restart

9. Refresh the page in the browser http://your.domain.name/phpinfo.php.

To check the installation was successful, find the required module on the page.

Connecting external libraries

You can also link libraries from other sources (not from the repository).

1.  Upload the library file (with the .so extension) to the extension directory.

To find out the address of the directory, enter in the address bar of the browser http://your.domain.name/phpinfo.php.

Find the extension_dir parameter, in the line of this parameter the directory for extensions will be displayed.

2. Go to the directory with additional configuration files.

To find out the address of the directory, enter http: //your.domainname/phpinfo.php in the address bar of your browser. Find the Scan this dir for additional.ini files parameter, the line for this parameter will display the directory for additional configuration files.

Change to this directory:

cd directory_address

3. Create a config file:

nano library_name.ini

4. Specify a directive in this file, save the changes:

extension=library_name.so

5. Restart the Apache web server:

service apache2 restart

6. Refresh the page http: //your.domain.name/phpinfo.php in your browser and check for the name of the installed library there.

If an error occurs and the library file is located in a different directory, at step 4 in the directive, additionally specify the required path:

extension=path_to_library/library_name.so

 

If you have any questions, please create a ticket to technical support.