阿里云体验实验室-5:快速搭建LNMP环境

体验地址:https://developer.aliyun.com/adc/scenario/6869de098ad44fc8a1560a1836a7c5f2

1、安装并配置MySQL

# 下载并安装MySQL
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm && \
yum -y install mysql57-community-release-el7-10.noarch.rpm && \
yum -y install mysql-community-server

# 启动 MySQL 数据库
systemctl start mysqld.service

# 查看MySQL运行状态
systemctl status mysqld.service

# 查看MySQL初始密码
grep "password" /var/log/mysqld.log

# 登录数据库
mysql -uroot -p

# 修改密码安全策略为低(只校验密码长度,至少8位)
> set global validate_password_policy=0;

# 修改MySQL默认密码
> ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';

# 授予root用户远程管理权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678';

# 退出数据库
exit

2、安装Nginx

# 安装Nginx运行所需要的插件
yum -y install gcc pcre pcre-devel zlib zlib-devel

# gcc编译器
# pcre解析正则表达式
# zlib进行gzip压缩和解压

# 下载Nginx安装包
wget http://nginx.org/download/nginx-1.17.10.tar.gz

# 解压、编译、安装Nginx
tar -zxvf nginx-1.17.10.tar.gz && \
cd nginx-1.17.10 && \
./configure && \
make && make install

# 创建软链
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

# 启动Nginx
nginx

访问测试:http://<公网IP>

3、安装PHP

# 安装PHP
yum -y install php php-mysql php-fpm

# 配置nginx.conf
vim /usr/local/nginx/conf/nginx.conf

nginx.conf文件增加如下配置


location / {
  root   html;
  index  index.html index.htm index.php;
}

if (!-e $request_filename) {
     rewrite ^/(.*)$ /index.php/$1 last;
}

location ~ .*\.php(\/.*)*$ {
     fastcgi_pass   127.0.0.1:9000;
     include       fastcgi.conf;
     fastcgi_index  index.php;
}

重启服务

# php-fpm服务
systemctl restart php-fpm

# 重启Nginx服务
nginx -s reload

创建PHP探针文件phpinfo.php

echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/phpinfo.php

访问测试: http://<公网IP>/phpinfo.php

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页