PHP is a 25-years-old, widely-used, popular server-side scripting language that is especially suited for web development. It is known for developing dynamic and interactive web pages. The world’s most popular content management systems (CMS), such as WordPress, Joomla !, Drupal, etc. are built with PHP.
Usually, new users use shared hosting to host their websites, whereas many users (websites) use the resources of one server. Because of a resource-hungry website hosted on this type of shared server, other websites do not perform as well as expected.
Many people use Virtual Private Servers (VPS) to get rid of this problem. In the case of this type of server, the resources of the server are usually set aside for one user. In this way, every user is satisfied with the expected performance of his website by buying the package of his choice from the packages of the VPS server.
VPSs can be compared to a single empty computer, where only the user’s preferred operating system is installed. According to the type of project of the VPS user, he installs various software in his VPS.
The beta version of PHP 8.0 has recently been released. However, in this tutorial, I will show you how to install the stable version 7.4 of PHP on my Virtual Private Server (VPS) Ubuntu 20.04 operating system. The PHP 7.4 Official version is released on November 28th, 2019. I hope this tutorial works perfectly with Ubuntu 19.04, 18.04, or, 16.04.
Before We Start
To install PHP we need to have an Ubuntu Server set up with
sudo privileges. Also, to strengthen the security of this server, some initial necessary procedures have been properly completed – this needs to be ensured. These include setting a strong password for the server, setting up a basic firewall, installing Fail2Ban to keep unwanted hackers at bay, and so on.
Getting it Started
First Things First! Let’s make sure, the Ubuntu server is running on the latest package. Ubuntu will take care of it if I just run the following command in your Terminal:
sudo apt update sudo apt upgrade
This will update the server packages and update the installed packages to the latest version.
Add PPA for PHP 7.4
I shall add the ondrej/php which hosts the PHP 7.4 packages and other required PHP extensions.
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update
I have added the required PPA. At this stage, I am ready to install PHP 7.4.
Install PHP 7.4 for Apache
Execute the following command to install PHP 7.4:
sudo apt install php7.4
After the installation has been completed, you can confirm the installation using the following command:
Install PHP 7.4 FPM for Nginx
For Nginx, you need to install FPM, and execute the following command to install PHP 7.4 FPM:
sudo apt install php7.4-fpm
After the installation has been completed, let’s check to confirm that PHP 7.4 FPM has been installed correctly with the following command:
Install Required PHP 7.4 Extensions
Well, we have our PHP installed. Now, it’s time to install some required PHP extensions to run alongside PHP. To do it, I have used the following command:
sudo apt install php7.4-extension_name
Now, install some commonly used PHP extensions with the following command:
sudo apt install php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl -y
Configure PHP 7.4
Now, we configure PHP for Web Applications by changing some values in
For PHP 7.4 with Apache, the location of the php.ini file will be in the following directory:
sudo vim /etc/php/7.4/apache2/php.ini
For PHP 7.4 FPM with Nginx, the location of the php.ini file will be in the following directory:
sudo vim /etc/php/7.4/fpm/php.ini
Update the following values to give PHP some performance boost.
upload_max_filesize = 32M post_max_size = 48M memory_limit = 256M max_execution_time = 600 max_input_vars = 3000 max_input_time = 1000
Once you have modified your PHP settings, you need to restart the Apache daemon for these changes to take effect.
Configure PHP 7.4 FPM Pools
In the case of Nginx, PHP 7.4 FPM runs under a certain user and group. PHP 7.4 FPM allows you to configure the user and group. Let us change these settings.
sudo vim /etc/php/7.4/fpm/pool.d/www.conf
Change the following lines by replacing the
www-data with your actual “username”.
user = www-data group = www-data listen.owner = www-data listen.group = www-data
Save the configuration and check if the configuration is correct and restart PHP.
Restart PHP 7.4 FPM
Once you have updated your PHP FPM settings, you need to restart the daemon to apply the changes.
sudo php-fpm7.4 -t sudo service php7.4-fpm restart
Now, you are having PHP 7.4 Installed and configured.
The steps described above for installing PHP 7.4 on a VPS can only be accomplished by following some straightforward steps.
Hopefully, you can install and configure your VPS manually by following this tutorial.