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
REFERENCES
https://kenfavors.com/code/how-to-upgrade-to-php7-2-in-ubuntu/
https://www.cloudbooklet.com/install-php-7-4-on-ubuntu/
Caution with cgi.fix_pathinfo=0 when running nginx as web server.
still for now php versions above 7.0 are not supported by 16.04 xenial. So, is there any way to install php7.4 atleast in my machine that is running on 16.04 and default php version is 7.0. Please suggest any solution.
Problem : apt install php7.4-fpm
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package php7.4-fpm
E: Couldn’t find any package by glob ‘php7.4-fpm’
E: Couldn’t find any package by regex ‘php7.4-fpm’
You can add this repository:
and then try to install php7.4-fpm again.
good morning , in this part $ sudo nano /etc/nginx/sites-available/nginx_vhost , can’t find destination location , what went wrong can you help me ?
Are you sure your nginx config file is `nginx_vhost`? First, double check to see if ‘nginx_host’ is even there:
Whatever file you see there would be the nginx config file to edit.