Press ESC to close

Topics on SEO & BacklinksTopics on SEO & Backlinks

Guide to Installing PHP 8.1 on Ubuntu: Step-by-Step Instructions

PHP 8.1, the latest version of the popular programming language, brings a host of new features and improvements. If you’re an Ubuntu user and want to upgrade or install PHP 8.1 on your system, this step-by-step guide will walk you through the process. Follow these instructions carefully to ensure a smooth installation.

Step 1: Update Ubuntu

Before proceeding with the installation, IT‘s always a good idea to update your Ubuntu system to the latest available packages. Open the terminal and run the following commands:

$ sudo apt update
$ sudo apt upgrade

Step 2: Install Dependencies

Next, we need to install some dependencies that are necessary for PHP 8.1 to work properly. Run the following command in the terminal:

$ sudo apt install wget curl unzip

Step 3: Add Ondřej Surý PPA

Ondřej Surý maintains a Personal Package Archive (PPA) that includes the latest PHP packages for Ubuntu. We’ll add this PPA to our system. Run the following commands:

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

Step 4: Install PHP 8.1

Now we’re ready to install PHP 8.1. Run the following command in your terminal:

$ sudo apt install php8.1

Step 5: Verify the Installation

Once the installation is complete, you can verify if PHP 8.1 is successfully installed by running the following command:

$ php -v

This should display the PHP version information, confirming that PHP 8.1 is installed on your system.

Step 6: Configuring PHP

By default, PHP 8.1 should work out of the box with Ubuntu. However, you may want to make some modifications to the configuration file based on your specific requirements. The configuration file is located at /etc/php/8.1/cli/php.ini. Edit this file using a text editor of your choice.

FAQs:

1. How can I install PHP extensions?

To install additional PHP extensions, you can use the apt package manager. For example, to install the MySQL extension, run:

$ sudo apt install php8.1-mysql

2. Can I install multiple PHP versions?

Yes, you can have multiple PHP versions installed on your Ubuntu system. Simply follow the same steps above for each PHP version you want to install. However, keep in mind that you should only run one PHP version at a time.

3. How can I switch between PHP versions?

To switch between PHP versions on Ubuntu, you can use the update-alternatives command. For example, to switch to PHP 8.1 as the default version, run:

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

4. How can I restart PHP-FPM?

If you’re using PHP-FPM, you can restart the service by running:

$ sudo systemctl restart php8.1-fpm

5. How do I check the installed PHP extensions?

To see a list of installed PHP extensions, run the following command:

$ php -m

6. Can I remove previous PHP versions?

Before installing PHP 8.1, you may have older versions of PHP installed. To remove those versions, you can use the purge command. For example, to completely remove PHP 7.4, run:

$ sudo apt purge php7.4*

That’s IT! You have successfully installed PHP 8.1 on your Ubuntu system. Enjoy exploring the new features and improvements that PHP 8.1 has to offer.