Skip to content

Instantly share code, notes, and snippets.

@ruman
Last active June 21, 2024 08:41
Show Gist options
  • Save ruman/ecdc0f7ea09266a1ac79f0fe00a6815f to your computer and use it in GitHub Desktop.
Save ruman/ecdc0f7ea09266a1ac79f0fe00a6815f to your computer and use it in GitHub Desktop.
PHP additional version installation with version switched.

Install PHP version 8.0

In order to install PHP version 8.0, first, open your Ubuntu Terminal and enter the following command in order to add the Ondrej PHP repository to your Ubuntu system (in case you have not done that already in the above chapter to install PHP 5.6).

$ sudo add-apt-repository ppa:ondrej/php

This repository contains all the released versions of PHP till date.

Once the Ondrej repository is added, you need to update your system’s repository with that on the internet. This way you can install the latest available version of a software on your system. Enter the following command in order to do so:

$ sudo apt update

Now is the time to install PHP 8.0 to your system. Enter the following command as sudo as only an authorized person can install/uninstall and configure software on Ubuntu:

$ sudo apt install -y php8.0

The software will then be installed on your system.

In order to check the version number of your installed PHP, run the following command:

$ php -v

or,

$ php --version

The command will also verify that PHP is now indeed installed on your system.

Now you have PHP 8.0 installed, but most use cases require that you install additional PHP modules like MySQL support, Curl, GD, SQLite, XML, etc. Run the below command to install some commonly used modules.

sudo apt install php8.0-gd php8.0-mysql php8.0-imap php8.0-curl php8.0-intl php8.0-pspell php8.0-sqlite3 php8.0-tidy php8.0-xsl php8.0-zip php8.0-mbstring php8.0-soap php8.0-opcache libonig5 php8.0-common php8.0-readline php8.0-xml

Now check the server's existing PHP versions

sudo update-alternatives --config php

Now choose php8.0 with entering the number. Then run the follow commands to de-active the current version and activate the new one. For example server already have install php8.1, then

sudo a2dismod php8.1 && sudo a2enmod php8.0 && sudo service apache2 restart
@ruman
Copy link
Author

ruman commented Jun 21, 2024

// to add new config file into apache2
sites-available/newsite.conf
//update
a2ensite newsite
//restart the server
systemctl reload apache2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment