目录
一.nginx 的yum安装
1.关闭防火墙
2. 安装 nginx
3.安装依赖包
4.启动服务
二. 安装 mysql 5.7 (mariadb)
1.nysal的yum安装
2. 启动服务
3.在日志文件中找出root用户的初始密码
4.登录 mysql
5. 停止版本更新,稳定数据库的运行
三.php 的yum安装
1.php.安装 php7.2
2. 安装相关的依赖拓展模块
3. 做备份
4. 修改php的默认配置
5. 保存配置后并重启服务
四.lnmp的连接测试
1. lnmp的连接测试
创建php页面测试,进行访问测试
2.测试结果
浏览器访问: http://192.168.158.22/index.php
3. 测试mysql是否能连接成功
4.测试最终结果
一.nginx 的yum安装
1.关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
2. 安装 nginx
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
3.安装依赖包
yum -y install nginx
nginx -v #查看版本号
4.启动服务
systemctl start nginx
systemctl enable nginx
二. 安装 mysql 5.7 (mariadb)
1.nysal的yum安装
yum remove mariadb* -y
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo
yum -y install mysql-server
2. 启动服务
systemctl start mysqld.service
systemctl enable mysqld.service
systemctl status mysqld.service
3.在日志文件中找出root用户的初始密码
两种查看密码的方式
[root@localhost yum.repos.d]# grep "password" /var/log/mysqld.log
2023-06-24T15:09:31.610581Z 1 [Note] A temporary password is generated for root@localhost: k5ljEsDKha_w
[root@localhost yum.repos.d]# grep "password" /var/log/mysqld.log | awk '{print $NF}'
k5ljEsDKha_w
#初始密码为:k5ljEsDKha_w
4.登录 mysql
[root@localhost yum.repos.d]# mysql -uroot -p
Enter password: n<17S<NvqF,x #输入密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123'; #密码设置要求有 大小写字母、数字和符号 组合
grant all privileges on *.* to root@"%" identified by "Admin@123" with grant option;
flush privileges;
quit #退出即可
5. 停止版本更新,稳定数据库的运行
#为了防止每次yum操作都会自动更新,卸载这个软件
yum -y remove mysql57-community-release-el7-10.noarch
三.php 的yum安装
1.php.安装 php7.2
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
2. 安装相关的依赖拓展模块
yum -y install php72w \
php72w-cli\
php72w-common\
php72w-devel\
php72w-embedded\
php72w-gd\
php72w-mbstring\
php72w-pdo\
php72w-xml\
php72w-fpm\
php72w-mysqlnd\
php72w-opcache \
php72w-redis
systemctl start php-fpm
systemctl enable php-fpm
php -v
3. 做备份
#更改配置文件前 先做个备份
cd /etc/nginx/conf.d
default.conf default.conf.bak
4. 修改php的默认配置
//配置 nginx 支持 PHP 解析
cd /etc/nginx/conf.d
vim default.conf
......
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; #将 /scripts 修改为nginx的工作目录
include fastcgi_params;
}
5. 保存配置后并重启服务
systemctl restart nginx
四.lnmp的连接测试
1. lnmp的连接测试
创建php页面测试,进行访问测试
cd /usr/share/nginx/html
vim index.php
<?php
phpinfo();
?>
2.测试结果
浏览器访问: http://192.168.158.22/index.php
3. 测试mysql是否能连接成功
vim /usr/share/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.158.22','root','Admin@123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>
4.测试最终结果
浏览器访问: http://192.168.158.22/index.php