LNMP指的是在Linux 操作系统中分别安装Nginx网页服务器、MySQL数据库服务器和PHP开发服务器,以及一些对应的扩展软件。
LNMP简单说就是:Linux+Nginx+MySQL+PHP。
相较于LAMP,LNMP使用Nginx 网页服务器取代了Apache网页服务器。Nginx是一款高性能的HTTP网页服务器和反向代理服务器,它的执行效率极高,配置相比Apache也较为简单,所以在短时间内被国内外很多大型公司所采用,大有取代 Apache 的势头(目前Apache和Ngnix使用量基本持平),这也是本文采用LNMP的原因。
在一台linux虚拟机中部署LNMP
[root@lnmp ~]# 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
[root@lnmp ~]# yum install nginx -y
[root@lnmp ~]# nginx -v
[root@lnmp ~]# systemctl start nginx
[root@lnmp ~]# systemctl enable nginx
[root@lnmp ~]# yum remove mariadb* -y
[root@lnmp ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
[root@lnmp ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
[root@lnmp ~]# yum -y install mysql-community-server
出现问题原因
如果使用的4.1以上版本的rpm的话,除了import mysql的公钥到个人用户的配置中,还需要import mysql的公钥到RPM的配置中
[root@lnmp ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
## 重新安装
[root@lnmp ~]# yum -y install mysql-community-server
[root@lnmp ~]# systemctl start mysqld.service
[root@lnmp ~]# systemctl enable mysqld.service
[root@lnmp ~]# grep "password" /var/log/mysqld.log
2023-05-27T11:51:20.800807Z 1 [Note] A temporary password is generated for root@localhost: loI_u&kgo3hq
[root@lnmp ~]# mysql -u root -p
## 初始密码:loI_u&kgo3hq
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to root@"%" identified by "Admin@123" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@lnmp ~]# yum -y remove mysql57-community-release-el7-10.noarch
[root@lnmp ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@lnmp ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@lnmp ~]# 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
[root@lnmp ~]# systemctl start php-fpm
[root@lnmp ~]# systemctl enable php-fpm
[root@lnmp ~]# php -v
PHP 7.2.34 (cli) (built: Oct 1 2020 13:37:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies
[root@lnmp ~]# cd /etc/nginx/conf.d
[root@lnmp 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;
include fastcgi_params;
}
[root@lnmp conf.d]# cd /usr/share/nginx/html
[root@lnmp html]# vim index.php
<?php
phpinfo();
?>
[root@lnmp html]# systemctl restart nginx
访问网站:http://20.0.100/index.php
[root@lnmp html]# vim index.php
<?php
$link=mysqli_connect('20.0.0.100','root','Admin@123');
if($link) echo "Success!!
";
else echo "Fail!!";
?>