Install and use different versions of PHP

Dec 18, 2022 by Thibault Debatty | 979 views

PHP Sysadmin

When working on different projects, you may have to switch between different versions of PHP. In this blog post we show how to install and use different versions PHP on Ubuntu.

Install different versions of PHP

To install different versions of PHP we will install the ondrej/php PPA repository:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Now we can install the desired version(s) of PHP. For example:

sudo apt install php7.4-cli php8.1-cli

At the time of writing, you can choose from

  • php5.6
  • php7.0
  • php7.1
  • php7.2
  • php7.3
  • php7.4
  • php8.0
  • php8.1
  • php8.2

You can also check available versions by yourself with

sudo apt search php.*-cli

Switch between and use different versions of PHP

So now you should have different versions of PHP installed. To know which version is currently in use, you can simply type

php --version

To switch to another version, you can use update-alternatives. First you can list the installed versions with

sudo update-alternatives --list php


Now you can change to another version with update-alternatives --set. For example:

sudo update-alternatives --set php /usr/bin/php8.1


This blog post is licensed under CC BY-SA 4.0

Fully customizable emails using Laravel 9
With the release of Laravel 9, the Swift Mailer (that is no longer maintained) has been replaced by the Symfony Mailer. You can already find some useful information about this change along all the other ones in the Upgrade Guide from Laravel 8.x to 9.0. However this guide does not contain enough information if you want to send fully customized emails. This blog post proposes you a solution coming directly from the Symfony documentation!
SQL injection with SQLMap
Code injection is one of the most critical web application vulnerabilities. Indeed, the consequences of code injection can be dramatic (impact). Moreover, still today a lot of web applications are vulnerable to code injection (frequency). Finally, some tools like SQLMap allow to automatically detect and use these vulnerabilities (exploitation). For this reason, the vulnerability is listed in the top 10 published by the Open Web Application Security Project (OWASP) [1]. In this blog post, we will present one type of code injection, called SQL injection, and we will show how to perform a SQL injection attack with SQLMap.
Filter USB devices with udev (and some PHP code)
USB devices can be a liability : they can be used to exfiltrate data from a computer or server, to plug a hardware keylogger, or to plant a malware. Hence on a managed computer, USB devices should be filtered and whitelisted. In this blog post we show how this can be achieved thanks to udev, and some PHP code.
This website uses cookies. More information about the use of cookies is available in the cookies policy.