How To Install PHP on Ubuntu Print

  • 0

Introduction

PHP is a scripting language commonly used to develop web applications. It can create dynamic websites that adapt pages for specific users. Its advantages include versatility and security.

In this guide, we will install PHP 8.3 on Ubuntu (20.04 or newer). You can also follow this tutorial for other PHP versions.

 

Installation Guide

 

1. Update the System

Run the following command to update your system:

apt update

 

2. Add PHP Repository

To access the latest PHP versions, add the Ondřej Surý PPA:

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

Update your system again:

apt update

 

3. Install PHP

Install PHP 8.3 (replace 8.3 with your desired version if needed):

apt install php8.3

If Apache is automatically installed and you do not require it, remove it using:

systemctl stop apache2
apt remove apache2 -y
apt purge apache2 -y
apt autoremove -y

 

4. Install Frequently Used PHP Extensions

Install common PHP extensions (adjust version number if necessary):

apt install php8.3-cli php8.3-fpm php8.3-mysql php8.3-curl php8.3-xml php8.3-zip php8.3-mbstring php8.3-gd php8.3-soap php8.3-intl php8.3-bcmath

If Apache is running, enable PHP-FPM with the following commands:

a2enmod proxy_fcgi setenvif
systemctl restart apache2
a2enconf php8.3-fpm
systemctl reload apache2

 

5. Check PHP

Verify that PHP was installed correctly:

php -v

List all available PHP extensions:

php -m

 

6. Manually Install Desired PHP Extensions

To install any PHP extension manually (replace extension_name with the extension you need):

apt install php8.3-extension_name -y

Was this answer helpful?

« Back

Powered by WHMCompleteSolution