LNMP部署
基础环境
系统环境:CentOS Stream 9
软件环境:nginx-1.20.1、mysql-8.0.36(mariaDB)、php-8.0.30
部署过程
方案一:yum安装
步骤一:配置安全策略
1 | # 开放80端口 |
步骤二:安装nginx
1 | yum -y install nginx |
步骤三:安装并配置mysql
安装mysql
1 | yum -y install mysql-server |
配置mysql
(1)查看root用户的初始密码
1 | grep 'password' /var/log/mysql/mysqld.log |
2024-05-08T09:37:31.765242Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the —initialize-insecure option.
(2)配置MySQL的安全性
1 | mysql_secure_installation |
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?设置MySQL的新密码
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file设置的密码强度
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.New password:
Re-enter new password:
Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.删除匿名用户
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.Normally, root should only be allowed to connect from
‘localhost’. This ensures that someone cannot guess at
the root password from the network.禁止使用root用户远程登录MySQL
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.By default, MySQL comes with a database named ‘test’ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.删除test库以及用户对test库的访问权限
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database…
Success.- Removing privileges on test database…
Success.Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.重新加载授权表
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.All done!
步骤四:安装php
1 | # 下载php组件 |
修改nginx配置文件以启用php
1 | # 备份Nginx配置文件 |
配置并验证php
1 | # 保证 nginx 进程的管理用户和 PHP 服务进程的管理用户保持一致 |
步骤五:访问测试
在浏览器中输入http://本机ip/index.php
进行访问,如下图所示,表示LNMP环境部署成功。
方案二:脚本一键安装
1 | yum install -y wget |
在浏览器http://本机ip/
访问,出现以下界面,即为部署成功。
打开lnmp2.1/conf/nginx.conf文件,查看其网站根目录为/home/wwwroot/default,
在其网站根目录/home/wwwroot/default中# 编写测试php界面,在浏览器中输入http://本机ip/index.php
进行访问,结果如方案一中的《步骤五》中的图所示,即为成功。
1 | echo "<?php echo phpinfo(); ?>" >/data/index.php |