PHP is the heart of your web server. In a Linux environment (Ubuntu or Debian), installing and maintaining PHP via the terminal is fast and efficient. Below are the steps for a fresh installation and upgrading to the latest stable version 8.3.
Installing PHP
- Open the terminal and update your system packages:
sudo apt update && sudo apt upgrade - Install PHP (version 8.3 is recommended):
sudo apt install php - Verify the installation:
php -vThe current PHP version should be displayed.
- Install common extensions (for database work, XML, ZIP, etc.):
sudo apt install php-cli php-mbstring php-curl php-xml php-zip php-mysql
Upgrading to PHP 8.3
- Add the Ondřej Surý PPA (repository for the latest PHP):
sudo add-apt-repository ppa:ondrej/php -y - Update lists and install version 8.3:
sudo apt update sudo apt install php8.3 php8.3-cli php8.3-common php8.3-curl php8.3-mbstring php8.3-xml php8.3-zip - Register and set PHP 8.3 as the default version:
sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.3 83 sudo update-alternatives --set php /usr/bin/php8.3 - Verify the active version:
php -vThe output should now show PHP 8.3.x.