Skip to content

Commit c524b9c

Browse files
committed
init
0 parents  commit c524b9c

File tree

2 files changed

+305
-0
lines changed

2 files changed

+305
-0
lines changed

deploy.sh

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
#!/usr/bin/env bash
2+
3+
export DEBIAN_FRONTEND=noninteractive
4+
5+
# Check if user is root
6+
[ $(id -u) != "0" ] && { echo "${CFAILURE}Error: You must be root to run this script${CEND}"; exit 1; }
7+
8+
# Configure
9+
MYSQL_ROOT_PASSWORD=""
10+
MYSQL_NORMAL_USER="estuser"
11+
MYSQL_NORMAL_USER_PASSWORD=""
12+
13+
# Check if password is defined
14+
if [[ "$MYSQL_ROOT_PASSWORD" == "" ]]; then
15+
echo "${CFAILURE}Error: MYSQL_ROOT_PASSWORD not define!!${CEND}";
16+
exit 1;
17+
fi
18+
if [[ "$MYSQL_NORMAL_USER_PASSWORD" == "" ]]; then
19+
echo "${CFAILURE}Error: MYSQL_NORMAL_USER_PASSWORD not define!!${CEND}";
20+
exit 1;
21+
fi
22+
23+
# Add www user and group
24+
addgroup www
25+
useradd -g www -d /home/www -c "www data" -m -s /usr/sbin/nologin www
26+
27+
# Update Package List
28+
29+
apt-get update
30+
31+
# Update System Packages
32+
33+
apt-get -y upgrade
34+
35+
# Force Locale
36+
37+
echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
38+
locale-gen en_US.UTF-8
39+
40+
# Install Some PPAs
41+
42+
apt-get install -y software-properties-common curl
43+
44+
apt-add-repository ppa:nginx/development -y
45+
apt-add-repository ppa:chris-lea/redis-server -y
46+
apt-add-repository ppa:ondrej/php -y
47+
48+
# gpg: key 5072E1F5: public key "MySQL Release Engineering <mysql-build@oss.oracle.com>" imported
49+
apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 5072E1F5
50+
sh -c 'echo "deb http://repo.mysql.com/apt/ubuntu/ trusty mysql-5.7" >> /etc/apt/sources.list.d/mysql.list'
51+
52+
curl --silent --location https://deb.nodesource.com/setup_5.x | bash -
53+
54+
# Update Package Lists
55+
56+
apt-get update
57+
58+
# Install Some Basic Packages
59+
60+
apt-get install -y build-essential dos2unix gcc git libmcrypt4 libpcre3-dev \
61+
make python2.7-dev python-pip re2c supervisor unattended-upgrades whois vim libnotify-bin
62+
63+
# Set My Timezone
64+
65+
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
66+
67+
# Install PHP Stuffs
68+
69+
apt-get install -y --force-yes php7.0-cli php7.0 \
70+
php-pgsql php-sqlite3 php-gd php-apcu \
71+
php-curl php7.0-mcrypt \
72+
php-imap php-mysql php-memcached php7.0-readline php-xdebug \
73+
php-mbstring php-xml php7.0-zip php7.0-intl php7.0-bcmath
74+
75+
# Install Composer
76+
77+
curl -sS https://getcomposer.org/installer | php
78+
mv composer.phar /usr/local/bin/composer
79+
80+
# Add Composer Global Bin To Path
81+
printf "\nPATH=\"$(composer config -g home 2>/dev/null)/vendor/bin:\$PATH\"\n" | tee -a ~/.profile
82+
83+
# Set Some PHP CLI Settings
84+
85+
sudo sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/7.0/cli/php.ini
86+
sudo sed -i "s/display_errors = .*/display_errors = On/" /etc/php/7.0/cli/php.ini
87+
sudo sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/cli/php.ini
88+
sudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/cli/php.ini
89+
90+
# Install Nginx & PHP-FPM
91+
92+
apt-get install -y --force-yes nginx php7.0-fpm
93+
94+
# Setup Some PHP-FPM Options
95+
96+
sed -i "s/error_reporting = .*/error_reporting = E_ALL \& ~E_NOTICE \& ~E_STRICT \& ~E_DEPRECATED/" /etc/php/7.0/fpm/php.ini
97+
sed -i "s/display_errors = .*/display_errors = Off/" /etc/php/7.0/fpm/php.ini
98+
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/7.0/fpm/php.ini
99+
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/7.0/fpm/php.ini
100+
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 50M/" /etc/php/7.0/fpm/php.ini
101+
sed -i "s/post_max_size = .*/post_max_size = 50M/" /etc/php/7.0/fpm/php.ini
102+
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.0/fpm/php.ini
103+
sed -i "s/listen =.*/listen = 127.0.0.1:9000/" /etc/php/7.0/fpm/pool.d/www.conf
104+
105+
# Setup Some fastcgi_params Options
106+
107+
cat > /etc/nginx/fastcgi_params << EOF
108+
fastcgi_param QUERY_STRING \$query_string;
109+
fastcgi_param REQUEST_METHOD \$request_method;
110+
fastcgi_param CONTENT_TYPE \$content_type;
111+
fastcgi_param CONTENT_LENGTH \$content_length;
112+
fastcgi_param SCRIPT_FILENAME \$request_filename;
113+
fastcgi_param SCRIPT_NAME \$fastcgi_script_name;
114+
fastcgi_param REQUEST_URI \$request_uri;
115+
fastcgi_param DOCUMENT_URI \$document_uri;
116+
fastcgi_param DOCUMENT_ROOT \$document_root;
117+
fastcgi_param SERVER_PROTOCOL \$server_protocol;
118+
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
119+
fastcgi_param SERVER_SOFTWARE nginx/\$nginx_version;
120+
fastcgi_param REMOTE_ADDR \$remote_addr;
121+
fastcgi_param REMOTE_PORT \$remote_port;
122+
fastcgi_param SERVER_ADDR \$server_addr;
123+
fastcgi_param SERVER_PORT \$server_port;
124+
fastcgi_param SERVER_NAME \$server_name;
125+
fastcgi_param HTTPS \$https if_not_empty;
126+
fastcgi_param REDIRECT_STATUS 200;
127+
EOF
128+
129+
# Set The Nginx & PHP-FPM User
130+
131+
sed -i "s/user www-data;/user www;/" /etc/nginx/nginx.conf
132+
sed -i "s/# server_names_hash_bucket_size.*/server_names_hash_bucket_size 64;/" /etc/nginx/nginx.conf
133+
134+
sed -i "s/user = www-data/user = www/" /etc/php/7.0/fpm/pool.d/www.conf
135+
sed -i "s/group = www-data/group = www/" /etc/php/7.0/fpm/pool.d/www.conf
136+
137+
sed -i "s/listen\.owner.*/listen.owner = www/" /etc/php/7.0/fpm/pool.d/www.conf
138+
sed -i "s/listen\.group.*/listen.group = www/" /etc/php/7.0/fpm/pool.d/www.conf
139+
sed -i "s/;listen\.mode.*/listen.mode = 0666/" /etc/php/7.0/fpm/pool.d/www.conf
140+
141+
service nginx restart
142+
service php7.0-fpm restart
143+
144+
# Install Node
145+
146+
apt-get install -y nodejs
147+
/usr/bin/npm install -g gulp
148+
/usr/bin/npm install -g bower
149+
150+
# Install SQLite
151+
152+
apt-get install -y sqlite3 libsqlite3-dev
153+
154+
# Install MySQL
155+
156+
debconf-set-selections <<< "mysql-community-server mysql-community-server/root-pass password ${MYSQL_ROOT_PASSWORD}"
157+
debconf-set-selections <<< "mysql-community-server mysql-community-server/re-root-pass password ${MYSQL_ROOT_PASSWORD}"
158+
apt-get install -y mysql-server --force-yes
159+
160+
# Configure MySQL Password Lifetime
161+
162+
echo "default_password_lifetime = 0" >> /etc/mysql/my.cnf
163+
164+
sed -i '/^bind-address/s/bind-address.*=.*/bind-address = 0.0.0.0/' /etc/mysql/my.cnf
165+
166+
mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "CREATE USER '${MYSQL_NORMAL_USER}'@'0.0.0.0' IDENTIFIED BY '${MYSQL_NORMAL_USER_PASSWORD}';"
167+
mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "GRANT ALL ON *.* TO '${MYSQL_NORMAL_USER}'@'127.0.0.1' IDENTIFIED BY '${MYSQL_NORMAL_USER_PASSWORD}' WITH GRANT OPTION;"
168+
mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "GRANT ALL ON *.* TO '${MYSQL_NORMAL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_NORMAL_USER_PASSWORD}' WITH GRANT OPTION;"
169+
mysql --user="root" --password="${MYSQL_ROOT_PASSWORD}" -e "FLUSH PRIVILEGES;"
170+
service mysql restart
171+
172+
# Add Timezone Support To MySQL
173+
174+
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql --user=root --password=${MYSQL_ROOT_PASSWORD} mysql
175+
176+
# Install A Few Other Things
177+
178+
apt-get install -y redis-server memcached beanstalkd
179+
180+
# Configure Beanstalkd
181+
182+
sed -i "s/#START=yes/START=yes/" /etc/default/beanstalkd
183+
/etc/init.d/beanstalkd start
184+
185+
# Enable Swap Memory
186+
187+
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
188+
/sbin/mkswap /var/swap.1
189+
/sbin/swapon /var/swap.1
190+
191+
clear
192+
echo "--"
193+
echo "--"
194+
echo "It's Done."
195+
echo "Mysql Root Password: ${MYSQL_ROOT_PASSWORD}"
196+
echo "Mysql Normal User: ${MYSQL_NORMAL_USER}"
197+
echo "Mysql Normal User Password: ${MYSQL_NORMAL_USER_PASSWORD}"
198+
echo "--"
199+
echo "--"

readme.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
2+
## 说明
3+
4+
此脚本用于在一台全新的 Ubuntu 14.04 LTS 上部署适合 Laravel 使用的 LNMP 生产环境。
5+
6+
## 软件信息
7+
8+
* Ubuntu 16.04
9+
* Git
10+
* PHP 7.0
11+
* Nginx
12+
* MySQL
13+
* Sqlite3
14+
* Composer
15+
* Node (With PM2, Bower, Grunt, and Gulp)
16+
* Redis
17+
* Memcached
18+
* Beanstalkd
19+
20+
## 预计安装时间
21+
22+
视网络情况而定,平均安装需要 15 分钟左右。
23+
24+
## 安装步骤
25+
26+
1). 运行以下命令,生成 `deploy.sh` 脚本文件
27+
28+
```
29+
touch ~/deploy.sh
30+
chmod +x ~/deploy.sh
31+
```
32+
33+
<img src="http://7xrxcg.com1.z0.glb.clouddn.com/dc0b2cee0ff1abfe63465beb69067d10.png" width="600">
34+
35+
2). 将 [服务器部署脚本](https://coding.net/u/estgroup/p/est-docs/git/blob/master/%E5%9B%A2%E9%98%9F%E6%96%87%E6%A1%A3/%E5%BC%80%E5%8F%91%E6%8A%80%E5%B7%A7/%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2%E8%84%9A%E6%9C%AC/deploy.sh) 里的内容复制到 `deploy.sh` 文件里,并修改 5 - 7 行的配置。
36+
37+
![](media/14618913496721.jpg)
38+
39+
3). 直接运行 `~/deploy.sh` 文件, 会看到安装程序开始执行了
40+
41+
<img src="http://7xrxcg.com1.z0.glb.clouddn.com/d23db6f3040931d8c60c2b2b262bdc62.png">
42+
43+
## 安装完以后的配置和注意事项
44+
45+
### 1. 修改站点目录权限
46+
47+
通过此脚本配置的 Nginx 将使用 www 用户权限,因此需要在你的站点根目录下运行以下命令更新权限。
48+
49+
```
50+
cd /data/www/{你的网站目录}
51+
chown www:www -R ./
52+
```
53+
54+
### 2. 添加站点的 nginx 配置
55+
56+
下面是站点的 nginx 配置模板,写入按照域名命名的文件中,并放入到 `/etc/nginx/sites-enabled` 目录下。
57+
58+
如:`/etc/nginx/sites-enabled/phphub.org`
59+
60+
```
61+
server {
62+
listen 80;
63+
server_name {你的域名};
64+
root "{站点根目录}";
65+
66+
index index.html index.htm index.php;
67+
68+
charset utf-8;
69+
70+
location / {
71+
try_files $uri $uri/ /index.php?$query_string;
72+
}
73+
74+
location = /favicon.ico { access_log off; log_not_found off; }
75+
location = /robots.txt { access_log off; log_not_found off; }
76+
77+
access_log /data/log/nginx/{你的网站标识}-access.log;
78+
error_log /data/log/nginx/{你的网站标识}-error.log error;
79+
80+
sendfile off;
81+
82+
client_max_body_size 100m;
83+
84+
include fastcgi.conf;
85+
86+
location ~ /\.ht {
87+
deny all;
88+
}
89+
90+
location ~ \.php$ {
91+
fastcgi_pass 127.0.0.1:9000;
92+
#fastcgi_pass /run/php/php7.0-fpm.sock;
93+
fastcgi_index index.php;
94+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
95+
include fastcgi_params;
96+
}
97+
}
98+
```
99+
100+
配置完以后重启 nginx 即可。
101+
102+
```
103+
service nginx restart
104+
```
105+
106+

0 commit comments

Comments
 (0)