How to install PHP extensions on Linux

How to install PHP extensions on Linux

12:58, 04.07.2022

Article Content
arrow

  • Installing PHP 7.4 for Apache
  • PHP 7.4 Installation Guide for Nginx
  • How to install PHP extensions on Linux
  • A little bit about PECL and conclusion

During the initial configuration of the server, one of the most important steps is the installation of PHP extensions – they are needed for most CMS, including the popular WordPress, Magento, and Laravel. In this article, we will tell you which PHP scripts must be installed and how to do it through the console. We will install it on Ubuntu 20.04, but the syntax of the commands described below can be adapted to any other Linux system.

Installing PHP 7.4 for Apache

Users of this web server only need to execute two commands sequentially:

sudo apt update
sudo apt install php libapache2-mod-php

And then restart the web server so that the changes take effect and the PHP scripts start working:

sudo systemctl restart apache2

PHP 7.4 Installation Guide for Nginx

This web server does not support PHP processing out of the box, so it will need a FastCGI - PHP–FPM process manager to work. Through the console we drive in:

sudo apt update
sudo apt install php-fpm

Upon completion of the installation, the service will start working, you will not even need to reboot. You can check the status of its work using the command:

systemctl status php7.4-fpm

And now we proceed directly to the installation of PHP extensions.

how to install php extensions on linux

How to install PHP extensions on Linux

These package modules are compiled libraries that extend the basic functions of PHP. They are often needed for programmers and webmasters to work, as they help to implement many interesting features. To install packages, use the command:

sudo apt install php-[extname]

Only instead of [extname] it is necessary to substitute the name of the plugin of interest. For WordPress, for example, you may need the following:

  • php-mysql — needed when working with a database, most often put together with the main language package;
  • php-ctype — is needed in cases when a Fatal error occurs during operation: Call to undefined function ctype_digit() in /wp-admin/includes/file.php;
  • php-dom — sometimes needed when working with Windows hosting, but most often not in demand;
  • php-exif — required to work with photo meta data;
  • php-gd — used when processing images, needed often;
  • php-iconv — converting a string from one encoding to another;
  • php-json — JSON support;
  • php-posix — used in the WP_Filesystem_Direct class
  • php-mbstring — required, needed for string processing;
  • php-zip, php-zlib — useful for those who work with archives.

In general, the complete list of all existing PHP extensions is estimated at hundreds of different modules, most of which are highly specialized and are used by IT specialists to optimize work tasks.

You can also install PHP extensions via the ISPmanager control panel or any other – there in the corresponding tab you can download and install all the necessary packages without a console.

A little bit about PECL and conclusion

We should also mention the repository of native extensions for PHP written in the C language. They are used in cases when it is not possible to implement some ideas in PHP - for example, reloading operators. All modules in the PECL repository are developed in strict accordance with the coding standards adopted by the PHP development team, so the quality of their work should not cause you any doubts.

If you still have questions about how to install and connect PHP extensions to your server, contact our specialists via Livechat or by phone. We will answer all your questions within our competence.

views 2m, 46s
views 2
Share

Was this article helpful to you?

VPS popular offers

Other articles on this topic

cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.