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 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 (replace 8.3 with the desired version if needed):
apt install -y php8.3
The installation might automatically install Apache. If you don't need it, uninstall Apache using these commands:
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 (adjust version as needed):
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 a PHP extension, run:
apt install php8.3-extension_name
If Apache is running, enable PHP-FPM with these commands:
a2enmod proxy_fcgi setenvif
systemctl restart apache2
a2enconf php8.3-fpm
systemctl reload apache2
6. Check the Installation
Verify that PHP was installed successfully:
php -v
You can also list all installed PHP extensions:
php -m
7. Restart Your Web Server (Optional)
If you’re using a web server, restart it to apply changes:
For Apache:
systemctl restart apache2
For Nginx:
systemctl restart php8.3-fpm
systemctl restart nginx