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