Skip to content

Ultra lazy script to install and set up Web dev env. Apache with PHP 7.4 and 8.1 in Ubuntu 20.04+

  • by

This is my list/script with commands that permit me to install very quickly PHP 7.4 and 8.1 on a new machine. My pref dev environment is the KDE provided by these fantastic people


# Install necessary packages
sudo apt install software-properties-common apt-transport-https
sudo apt install apache2

sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.1 libapache2-mod-php8.1
sudo apt install php7.4 libapache2-mod-php7.4

# Install PHP extensions
sudo apt-get install php-common php-cli php-curl php-json php-bcmath php-bz2 php-intl php-gd php-mbstring php-mysql php-zip php-fpm php-cgi php-xsl php-xml php-soap php-zip
sudo apt-get install php7.4-common php7.4-cli php7.4-curl php7.4-json php7.4-bcmath php7.4-bz2 php7.4-intl php7.4-gd php7.4-mbstring php7.4-mysql php7.4-zip php7.4-fpm php7.4-cgi php7.4-xsl php7.4-xml php7.4-soap php7.4-zip

# Restart Apache
sudo service apache2 restart

# Install Composer
curl -sS -o /tmp/composer-setup.php
HASH=$(curl -sS
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer

# Cleanup temporary files
rm /tmp/composer-setup.php

Copy and paste the above script into a text file (e.g.,, and save it. Make the script file executable by running the following command:

chmod +x

You can then run the script by executing:


Use this command to choose your default PHP version. Based on the code above you can choose PHP 7.4 or 8.1. Feel free to modify.

sudo update-alternatives --config php

Far to be complex but can be a quick and short way to add MySQL for local WordPress development you can read this article:

Hits: 6

Leave a Reply

Your email address will not be published. Required fields are marked *