How To Upgrade To PHP7.4-FPM in Ubuntu 16.04/18.04
This will upgrade your php version to php7.4-fpm when using Nginx web server.
Check your PHP version:
$ php -v
1. Install PHP 7.4
$ sudo apt install php7.4-fpm
2. Install additional modules
$ 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
3. Update config files
Open the file located at /etc/php/7.4/fpm/pool.d/www.conf
:
$ sudo nano /etc/php/7.4/fpm/pool.d/www.conf
Find the lines below:
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp
and delete the semi-colons so that it looks like this:
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
Ctrl+x to exit, then ‘Y' to save and exit.
Then, open the file located at /etc/php/7.4/fpm/php.ini
:
$ sudo nano /etc/php/7.4/fpm/php.ini
find (Ctrl+w) and change the following to your desired settings:
max_execution_time = 300
memory_limit = 512M
post_max_size = 100M
upload_max_filesize = 100M
and find the line:
;cgi.fix_pathinfo=1
and delete the semicolon and set to 0:
cgi.fix_pathinfo=0
Ctrl+x to exit, then ‘Y' to save and exit.
3. Web server configuration
Make sure that your web server correctly uses the PHP 7.4 sockets/modules. Edit your nginx config to change the socket paths (substituting ‘nginx_vhost' with your correct filename, i.e. ‘default'):
$ sudo nano /etc/nginx/sites-available/nginx_vhost
For example, change the lines below from php7.3 to php7.4:
...
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
...
Ctrl+x, then ‘y' to save and exit. Restart PHP and Nginx:
$ sudo systemctl restart php7.4-fpm
$ sudo service nginx restart
4. Change the default PHP version
If you have multiple PHP versions installed on your Ubuntu server, you can set PHP 7.2 as the default:
$ sudo update-alternatives --set php /usr/bin/php7.4
Link: