Centos 7.5 安装LNMP平台
一台Centos 7.5虚拟机
安装软件包
[root@localhost /]# yum install -y epel-*
[root@localhost /]# yum install -y nginx mariadb-server php php-mysql \
> php-fpm \php-xml php-pecl-zip php-json php-devel wget vim
配置nginx支持PHP
- 创建nginx的web主目录
- [root@localhost /]# mkdir /var/wwwroot
- [root@localhost /]# cd /var/wwwroot/
- [root@localhost wwwroot]# echo -e hello_world >> index.html
- [root@localhost wwwroot]# echo -e "<?php phpinfo(); ?>" >> info.php
- [root@localhost wwwroot]# ls
2、编辑nginx的配置文件
[root@localhost /]# vim /etc/nginx/nginx.conf
3、修改nginx主目录和索引
将http下的server下的root的值修改为/var/wwwroot
在http下的server下添加index index.php index.html index.htm
4.在http下的server区块加入以下内容
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
5.启动nginx和php-fpm
[root@localhost ~]# systemctl start nginx php-fpm
[root@localhost ~]# systemctl enable nginx php-fpm
[root@localhost ~]# systemctl status nginx php-fpm
6.关闭防火墙
[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
7.在宿主机访问nginx
访问 http://[centos_ip]/info.php
配置MySQL
- 启动MySQL
[root@localhost /]# systemctl start mariadb
[root@localhost /]# systemctl enable mariadb
- 输入以下命令,配置MySQL
[root@localhost /]# mysql_secure_installation
- 提示 Enter current password for root (enter for none):
敲击回车
4.提示Set root password? [Y/n]
按Y,随后设置密码
密码设置:123(生产环境尽量不要使用弱口令密码)
5.提示Remove anonymous users?
意思是否删除匿名用户
6.提示Disallow root login remotely?
意思是远程禁止root登录吗?
7.提示Remove test database and access to it?
意思为删除测试数据库吗?
- 提示Reload privilege tables now?
意思是现在重新加载特权表吗?
9.登录mysql数据库
[root@localhost /]# mysql -u root -p
MariaDB [(none)]> show databases;
下载WorldPress测试LNMP环境
- 下载WordPress
[root@localhost ~]# cd /var/www/root/
[root@localhost wwwroot]# rm -rf index.html
[root@localhost wwwroot]# rm -rf info.php
[root@localhost wwwroot]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
[root@localhost wwwroot]# tar -zxvf wordpress-4.9.4-zh_CN.tar.gz
[root@localhost wwwroot]# cd wordpress/
[root@localhost /]# cp -r /var/wwwroot/wordpress/* /var/wwwroot/
[root@localhost /]# cd /var/wwwroot/
[root@localhost wwwroot]# ll
- 登录mysql创建数据库
[root@localhost wwwroot]# mysql -u root -p
#创建一个wordperss数据库
MariaDB [(none)]> CREATE DATABASE wordpress;
在宿主机访问nginx服务器
访问http://[centos_ip]/
按提示安装即可