Blog about Web Programming and Electronics
💬 👤
back Back to blog
Linux

Installing and upgrading PHP on Linux Ubuntu/Debian

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 new installation and switching to the latest stable version.

Installing PHP

  1. Open the terminal and update system packages:
    sudo apt update && sudo apt upgrade
  2. Install PHP:
    sudo apt install php
  3. Verify the installation:
    php -v

    The current version of PHP should be displayed.

  4. 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 the Latest PHP Version

  1. Add Ondřej Surý PPA (repository for the latest PHP):
    sudo add-apt-repository ppa:ondrej/php -y
  2. Update package lists and install the latest available version:
    sudo apt update
    sudo apt install php php-cli php-common php-curl php-mbstring php-xml php-zip
  3. Set PHP as the default version in the system:
    sudo update-alternatives --install /usr/bin/php php /usr/bin/php8.3 83
    sudo update-alternatives --set php /usr/bin/php8.3

    Note: If you want to use a specific version, replace php8.3 with the name of the installed version (e.g., php8.5). For automatic identification, you can use the command ls /usr/bin/php*.

  4. Check the active version:
    php -v

    The output should show the installed PHP version.

back Back to blog