frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

How To Install PHP on Ubuntu

MichailMichail Moderator
edited December 11 in Linux Applications

Introduction

PHP is a scripting language that is commonly used to develop web applications. It can be used to create dynamic websites that will adapt pages to a specific user. Its advantages are its wide range of capabilities and security due to its closed source code.

In this guide we will install PHP 8.3 version on Ubuntu (starting from 20.04 version). You can also use this tutorial for any other PHP version.

Installation Guide

1. Update the system

Update your system by running this command:

apt update

2. Add PHP Repository

To access the latest PHP versions, add the Ondřej Surý PPA to your system by running:

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

Then repeat the system update:

apt update

3. Install PHP

Run this command to install PHP (You can also install any other version by simply entering a different number in place of 8.3.):

apt install php8.3

Please note that on some systems, the second update command or the installation of PHP 8.3 may automatically install Apache. If you do not require it, you can run the following commands to remove Apache:

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

If you wish to keep it, simply continue following this guide.

4. Install Frequently Used PHP Extensions

Most web applications need extra PHP extensions. You can install common PHP extensions by running command (change version number if you using a different one):

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 you have Apache running, execute the following commands to enable the PHP-FPM extension:

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

5. Check PHP

To verify if PHP was installed correctly, you can execute this command, which will display information about the installed version:

php -v

To display all available PHP extensions, use the following command:

php -m

6. Manually Install the Desired PHP Extension

To install any PHP extension manually, run this command (replace extension_name and version if you are using a different one)

apt install php8.3-extension_name -y

Tagged:
Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch