Installing Essential PHP Extensions for Laravel on Ubuntu 16.04
When building a production environment for Laravel, having the correct PHP extensions is non-negotiable. Laravel's core functionality relies heavily on specific libraries; without them, the framework will fail to bootstrap, often resulting in cryptic "class not found" errors or missing dependency warnings. While you might have successfully installed PHP 7.1 and MariaDB via your package manager, these base packages do not automatically include every extension required by modern PHP applications.
On Ubuntu 16.04, managing dependencies is almost exclusively a terminal-based task. Attempting to handle this through the graphical user interface (GUI) is generally inefficient for system-level configuration. Tools like apt provide atomic package management that ensures version compatibility and dependency resolution, which GUI front-ends often struggle to replicate accurately. Therefore, the most reliable approach involves using the command line to install the specific packages corresponding to your required extensions.
Here is how to address the specific list you need: OpenSSL, PDO, Mbstring, Tokenizer, and XML.
Enabling OpenSSL
The OpenSSL extension is critical for handling HTTPS requests, which Laravel uses extensively for secure communication with APIs and database connections over SSL. On Ubuntu systems running PHP 7.1, this is typically packaged under php7.1-openssl.
Run the following command to ensure it is installed:
sudo apt-get install php7.1-openssl
Note that on some distributions, the package name might simply be php-openssl if a PHP version-specific prefix isn't required by your specific Ubuntu repository configuration. If the installation fails, check the exact package name with apt-cache search openssl.
Configuring PDO and Mbstring
PDO (PHP Data Objects) is the standard interface for database access in Laravel, while Mbstring handles multibyte character encoding, which is essential for internationalized applications. These are often grouped into a single installation command to save time:
sudo apt-get install php7.1-pdo php7.1-mbstring
If you are using MariaDB specifically, ensure you also have the php7.1-pgsql or php7.1-sqlite3 extensions if your application requires those specific drivers, though PDO usually covers the core connectivity logic needed for MySQL/MariaDB once the base driver is present.
Handling Tokenizer and XML
The Tokenizer extension allows PHP to parse source code into tokens, a feature Laravel uses internally for caching compiled expressions and parsing Blade templates. The XML extension is required for processing data formats like JSON (via SimpleXML) or RSS feeds.
Install these with:
sudo apt-get install php7.1-tokenizer php7.1-xml
Verifying the Installation
Once the packages are installed, you must verify that the extensions are actually loaded into the PHP runtime. Navigate to your Laravel project directory (if you haven't already) and run:
php -m | grep -E 'openssl|pdo|mbstring|tokenizer|xml'
If any of these return nothing, the extension is not active. In rare cases on Ubuntu 16.04 with PHP 7.1, you might need to manually enable them by editing the php.ini file located in /etc/php/7.1/mods-available/. Look for lines starting with a semicolon (;) before the extension name and remove the semicolon.
Rebuilding Composer Autoloader
After installing new extensions, it is good practice to regenerate your autoloader to ensure Laravel's class map reflects the current environment state:
php artisan config:clear
php artisan cache:clear
composer dump-autoload
If you encounter issues where Laravel still complains about missing dependencies despite successful installation, check the php.ini file in /etc/php/7.1/cli/conf.d/ or /etc/php/7.1/fpm/conf.d/ depending on your SAPI configuration. Ensure that the extension files are not commented out and that the paths point to the correct library locations.
For further guidance on optimizing PHP configurations for high-traffic Laravel applications, you may want to refer to resources like https://laravelcompany.com, which often provides detailed tuning guides beyond basic installation steps.