By default, if we install PHP on Ubuntu 24.04, it will automatically choose PHP 8.3.x.
But, how if we want to install PHP 8.0 on ubuntu 24.04 ?
Install PHP 8.0 / PHP 8.0 FPM on Ubuntu 24.04
For the information, i have Ubuntu 24.04
lsb_release -a
To install PHP 8.0 / PHP 8.0 FPM, we need to leverage ondrej/php. Here are complete steps:
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update
And to install PHP run this command, enter Y
sudo apt-get install php8.0
Or in case you want to install php8.0 with FPM mode, run:
sudo apt-get install php8.0-fpm
After installed, you can check PHP version by typing:
php -v
Or checking PHP FPM version and status:
php-fpm8.0 --version
systemctl php8.0-fpm status
If you want to install another php-extension, you can do with this command:
apt-get install php8.0-mbstring php8.0-gd php8.0-curl
PHP 8.0 configuration
PHP 8.0 is stored in /etc/php/8.0/
ls -al /etc/php/8.0
If you want to configure PHP for apache, go to apache2 folder and see php.ini
vi /etc/php/8.0/apache2/php.ini
In this example, we are going to modify some parameters:
memory_limit = 256M
max_execution_time = 60
post_max_size = 10M
And to take the effect, just restart your apache webserver
systemctl restart apache2
PHP 8.0 FPM configuration is also stored in /etc/php/8.0/ inside folder: fpm
Test phpinfo() on browser
To ensure PHP 8.0 works on browser, test with creating a file phpinfo.php inside /var/www/html
cd /var/www/html
Create phpinfo.php and paste this code in it:
<?php
phpinfo();
?>
Run on browser:
http://<your ip public>/phpinfo.php
If the output is not like above (phpinfo.php is downloaded instead of showing the result). That means you have missing libapache2-mod-php8.0
. So you need to install it:
apt-get install libapache2-mod-php8.0
Then restart your apache webserver:
systemctl restart apache2
Run on the browser again, it should work now.
http://<your ip public>/phpinfo.php