快速搭建服务器

  1. 1. 下载 deploy.sh 脚本
  2. 2. 设置 MYSQL 密码
  3. 3. 开始安装
  4. 4. 安装完以后的配置和注意事项
    1. 4.1. 修改站点目录权限
    2. 4.2. 添加站点的 Nginx 配置

下载 deploy.sh 脚本

14.04安装脚本
wget https://raw.githubusercontent.com/summerblue/laravel-ubuntu-init/master/deploy.sh

16.04安装脚本
wget https://raw.githubusercontent.com/summerblue/laravel-ubuntu-init/master/deploy-16.sh

设置 MYSQL 密码

vi deploy.sh:

1
2
3
4
# Configure
MYSQL_ROOT_PASSWORD=""
MYSQL_NORMAL_USER="estuser"
MYSQL_NORMAL_USER_PASSWORD=""

开始安装

有需要的话可以使用网易镜像加速:
wget http://mirrors.163.com/.help/sources.list.trusty -O /etc/apt/sources.list

运行脚本:

1
2
chmod +x deploy.sh
./deploy.sh

注:请使用 root 运行。

安装完以后的配置和注意事项

修改站点目录权限

通过此脚本配置的 Nginx 将使用 www 用户权限,因此需要在你的站点根目录下运行以下命令更新权限。

1
2
cd /var/www/
chown www:www -R ./

添加站点的 Nginx 配置

下面是站点的 Nginx 配置模板,写入按照域名命名的文件中,并放入到 /etc/nginx/sites-enabled 目录下。
如:/etc/nginx/sites-enabled/phphub.org

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
server {
listen 80;
server_name YOU-DOMAIN-NAME;
root YOU-PROJECT-FOLDER;
index index.php index.html index.htm;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /data/log/nginx/YOU-PROJECT-NAME-access.log;
error_log /data/log/nginx/YOU-PROJECT-NAME-error.log error;
sendfile off;
client_max_body_size 100m;
include fastcgi.conf;
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass /run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

或者直接修改default

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm;
server_name _;
charset utf-8;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/default.access.log;
error_log /var/log/nginx/default.error.log error;
sendfile off;
client_max_body_size 100m;
include fastcgi.conf;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
# fastcgi_pass unix:/var/run/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}