This article shows how to install php7.4 on ubuntu 22.04 | 20.04, a guide to config php7.4-fpm on ubuntu, and optimizing PHP, php7.4-fpm on Linux.
Stepby-step: Install php7.4 on Ubuntu 22.04 and 20.04 LTS
PHP 7.4, and php7.4-fpm on Linux is the latest stable version available. If you want to install a specific PHP version or multiple versions (Multiple versions of PHP), then this article may be useful for you. This article guides you to install php7.4, and php7.4-fpm on ubuntu, and Linux using PPA. And similar versions php7.3, php7.2, php5.6.
Step 1: Add PPA repository and install PHP
The following dependent packages will need to be installed, most of which are already on Ubuntu 20.04 | 22.04, but running the command below can help ensure they are installed.
sudo apt install software-properties-common sudo add-apt-repository ppa:ondrej/php
Next, update the system and install PHP 7.4 on ubuntu 22.04 | 20.04
sudo apt-get update sudo apt install php7.4 -y
Change php7.4 if you want to install another version, for example, php7.3, php7.2
Step 2: Install php7.4-fpm on Ubuntu 22.04
You can also install modules based on your application requirements. Use the following command to search for ubuntu php7.4 modules available in the package repository.
sudo apt-cache search php7*
You can install php7.4 on ubuntu Ubuntu 20.04 | 22.04 the necessary modules on your system. Just change the PHP version with the package name according to your requirement:
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 php7.4-fpm php7.4-json php7.4-zip php7.4-bcmath php7.4-mcrypt
Enable php-fpm and allow php-fpm to start with the system:
sudo systemctl enable php7.4-fpm sudo service php7.4-fpm restart
Step 3: Configure php7.4-fpm on Ubuntu Linux
Open the directory under the path /etc/php/7.4/fpm/pool.d and edit the file www.conf
.
- user = itsmeit
- listen.owner = itsmeit
+ itsmeit is the username on your operating system that allows it to manage PHP. The default is www-data but you should change it. Save the file and reset php-fpm ( change your PHP version number)
+ listen is the communication port between PHP and Nginx, you need to check that the value of listening is correctly installed in Nginx with separate configs.
sudo service php7.4-fpm restart
Step 4: Optimization php7.4-fpm on Ubuntu
Next, come the optimization and configuration of php.ini, navigate to the variables and edit the values to suit your needs. You need to edit both files as below, then find the values and change them.
sudo gedit /etc/php/7.4/cli/php.ini sudo gedit /etc/php/7.4/fpm/php.ini
— Reference timezone link: https://www.php.net/manual/en/timezones.php
Save the file and reset php-fpm for the config to take effect, don’t forget to change your PHP version number.
sudo service php7.4-fpm restart
Step 5. Config multiple PHP versions on Ubuntu / Linux
You can also install and use multiple PHP versions for each website (project). The command changes the default PHP version, just enter the version number.
sudo update-alternatives --config php
This article guide you on how to install php7.4 on Ubuntu 22.04 | 20.04, if you want to install multiple versions just change the version number. For example php7.4, php7.3, etc.
– Advertising –
Thank admin, bài viết rất chi tiết