PHP is an open source server-side scripting language majorly used in development of web applications. The syntax of PHP is similar to C and Java, making it easier to learn for developers with prior experience in those languages. There is a vast community of developers behind the build and success of PHP. You can use PHP to build automation scripts, create a personal website, or adopting it for the development of large enterprise-grade applications. As a developer you can easily create interactive and dynamic web apps by leveraging PHP support for standards such as CSS, HTML, and JavaScript.
Today we shall perform the installation, configuration, and basic usage of PHP 8.3 on Debian 12 or Debian 11 machine. PHP 8.3 is a major update of the PHP language. This release comes with many new features. Here’s a general guidance on the installation of PHP 8.3 on Debian 12 or Debian 11 Linux system.
Before we can do the installation of PHP 8.3, it’s good idea to update system’s package lists.
sudo apt update
1) Add PPA repository with PHP 8.3 packages
The default Debian repository might not contain the latest PHP releases. For this reason we’re adding a PPA repository. Install some dependencies required to operate the repo.
sudo apt update
sudo apt install software-properties-common lsb-release apt-transport-https ca-certificates -y
Now import repository GPG key after installing the packages.
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
Next run the commands below to enable sury PPA repository on your Debian system.
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
Confirm the repository is functional.
$ sudo apt update
Hit:1 http://security.debian.org/debian-security bookworm-security InRelease
Hit:2 http://deb.debian.org/debian bookworm InRelease
Hit:3 http://deb.debian.org/debian bookworm-updates InRelease
Hit:4 http://mirror.hetzner.com/debian/packages bookworm InRelease
Get:5 https://packages.sury.org/php bookworm InRelease [7,539 B]
Hit:6 http://mirror.hetzner.com/debian/packages bookworm-updates InRelease
Hit:7 http://mirror.hetzner.com/debian/security bookworm-security InRelease
Get:8 https://packages.sury.org/php bookworm/main amd64 Packages [221 kB]
Fetched 228 kB in 1s (208 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
You can list available PHP versions.
$ sudo apt list -a php
Listing... Done
php/bookworm 2:8.3+94+0~20240205.51+debian12~1.gbp6faa2e all
php/stable,stable 2:8.2+93 all
2. Install PHP 8.3 on Debian 12 or Debian 11
Once the OS package lists are updated, installation of PHP 8.3 can be done by executing the commands given below.
sudo apt install php8.3
Hit the y or <Enter> key in your keyboard to proceed with the installation.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
apache2-bin debsuryorg-archive-keyring libapache2-mod-php8.3 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 liblua5.3-0 libperl5.36 libsodium23 perl
perl-modules-5.36 php-common php8.3-cli php8.3-common php8.3-opcache php8.3-readline psmisc
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom www-browser php-pear perl-doc libterm-readline-gnu-perl | libterm-readline-perl-perl make libtap-harness-archive-perl
Recommended packages:
apache2
The following NEW packages will be installed:
apache2-bin debsuryorg-archive-keyring libapache2-mod-php8.3 libapr1 libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-ldap libgdbm-compat4 liblua5.3-0 libperl5.36 libsodium23 perl
perl-modules-5.36 php-common php8.3 php8.3-cli php8.3-common php8.3-opcache php8.3-readline psmisc
0 upgraded, 20 newly installed, 0 to remove and 5 not upgraded.
Need to get 14.0 MB of archives.
After this operation, 78.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
After the installation, verify it is installed properly by checking the version.
$ php -v
php --version
PHP 8.3.2-1+0~20240120.16+debian12~1.gbpb43448 (cli) (built: Jan 20 2024 14:14:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.2, Copyright (c) Zend Technologies
with Zend OPcache v8.3.2-1+0~20240120.16+debian12~1.gbpb43448, Copyright (c), by Zend Technologies
3. Install PHP 8.3 extensions
PHP extensions are libraries designed to give extra functionalities to the PHP programming language. Identify the extensions you need, and install them using apt. The command syntax is:
sudo apt install php8.3-<extension>
- Replace <extension> with the name of PHP extension to be installed.
Example that install cli,zip,mysql,bz2,curl,mbstring,intl,common
PHP extensions.
sudo apt install php8.3-{cli,zip,bz2,mysql,curl,mbstring,intl,common}
4. Using PHP with Apache or Nginx web server
Other web servers are also available but we only demonstrate the usage of PHP with Nginx and Apache web server.
1) Using PHP 8.3 with Apache
In Apache, PHP code will be executed using the mod_php module, which is built into Apache. Just install Apache web server and its php module.
sudo apt install apache2 libapache2-mod-php8.3
Remember to enable mod_php module that will process PHP code:
sudo a2enmod php8.3
Finally restart apache2
sudo systemctl restart apache2
2) Using PHP 8.3 with Nginx
You will need to install PHP-FPM (FastCGI Process Manager) alongside nginx.
sudo apt install nginx php8.3-fpm
Update Nginx configuration so that it forwards incoming requests to PHP-FPM, using the FastCGI protocol.
$ sudo vim /etc/nginx/nginx.conf
server {
listen 80;
server_name mysite.example.com;
root /var/www/mysite;
index index.php index.html;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
}
}
Validate nginx syntax.
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart nginx web server.
sudo systemctl restart nginx
Books to read on web development:
- Best Books to learn Web Development – PHP, HTML, CSS, JavaScript and jQuery
- Best Books To Master Web Design
- Best Books To Learn CSS & CSS3
- Best Books To Learn HTML & HTML5
- Best Apache and Nginx reference Books