文章目录
一. 环境说明
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
#检查配置文件
相关错误
-
访问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 ^