Skip to main content

Switching the PHP version used by Apache on Ubuntu

Linux 22 June 2022

On Ubuntu several PHP releases can be installed side by side, but Apache loads only one mod_php module at a time, and the command line php binary is selected separately through update-alternatives. These are the steps we use to move a web server from one PHP release to the next. The example switches from 7.1 to 7.2 and works the same way for 8.x.

1. See what is installed

apt list --installed | grep -i php

To remove an old release completely, here PHP 5:

apt-get purge php5*

2. Switch the Apache module

a2dismod php7.1
a2enmod php7.2
service apache2 restart

3. Switch the command line binaries

update-alternatives --set php /usr/bin/php7.2
update-alternatives --set phar /usr/bin/phar7.2
update-alternatives --set phar.phar /usr/bin/phar.phar7.2
update-alternatives --set phpize /usr/bin/phpize7.2
update-alternatives --set php-config /usr/bin/php-config7.2

The last two are only needed when PECL extensions are compiled on the server.

4. Check the loaded Apache modules

apachectl -M

The list must contain php7_module (or php_module for PHP 8) and no module of the old release. The same list is visible in Joomla under System Information.

5. php.ini values for Joomla

Each release has its own php.ini, so the settings have to be applied again in /etc/php/7.2/apache2/php.ini. These values clear the warnings under Joomla > Extensions > Warnings:

upload_max_filesize = 64M
post_max_size = 64M
sys_temp_dir = "/tmp"
upload_tmp_dir = /tmp

6. Remember the two php.ini files

The command line PHP may read a different configuration from the one loaded by Apache:

php -i | grep -i php.ini
Configuration File (php.ini) Path => /etc/php/7.2/cli
Loaded Configuration File => /etc/php/7.2/cli/php.ini

Reference: PHP supported versions. Related: web hosting by GOLINE.

0 0 votes
Article Rating
Subscribe
Notify of

0 Comments
Oldest
Newest Most Voted
Goline It Services Logo

News

  • GOLINE is pleased to announce that it has achieved ESET Gold Partner status for 2027. The recognition follows the successful completion of ESET’s partner certification requirements and confirms GOLINE’s continued investment in cybersecurity expertise and professional development. ESET’s partner programme is designed to support companies working with its cybersecurity solutions through dedicated technical and sales resources, training and other partner services. For GOLINE, the achievement further strengthens its collaboration with ESET and its ability to integrate ESET security technologies into the cybersecurity solutions and services it provides to businesses. ESET solutions are already part of GOLINE’s cybersecurity portfolio, alongside technologies...
  • GOLINE SA is excited to announce a new partnership with NetApp, a global leader in cloud data services and storage solutions. This collaboration aims to help organizations modernize their IT infrastructure, streamline data management, and enhance performance across cloud and hybrid environments. Modern Data Solutions for Businesses Through this partnership, GOLINE integrates advanced data management solutions, enabling businesses to securely store, manage, and access critical information across cloud, on-premises, or hybrid setups. Clients can benefit from: Flexible and scalable storage solutions to meet growing data needs Simplified management of cloud and on-premises environments Enterprise-grade security for sensitive and mission-critical data...
  • GOLINE SA is proud to announce a new strategic partnership with Omnissa, a global leader in digital workspace platforms and Horizon Cloud Service solutions. This collaboration marks a significant step forward in helping organizations embrace secure, flexible, and high-performance work environments. Why Choose Omnissa for Your Business? The platform enables virtual desktops, applications, and unified endpoint management. Organizations can deploy scalable workspaces across cloud, hybrid, or on-premises setups. Key benefits include: Easy access to desktops and apps on any device Centralized management for Windows, macOS, iOS, Android, and ChromeOS Strong security with access controls and multi-factor authentication Automated scaling to...
  • Hosting Services
  • +41 (0)91 260 76 50
0
Would love your thoughts, please comment.x
()
x
| Reply