Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install PHP on Ubuntu 24.04

Install PHP and the extra modules you need with APT, and remove it again if you want.

VPS and Cloud Servers2 min read6 screenshots

Step 1: Update the system

sudo apt update
Updating the system packages

Step 2: Install PHP

sudo apt install php -y
Installing PHP

This installs PHP and, if there is no web server yet, Apache with libapache2-mod-php. If you use Nginx, install PHP-FPM instead: sudo apt install php-fpm.

Step 3: Check the install

php -v
The PHP version

Step 4: Install PHP modules (optional)

The pattern is php-<module>:

sudo apt install php-{module_name}

Install several at once:

sudo apt install php-{mysql,gd,xml,curl,mbstring,zip}

Show the loaded modules:

php -m
The installed PHP modules

If you use Apache, restart it after you add modules: sudo systemctl restart apache2. With PHP-FPM, restart php8.3-fpm.

Step 5: Uninstall PHP

Remove PHP and its settings:

sudo apt remove --purge php
Removing PHP

Remove all the PHP packages (use the wildcard with care):

sudo apt remove --purge 'php*'

Clean up the packages that are no longer needed:

sudo apt autoremove
Removing unused packages

Change settings

The main file for the command line is /etc/php/8.3/cli/php.ini. For Apache it is /etc/php/8.3/apache2/php.ini and for PHP-FPM /etc/php/8.3/fpm/php.ini. Common values to change: memory_limit, upload_max_filesize, post_max_size and max_execution_time.

Quick recap

  • sudo apt install php, then php -v.
  • Add modules with sudo apt install php-<module>.
  • Remove with sudo apt remove --purge php.