一、安装配置Nginx
1、安装
[[email protected] /]# yum install -y epel-* 安装第三方epel源
[[email protected] /]# yum update 更新yum源
[[email protected] /]# yum -y install nginx*6
2、查看Nginx版本
[[email protected] /]# nginx -v
nginx version: nginx/1.16.1
3、备份Nginx文件
[[email protected] /]# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
4、进入编辑配置文件,提供Nginx对php的支持
[[email protected] html]# vi /etc/nginx/nginx.conf
LNMP网站搭建
5、设置开机自启
[[email protected] html]# systemctl start nginx
[[email protected] html]# systemctl enable nginx
二、安装mysql
1、更新yum源
[[email protected] /]# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2、安装mysql
[[email protected] /]# yum -y install mysql-community-server
[[email protected] /]# mysql -V 查看版本号
[[email protected] /]# systemctl start mysqld 启动数据库
[[email protected] /]# systemctl enable mysqld && systemctl daemon-reload 设为开机自启
[[email protected] /]# cat /var/log/mysqld.log |grep password 查看初始密码
3、进入数据库修改密码策略
[[email protected] /]# mysql -uroot -p
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
4、更改密码
mysql> ALTER USER ‘root’@’%’ IDENTIFIED BY ‘123456’;
mysql> flush privileges; 刷新
三、安装php
1、更新yum源添加epl
[[email protected] /]# yum install \

https://repo.ius.io/ius-release-el7.rpm
https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
2、添加webtatic源
[[email protected] /]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
3、安装php
[[email protected] /]# 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
[[email protected] /]# php -v 查看版本
4、新建index.php用于展示php信息
[[email protected] /]# vi /usr/share/nginx/html/index.php
LNMP网站搭建
5、启动php-fpm服务并设置开机自启
[[email protected] /]# systemctl start php-fpm
[[email protected] /]# systemctl enable php-fpm
6、配置动静分离
[[email protected] /]# vi /etc/nginx/nginx.conf
server {
listen 80;
server_name www.wordpress.com;
location / {
root /usr/share/nginx/html/wordpress;
index index.php index.html index.htm;
}
location ~* ..(php|php5)?$ {
root /usr/share/nginx/html/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
[[email protected] /]# nginx -t 测试语法错误
7、}编辑php与mysql连通性测试文件,并进行测试
(1)连接mysql数据库
[[email protected] /]# mysql -h localhost -u root -p
(2)创建wordpress数据库
mysql> create database wordpress;
(3)授权
mysql> grant all on wordpress.
to ‘wordpress’@‘localhost’ identified by ‘123456’; mysql> flush privileges;
(4)编写php与数据库测试连通性文件
[[email protected] /]# vi /usr/share/nginx/html/index-mysql.php

<?php $link = mysqli_connect('localhost', 'wordpress', '123456'); if (!$link) { die('Could not connect: ' . mysqli_error()); } echo 'Connected successfully'; mysqli_close($link); ?>

(5)测试成功
LNMP网站搭建
四、部署网站
1、传入wordpress网站包并解压
[[email protected] /]# tar xzf wordpress-4.9.4-zh_CN.tar.gz
[[email protected] /]# chmod -R o+w /usr/share/nginx/html/ 授予可写权限
2、编辑虚拟主机配置文件
[[email protected] /]# vi /etc/nginx/conf.d/wordpress.conf
server {
listen 80;
server_name www.wordpress.com;
location / {
root /usr/share/nginx/html/wordpress;
index index.php index.html index.htm;
}
location ~* .*.(php|php5)?$ {
root /usr/share/nginx/html/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}

}
3、测试语法
[[email protected] /]# nginx -t
4、重新加载配置
[[email protected] /]# nginx -s reload
5、修改host文件
加上:77.0.0.7 www.wordpress.com
6、上下文授权
[[email protected] html]# getenforce
Enforcing
[[email protected] html]# chcon -R --reference=/usr/share/nginx/html /usr/share/nginx/html/wordpress
7、访问成功http://www.wordpress.com
LNMP网站搭建

相关文章:

  • 2018-01-08
  • 2021-09-14
  • 2019-09-17
  • 2021-10-08
  • 2021-04-30
猜你喜欢
  • 2022-12-23
  • 2021-11-04
  • 2021-10-19
  • 2021-05-27
  • 2021-06-18
  • 2022-12-23
  • 2021-12-13
相关资源
相似解决方案