记录日常点点滴滴,欢迎来到我的小站。

0%

Ubuntu16.10 部署PHP7+Nginx+MySQL网站环境

更新手顺

第一、升级当前系统数据源

1
2
sudo apt-get update
sudo apt-get upgrade

第二、安装Nginx环境

1
sudo apt-get install nginx

第三、配置Nginx基本环境

1、 替换默认配置

1
tail /etc/nginx/sites-available/default -n 13 | cut -c 2- | sudo tee /etc/nginx/sites-available/wangzhan 1> /dev/null

执行命令。如果我们自己的网站需要根据实际的需要替换掉红色的网址部分。

2、配置网站文档(/etc/nginx/sites-available/wangzhan)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 server {

listen 80;

listen [::]:80;

server_name wangzhan;

root /var/www/wangzhan;

index index.html index.php;

location / {

try_files $uri $uri/ =404;

}

}

3、创建网站文件夹目录

1
mkdir -p /var/www/wangzhan

4、启动设置

1
2
3
4
5
 sudo ln -s /etc/nginx/sites-available/wangzhan /etc/nginx/sites-enabled

sudo rm /etc/nginx/sites-enabled/default

sudo systemctl restart nginx

第四、部署PHP7

1
sudo apt-get install php7.0-cli php7.0-cgi php7.0-fpm php7.0-zip

修改配置文件(/etc/nginx/sites-available/wangzhan)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 server {

listen 80;

listen [::]:80;

server_name wangzhan ;

root /var/www/wangzhan;

index index.html index.php;

location / {

try_files $uri $uri/ =404;

}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

}

启动配置生效

1
sudo systemctl restart php7.0-fpm nginx

第五、安装MySQL数据库

1、安装自带环境包数据库

1
sudo apt-get install mysql-server php7.0-mysql

2、数据库安全配置

1
sudo mysql_secure_installation

3、启动生效

1
sudo systemctl restart php7.0-fpm

想开启局域网及外网数据库访问的方法

1
vim /etc/mysql/mysql.conf.d/mysqld.cnf

查找

1
bind-address                = 127.0.0.1

注释掉,并在终端输入

1
2
mysql -uroot -p
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

Wordpress、Wordpress二级目录的rewrite方法

WordPress:

1
2
3
4
5
6
7
8
9
10
11
12
location / {
index index.html index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}

WordPress在二级目录:

1
2
3
4
5
6
7
8
location /wp {
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite ^/wp/(.*)$ /wp/index.php;
}
}

里面的wp改成你的二级目录名称