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 Debian

MichailMichail Moderator
edited December 11 in Linux Applications

Introduction

PHP is a popular programming language used to create dynamic websites and applications. It is widely used in web development due to its simplicity and powerful features. This article will guide you through installing PHP 8.3 on Debian versions 11 and 12.

Installation Guide

1. Update the system

Update your system by running this command:

apt update

2. Install Required Packages

Install the required packages to add a repository:

apt install -y apt-transport-https lsb-release ca-certificates wget

3. Add the PHP Repository

Run the following command to install install GnuPG and import the GPG key for the repository:

apt install -y gnupg

wget -qO - https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/php.gpg

Add the repository to your sources list:

echo "deb https://packages.sury.org/php/ $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/php.list

Update the system again:

apt update

4. Install PHP

Run this command to install PHP (to install a different version, just replace 8.3 with the desired version number):

apt install -y php8.3

The installation of PHP 8.3 might automatically install Apache. If you don't need it, you can use these commands to uninstall Apache:

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

5. Install PHP Extensions

Run this command to install common PHP extensions (you can change the version number):

apt install -y php8.3-cli php8.3-fpm php8.3-common php8.3-mysql php8.3-zip php8.3-gd php8.3-mbstring php8.3-curl php8.3-xml php8.3-bcmath php8.3-imap

To manually install PHP extensions, you can run this command (replace extension_name with actual extension name):

apt install php8.3-extension_name

If Apache is running, use these commands to enable the PHP-FPM extension:

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

6. Check the installation

Run this command to check if PHP was installed successfully:

php -v

The output should display information about the installed version:

You also can list all available PHP extensions. Use the following command:

php -m

7. Restart Your Web Server (Optional)

If you’re using a web server, restart it to apply the changes.

For Apache, run this command:

systemctl restart apache2

For Nginx, run the following command:

systemctl restart php8.3-fpm
systemctl restart nginx

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