LNMP搭建环境并且使用LNMP搭建网上博客(网站)

一.准备编译环境
1.关闭防火墙 查看防火墙状态

如果防火墙的状态参数是inactive,则防火墙为关闭状态。
如果防火墙的状态参数是active,则防火墙为开启状态。本示例中防火墙为开启状态,因此需要关闭防火墙
systemctl status firewalld #查看防火墙状态
systemctl disable firewalld #永久关闭防火墙

2.关闭SELinux 查看SELinux的当前状态。

getenforce #查看状态
setenforce 0 #关闭

二.安装Nginx

yum -y install nginx #安装Nginx
nginx -v #查看安装版本 如下结果安装成功
			nginx version: nginx/1.16.1

三.安装MySQL

 #更新YUM源
rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

#运行以下命令安装MySQL
yum -y install mysql-community-server

#查看安装版本号  如下结果安装成功
mysql -V
		mysql  Ver 14.14 Distrib 5.7.28, for Linux (x86_64) using  EditLine wrapper
		
#运行以下命令启动MySQL
systemctl start mysqld

#设置开机启动MySQL
systemctl enable mysqld
systemctl daemon-reload

四.安装php

#更新YUM源
yum install \
https://repo.ius.io/ius-release-el7.rpm \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
以上直接全部复制 执行即可

#运行以下命令添加Webtatic源
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

#安装php
yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache php70w-pecl-redis php70w-pecl-mongodb

#查看版本 返回如下结果,表示安装成功
php -v
PHP 7.0.33 (cli) (built: Dec  6 2018 22:30:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies                

五.配置Nginx

#备份Nginx配置文件
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak

修改Nginx配置文件,添加Nginx对PHP的支持
#打开Nginx配置文件
vim /etc/nginx/nginx.conf
#在server大括号内,修改或添加下列配置信息
1.修改
location / {
            index index.php index.html index.htm;
        }
2.添加
location ~ .php$ {
            root /usr/share/nginx/html;    #将/usr/share/nginx/html替换为您的网站根目录,本教程使用/usr/share/nginx/html作为网站根目录。
            fastcgi_pass 127.0.0.1:9000;   #Nginx通过本机的9000端口将PHP请求转发给PHP-FPM进行处理。
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;   #Nginx调用fastcgi接口处理PHP请求。
        }      

#保存文件之后退出(:wq) 并且启动Nginx服务
systemctl start nginx 

#运行以下命令设置Nginx服务开机自启动
systemctl enable nginx

效果图:

在这里插入图片描述
六.配置MySQL

#获取并记录root用户的初始密码
grep 'temporary password' /var/log/mysqld.log
返回结果如下:
2016-12-13T14:57:47.535748Z 1 [Note] A temporary password is generated for root@localhost: p0/G28g>lsHD

#运行以下命令配置MySQL的安全性  
mysql_secure_installation

       以下: 一直输入大写的Y !!!!!

1.重置root密码
Enter password for user root: #输入上一步获取的root用户初始密码
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration of the plugin.
Using existing password for root.
Estimated strength of the password: 100 
Change the password for root ? (Press y|Y for Yes, any other key for No) : Y #是否更改root用户密码,输入Y
New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #再次输入新密码
Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

七.配置php

#运行以下命令新建文件  网站根目录:/usr/share/nginx/html !!!
vim /usr/share/nginx/html/phpinfo.php

#运行以下命令启动PHP-FPM
systemctl start php-fpm

#运行以下命令设置PHP-FPM开机自启动
systemctl enable php-fpm

浏览器访问:http://<ECS实例公网IP地址>/phpinfo.php
效果图:
在这里插入图片描述
八.搭建wordpress

#启动数据库
systemctl start mysqld.service

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

#登录数据库  密码为之前自己修改的密码
mysql -uroot -p

#进入Mysql数据库之后创建wordpress数据库
create database wordpress; 

#查看是否创建成功 即出现wordpress数据库表
show databases;

#退出数据库  exit

#安装wordpress
yum -y install wordpress

#修改WordPress配置文件
	# 进入/usr/share/wordpress目录。
	cd /usr/share/wordpress
	# 修改路径。
	ln -snf /etc/wordpress/wp-config.php wp-config.php
	# 查看修改后的目录结构。
	ll
移动WordPress到Nginx根目录
	# 在Nginx的根目录/usr/share/nginx/html下,创建一个wp-blog文件夹。
	mkdir /usr/share/nginx/html/wp-blog
	mv * /usr/share/nginx/html/wp-blog

#修改wp-config.php文件
    database_name_here为之前步骤中创建的数据库名称,本示例为wordpress。
    username_here为MySQL数据库的用户名,本示例为root。
    password_here为MySQL数据库的登录密码,本示例为NewPassWord1.。
sed -i 's/database_name_here/wordpress/' /usr/share/nginx/html/wp-blog/wp-config.php
sed -i 's/username_here/root/' /usr/share/nginx/html/wp-blog/wp-config.php
sed -i 's/password_here/NewPassWord1./'/usr/share/nginx/html/wp-blog/wp-config.php

#查看是否修改正确
cat -n /var/www/html/wp-blog/wp-config.php

#重启Nginx服务
systemctl start nginx

#浏览器访问页面  
http://<ECS公网IP>/wp-blog/wp-admin/install.php

完成!!!

效果图:
在这里插入图片描述

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值