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 " --"
0 commit comments