Skip to content

Commit 2df47d6

Browse files
committed
add ubuntu 16 ver
1 parent a2531ed commit 2df47d6

File tree

1 file changed

+204
-0
lines changed

1 file changed

+204
-0
lines changed

deploy-16.sh

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

0 commit comments

Comments
 (0)