基于Nginx的动态网站环境部署(LNMP)

1、Linux部署

关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
vim /etc/selinux/config
SELINUX=disabled

2、Nginx部署
Nginx官网:http://nginx.org/en/download.html

sudo yum install yum-utils

vim /etc/yum.repos.d/nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

sudo yum-config-manager --enable nginx-mainline

sudo yum install nginx

3、php-fpm部署

yum install -y php-fpm php-mysql php-gd		安装相关工具
systemctl restart php-fpm					启动php-fpm
systemctl enable php-fpm					启动php-fpm
netstat -anpt | grep 9000					显示端口网络状态
vim /usr/share/nginx/html/index.php			编写测试页面
<?php
phpinfo();
?>
vim /etc/nginxx/conf.d/default.conf			更改Nginx子配置文件
server {
location / {
...
index index.php index.html;
...
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
systemctl restart nginx			启动Nginx

通过浏览器访问ip测试结果
在这里插入图片描述
4、mysql部署

yum -y install mariadb-server mariadb   安装数据库
systemctl start mariadb					启动数据库
systemctl enable mariadb 				开机自启
mysqladmin password '密码'				创建密码
mysql -uroot -p'密码'					登录数据库
create database bbs;					创建数据库bbs
grant all on bbs.* to 用户名@'ip地址范围' identified by '密码'; 授权给用户
flush privileges;  刷新
vim /usr/share/nginx/html/index.php		编写测试页面
<?php
$link=mysql_connect('ip','用户名','密码');
if ($link)
              echo "Successfuly";
else
              echo "Faile";
mysql_close();
?>
登录浏览器访问ip测试

5、上传网站
以WordPress为例

wget https://cn.wordpress.org/wordpress-4.9.1-zh_CN.zip		下载wordpress包
unzip wordpress-4.9.1-zh_CN.zip		解压
rm -rf /usr/share/nginx/html/index.php		删除之前编写的测试页面
cp -rf  /root/wordpress/* /usr/share/nginx/html  		把WordPress文件中的内容复制到/usr/share/nginx/html中
chown -R nginx.nginx /usr/share/nginx/html/*			更改/usr/share/nginx/html中的所有文件的属组和属主为Nginx
chmod 777 /usr/share/nginx/html/						授权/usr/share/nginx/html权限为777
在浏览器访问网站ip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值