Ubuntu 18.04 install LNMP environment

Ubuntu 18.04 install LNMP environment

1. Install Mysql

  1. Execute installation command

    apt-get -y install mysql-server mysql-client
    
  2. After the installation is complete, set the root password manually, or you can run mysql_secure_installation, which is the mysql security setup wizard, to set the root password.

    Steps to set password manually:

    • use mysql;
    • update user set authentication_string = PASSWORD ("The password you want to set") where user = 'root';
    • update user set plugin="mysql_native_password";
    • flush privileges;
    • quit;
    • /etc/init.d/mysql restart

    3. Log in to the root account

    root@s0ld1er-virtual-machine:/home/s0ld1er# mysql -u root -p 
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)
    
    Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    

    Well, mysql installation is successful.

2. Install Nginx

Execute nginx installation command

sudo apt-get install -y nginx

Check the version after installation

root@s0ld1er-virtual-machine:/home/s0ld1er# nginx -v
nginx version: nginx/1.14.0 (Ubuntu)

Execute start command

sudo service nginx restart   

Enter 127.0.0.1 in the browser and the Welcome to nginx! Installation is successful.

3. Install Php

Execute install php command

sudo apt-get install -y php7.2

Check the version after installation

php -v

The following message appears, the installation is successful

root@s0ld1er-virtual-machine:/home/s0ld1er# php -v
PHP 7.2.24-0ubuntu0.18.04.4 (cli) (built: Apr  8 2020 15:45:57) ( NTS )

Install php extension

sudo apt-get install -y php7.2-fpm php7.2-mysql php7.2-curl php7.2-json php7.2-mbstring php7.2-xml php7.2-intl php7.2-zip php7.2-gd php7.2-opcache php7.2-common php7.2-cli

Configure php.ini

vim /etc/php/7.2/fpm/php.ini

Set cgi.fix_pathinfo = 0:

/cgi.fix_pathinfo query, change the value 1 to 0 when found

Remove the previous ";", that is, remove the comment

Reload php service

service php7.2-fpm restart

Test whether the installation is successful

root@s0ld1er-virtual-machine:/home/s0ld1er# sudo php-fpm7.2 -t
[22-Apr-2020 00:02:13] NOTICE: configuration file /etc/php/7.2/fpm/php-fpm.conf test is successful

4. Configure nginx

Enter the Nginx default server block file directory

cd /etc/nginx/sites-available

Copy the configuration file in case you need it from time to time

sudo cp default default.bak

Edit nginx configuration file

sudo vim default

Modify line 41 as follows:

root /var/www;

Modify 44 lines as follows:

index index.php index.html index.htm index.nginx-debian.html;

Modify lines 56 to 63 as follows:

location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        #

        # # With php-fpm (or other unix sockets):

        # fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;

        # # With php-cgi (or other tcp sockets):

        fastcgi_pass 127.0.0.1:9000;
    }

5. Set PHP-FPM to use TCP connection

Open php configuration file

vim /etc/php/7.2/fpm/pool.d/www.conf

Find / listen, comment out the line listen = / run / php / php7.2-fpm.sock, add listen = 127.0.0.1: 9000 below, it will make PHP-FPM port 9000 listen to IP 127.0.0.1 local host)

Restart php7.2-fpm:

sudo service php7.2-fpm restart

Reload nginx

service nginx reload

Create a new php probe page, vim /var/www/info.php, compile the following content:

After saving, directly access this page, the probe page displays normally, Ok!

5

At this point, the linux (ubuntu18.04) + nginx + php (7.2) -fpm + mysql (5.7) system environment has been successfully built.

Guess you like

Origin www.cnblogs.com/bug132294/p/12749202.html