搭建最新版本的 Linux + PHP7.2 + MySQL 8.0 + Nginx1.2 生产环境(含 Redis 4.0、Node 9.8)
开始前准备
需要准备一台云服务器(Ubuntu16.04 系统),当然你也可以使用本地虚拟机进行测试
安装 Nginx 服务器
-
SSH 远程连接服务器
-
更新软件源
-
使用该命令安装 Nginx
apt install nginx -y
4.测试一下
安装 Mysql 服务器
-
使用该命令安装 MySQL
apt install mysql-server mysql-client -y
-
看到交互页面,会提示输入密码,键入密码即可
-
测试
mysql -uroot -p
安装 PHP7.2
-
添加软件源
更新软件源
apt update
-
查询PHP版本
-
安装 PHP 7.2
-
安装成功
配置 NGINX 将 PHP 文件转发给 PHP-FPM
-
进入到配置文件目
$ cd /etc/nginx
-
文件解读
- nginx.conf 为主配置文件
- sites-available 为主机配置文件,是我们需要配置的域名等信息
- sites-enable 为主机配置文件的映射文件,其内容来源于 sites-available
-
进入
sites-available
目录,将default
修改如下(建议备份一下)server { listen 80 default_server; listen [::]:80 default_server; # SSL configuration # # listen 443 ssl default_server; # listen [::]:443 ssl default_server; # # Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782 # # Self signed certs generated by the ssl-cert package # Don't use them in a production server! # # include snippets/snakeoil.conf; root /var/www/html; # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # With php7.0-fpm: fastcgi_pass unix:/run/php/php7.2-fpm.sock; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
-
查看配置是否出错
$ nginx -t
-
进入到
/var/www/html
目录,添加index.php
文件,其内容如下<?php phpinfo();
-
重启 NGINX
$ service nginx restart
-
测试
安装 Redis
-
添加源
$ add-apt-repository ppa:chris-lea/redis-server
-
更新源
$ apt update
-
安装
[图片上传中...(image.png-2e3cb8-1523017494581-0)]$ apt install redis-server -y
测试
$ redis-cli
安装 Node
-
添加源
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash
-
更新源
$ apt update
-
安装
$ apt install nodejs -y
测试
$ node -v $ npm -v