Linux Mint 19 installs PHP7.3 and configures with nginx

Posted by mrdance on Fri, 27 Dec 2019 09:07:42 +0100

1, Update Linux Mint 19 system

Make sure that you are running the latest version of Linux Mint. If there are important programs running and you do not want to upgrade them, you can only update the package list and run the following command:

sudo apt update
sudo apt upgrade

If a newer version of Kernel is installed, it is recommended to restart after the upgrade:

sudo reboot

2, Adding the PHP 7.3 repository to Linux Mint 19

Since Linux Mint 19 is based on Ubuntu 18.04, the repository to be added is for Ubuntu 18.04.

Add the ondrej/php PPA repository, which contains the PHP 7.3 package and other necessary PHP extensions:

sudo add-apt-repository ppa:ondrej/php

sudo apt update

Note: with the continuous update of Linux Mint 19, PHP version 7.3 may be provided in the future. This step can be omitted at that time.

3, Installing PHP 7.3 on Linux Mint 19

After adding the repository, install PHP 7.3 by running the following command on the terminal:

sudo apt-get install php7.3

You can check the version using the php - command:

$ php -v
PHP 7.3.1-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Jan 13 2019 10:19:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.1, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.1-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

 

4, Install PHP 7.3 extension

Use the following command to install the PHP 7.3 extension:

sudo apt-get install php7.3-<entension-name>

For example:

sudo apt install php7.3-cli php7.3-json php7.3-pdo php7.3-mysql php7.3-zip php7.3-gd  php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath

You can use the apt policy command to confirm the installed PHP extension version:

$ apt policy php7.3-gd
php7.3-gd:
Installed: 7.3.1-1+ubuntu18.04.1+deb.sury.org+1
Candidate: 7.3.1-1+ubuntu18.04.1+deb.sury.org+1
Version table:
*** 7.3.1-1+ubuntu18.04.1+deb.sury.org+1 500
500 http://ppa.launchpad.net/ondrej/php/ubuntu bionic/main amd64 Packages
100 /var/lib/dpkg/status

5, Installing PHP7.3-FPM on Linux Mint

If you are using Nginx Web Server and you need to install php7.3-fpm to provide PHP pages, run the following command:

sudo apt install php7.3-fpm

The PHP FPM configuration file is located in the / etc/php/7.3/fpm/ folder.

After installing PHP, it is recommended to restart the Web server:

For Apache:

sudo systemctl restart apache2

For Nginx:

sudo systemctl restart nginx

So far, PHP7.3-FPM installation is completed.

Note here: the path of PHP configuration file php.ini will vary with the PHP version, so the command to find the php.ini file location is as follows

php -i | grep php.ini

The command means: php-i displays the details of PHP, and then matches the information of php.ini. As shown in the above figure, the path is / etc/php/7.2/cli/php.ini. The PHP configuration files used to set up the environment are / etc/php/7.3/cli/php.ini and / etc/php/7.3/apache2/php.ini.

Now build a PHP file to see if you can run normally.

vim /var/www/html/info.php

Then press i again to enter the editing mode, and input the contents of the file as follows

<?php

phpinfo();

?>

Save the changes and access them in the browser

http://localhost/info.php

The PHP version 7.3.13-1 + Ubuntu 18.04.1 + deb.sury.org + 1 page appears.

Finally, there is a small place. Because nginx and php are turned off by default for cgi.fix ﹐ pathinfo. That is to say, you can't use pathinfo if you don't open it. But if it is opened, there will be serious loopholes. So make a little modification so that you can use pathinfo with cgi.fix? Pathinfo turned off.

open

sudo vi /etc/nginx/sites-available/default
          #. PHP $is changed to. PHP, which is to remove the $after PHP.
location ~ \.php {
                include snippets/fastcgi-php.conf;
        #       Increase the support for PathInfo to prevent cgi.fix'PathInfo vulnerability.
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
sudo systemctl restart nginx

Finally, install swoole.

WARNING: channel "pecl.php.net" has updated its protocols, use "pecl channel-update pecl.php.net" to update

First, determine whether to install pecl and phpize if not

sudo apt install php-pear
sudo apt install php7.3-dev //I use php7.3 here. Please refer to your version number for details

After the above dependencies are installed, execute the

sudo pecl install swoole

swoole will be installed automatically

Then, according to how to find php.ini mentioned above, find the php.ini configuration file location
Add to the configuration file of php cli(/etc/php/7.3/cli/php.ini)

extension=swoole.so

Restart php service and web server service

Topics: PHP sudo Linux Nginx