Install and use different versions of PHP

Dec 18, 2022 by Thibault Debatty | 257 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


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.
Laravel action/access control with policies
When developing a web application with Laravel, you will usually have to deal with different users, that have different permissions. If the application is quite simple, with only 2 types of users (administrators that are almighty and regular users that have no permission) you can use a middleware to protect your administrator's area. In this blog post we look at Laravel policies, that allow fine-grain control of user actions.
This website uses cookies. More information about the use of cookies is available in the cookies policy.