Ubuntu18.04安装LNMP环境

Ubuntu18.04安装LNMP环境

1.安装Mysql

  1. 执行安装命令

    apt-get -y install mysql-server mysql-client
    
  2. 安装完成后手动设置root密码,也可运行mysql_secure_installation,也就是mysql安全设置向导,对root密码相关进行设置。

    手动设置密码步骤:

    • use mysql;
    • update user set authentication_string=PASSWORD("你要设定的密码") where user='root';
    • update user set plugin="mysql_native_password";
    • flush privileges;
    • quit;
    • /etc/init.d/mysql restart

    3.登录root账号

    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.
    
    

    好了,mysql安装成功。

2.安装Nginx

执行nginx安装命令

sudo apt-get install -y nginx

安装完成以后查看版本

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

执行启动命令

sudo service nginx restart   

浏览器输入127.0.0.1,Welcome to nginx!安装成功。

3.安装Php

执行安装PHP命令

sudo apt-get install -y php7.2

安装完以后查看版本

php -v

出现以下信息,安装成功

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 )

安装php扩展

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

配置php.ini

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

设置 cgi.fix_pathinfo=0:

/cgi.fix_pathinfo查询,找到后将值1改为0

去除前面的“;”,也就是去掉注释

重新加载php服务

service php7.2-fpm restart

测试是否安装成功

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.配置nginx

进入Nginx默认服务器块文件目录

cd /etc/nginx/sites-available

复制该配置文件,以备不时之需

sudo cp default default.bak

编辑nginx配置文件

sudo vim default

修改41行如下:

root /var/www;

修改44行如下:

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

修改56行到63行如下:

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.设置PHP-FPM使用TCP连接

打开php配置文件

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

查找 /listen,注释掉listen=/run/php/php7.2-fpm.sock这一行,在下面加上listen=127.0.0.1:9000,将使PHP-FPM端口9000侦听的IP 127.0.0.1(本地主机)

重启php7.2-fpm:

sudo service php7.2-fpm restart

重新加载nginx

service nginx reload

新建一个php探针页面,vim /var/www/info.php ,编译如下内容:

保存之后直接访问该页面,探针页面正常显示,Ok!

5

至此,linux(ubuntu18.04)+nginx+php(7.2)-fpm+mysql(5.7)系统环境搭建成功。

猜你喜欢

转载自www.cnblogs.com/bug132294/p/12749202.html