LNMP搭建(ubuntu18)

本文详细介绍了如何在Ubuntu 18.04上搭建LNMP环境,包括安装Nginx、Mysql和PHP 7.2,重点讨论了Nginx的配置,如解决php文件被下载的问题,配置FastCGI与php-fpm的通信,以及Mysql的安全设置和外部访问权限的开放。
摘要由CSDN通过智能技术生成

一. 环境说明

Ubuntu系统版本:Ubuntu 18.04.4

nginx安装版本:nginx/1.14.0 (Ubuntu)

mysql版本:5.7.30-0ubuntu0.18.04.1 (Ubuntu)

PHP版本:PHP 7.2.24-0ubuntu0.18.04.6

二. 安装Nginx

root@lnmp:~#apt-get install nginx
...............
root@lnmp:~# nginx -v
nginx version: nginx/1.14.0 (Ubuntu)

三. 安装Mysql

root@lnmp:~# apt-get install mysql-server
#查看安装结果
root@lnmp:~# systemctl status mysql
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-05-30 18:48:38 CST; 36min ago
 Main PID: 7616 (mysqld)
    Tasks: 28 (limit: 4665)
   CGroup: /system.slice/mysql.service
           └─7616 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

5月 30 18:48:38 lnmp systemd[1]: Starting MySQL Community Server...
5月 30 18:48:38 lnmp systemd[1]: Started MySQL Community Server.
#登录mysql 
root@lnmp:~# mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.30-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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

四. 安装PHP

#安装指定版本,请指定版本号
root@lnmp:~# apt-get install php
#查看安装结果
root@lnmp:~# php -v
PHP 7.2.24-0ubuntu0.18.04.6 (cli) (built: May 26 2020 13:09:11) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.24-0ubuntu0.18.04.6, Copyright (c) 1999-2018, by Zend Technologie

五. 配置Nginx

相关配置文件

  • /etc/nginx/nginx.conf
  • /etc/nginx/sites-available/default

Nginx配置文件结构可参考Nginx 配置详解

相关命令

nginx -s reload
#重启nginx服务
nginx -s stop
#停止nginx服务
nginx -t 
#检查配置文件

相关错误

  1. 访问php后缀页面提示下载文件,而不是正常显示php文件执行后的结果。

    原因是nginx配置文件中未配置php解析需要的相关参数。

    网上博文提示修改/etc/nginx/nginx.conf文件,在http结构块内添加server块。

在这里插入图片描述

server {
   
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name _;
        location / {
   
                index index.html index.htm index.php l.php;
                autoindex off;
        }
        location ~ \.php(.*)$ {
   
                #fastcgi_pass 127.0.0.1:9000;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                fastcgi_index index.php;
                fastcgi_split_path_info ^
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值