-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlemp_magento.sh
266 lines (182 loc) · 9.87 KB
/
lemp_magento.sh
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#!/bin/bash
#### Installation script to setup Ubuntu, Nginx, Percona, Php-fpm
#### By Philip N. Deatherage, Deatherage Web Development
#### www.dwdonline.com
pause(){
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n'
}
echo "---> WELCOME! FIRST WE NEED TO MAKE SURE THE SYSTEM IS UP TO DATE!"
pause
apt-get update
apt-get -y upgrade
echo "---> NOW, LET'S BUILD THE ESSENTIALS AND INSTALL ZIP/UNZIP"
pause
apt-get update
apt-get -y install build-essential zip unzip
echo "---> Let's add a new admin user and block the default root from logging in:"
pause
read -e -p "---> What would you like your new admin user to be?: " -i "" NEW_ADMIN
read -e -p "---> What should the new admin password be?: " -i "" NEW_ADMIN_PASSWORD
read -e -p "---> What should we make the SSH port?: " -i "" NEW_SSH_PORT
adduser ${NEW_ADMIN} --disabled-password --gecos ""
echo "${NEW_ADMIN}:${NEW_ADMIN_PASSWORD}"|chpasswd
gpasswd -a ${NEW_ADMIN} sudo
sed -i "s,PermitRootLogin yes,PermitRootLogin no,g" /etc/ssh/sshd_config
sed -i "s,Port 22,Port ${NEW_SSH_PORT},g" /etc/ssh/sshd_config
service ssh restart
echo "---> ALRIGHT, NOW WE ARE READY TO INSTALL THE GOOD STUFF!"
pause
echo "---> INSTALLING NGINX AND PHP-FPM"
nginx=development
add-apt-repository ppa:nginx/$nginx
apt-get -y update
add-apt-repository -y ppa:ondrej/php5-5.6
apt-get -y update
apt-get -y install php5-fpm php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-intl php5-xsl libperl-dev libpcre3 libpcre3-dev libssl-dev php5-gd libgd2-xpm-dev libgeoip-dev libgd2-xpm-dev nginx
echo "---> NOW, LET'S COMPILE NGINX WITH PAGESPEED"
pause
cd
wget -q https://github.com/pagespeed/ngx_pagespeed/archive/master.zip
unzip master.zip
cd ngx_pagespeed-master
wget -q https://dl.google.com/dl/page-speed/psol/1.11.33.0.tar.gz
tar -xzvf 1.11.33.0.tar.gz # expands to psol/
cd
wget -q http://nginx.org/download/nginx-1.9.14.tar.gz
tar -xzvf nginx-1.9.14.tar.gz
cd nginx-1.9.14
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --with-http_stub_status_module --user=www-data --group=www-data --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_image_filter_module --add-module=$HOME/ngx_pagespeed-master --with-ipv6 --with-http_geoip_module --with-http_realip_module;
make
make install
service nginx restart
echo "---> INSTALLING PERCONA"
pause
echo
read -e -p "---> What do you want your MySQL root password to be?: " -i "password" MYSQL_ROOT_PASSWORD
apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
echo "deb http://repo.percona.com/apt trusty main" >> /etc/apt/sources.list
echo "deb-src http://repo.percona.com/apt trusty main" >> /etc/apt/sources.list
touch /etc/apt/preferences.d/00percona.pref
echo "Package: *" >> /etc/apt/preferences.d/00percona.pref
echo "Pin: release o=Percona Development Team" >> /etc/apt/preferences.d/00percona.pref
echo "Pin-Priority: 1001" >> /etc/apt/preferences.d/00percona.pref
apt-get -y update
export DEBIAN_FRONTEND=noninteractive
echo "percona-server-server-5.6 percona-server-server/root_password password ${MYSQL_ROOT_PASSWORD}" | sudo debconf-set-selections
echo "percona-server-server-5.6 percona-server-server/root_password_again password ${MYSQL_ROOT_PASSWORD}" | sudo debconf-set-selections
apt-get -y install percona-server-server-5.6 percona-server-client-5.6
echo "---> NOW, LET'S SETUP SSL. YOU'LL NEED TO ADD YOUR CERTIFICATE LATER"
pause
echo
read -e -p "---> What will your domain name be (without the www): " -i "domain.com" MY_DOMAIN
cd "/etc/ssl/"
mkdir "sites"
cd "sites"
openssl genrsa -out ${MY_DOMAIN}.key 2048
openssl req -new -key ${MY_DOMAIN}.com.key -out ${MY_DOMAIN}.com.csr
cd
echo "---> OK, WE ARE DONE SETTING UP THE SERVER. LET'S PROCEED TO CONFIGURING THE NGINX HOST FILES FOR MAGENTO AND WORDPRESS"
pause
#### Install nginx configuration
#### IT WILL REMOVE ALL CONFIGURATION FILES THAT HAVE BEEN PREVIOUSLY INSTALLED.
NGINX_EXTRA_CONF="error_page.conf extra_protect.conf export.conf hhvm.conf headers.conf maintenance.conf multishop.conf pagespeed.conf spider.conf"
NGINX_EXTRA_CONF_URL="https://raw.githubusercontent.com/magenx/nginx-config/master/magento/conf.d/"
echo "---> CREATING NGINX CONFIGURATION FILES NOW"
echo
read -e -p "---> Enter your domain name (without www.): " -i "myshop.com" MY_DOMAIN
read -e -p "---> Enter your web root path: " -i "/var/www/html" MY_SHOP_PATH
read -e -p "---> Enter your web user usually www-data (nginx for Centos): " -i "www-data" MY_WEB_USER
wget -qO /etc/nginx/port.conf https://raw.githubusercontent.com/magenx/nginx-config/master/magento/port.conf
wget -qO /etc/nginx/fastcgi_params https://raw.githubusercontent.com/magenx/nginx-config/master/magento/fastcgi_params
wget -qO /etc/nginx/nginx.conf https://raw.githubusercontent.com/magenx/nginx-config/master/magento/nginx.conf
sed -i "s/www/sites-enabled/g" /etc/nginx/nginx.conf
mkdir -p /etc/nginx/sites-enabled
mkdir -p /etc/nginx/sites-available && cd $_
wget -q https://raw.githubusercontent.com/magenx/nginx-config/master/magento/www/default.conf
wget -q https://raw.githubusercontent.com/magenx/nginx-config/master/magento/www/magento.conf
sed -i "s/example.com/${MY_DOMAIN}/g" /etc/nginx/sites-available/magento.conf
sed -i "s,root /var/www/html,root ${MY_SHOP_PATH},g" /etc/nginx/sites-available/magento.conf
sed -i "s,user nginx,user ${MY_WEB_USER},g" /etc/nginx/nginx.conf
sed -i "s,listen = /var/run/php5-fpm.sock,listen = 127.0.0.1:9000,g" /etc/php5/fpm/pool.d/www.conf
ln -s /etc/nginx/sites-available/magento.conf /etc/nginx/sites-enabled/magento.conf
ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf
cd /etc/nginx/conf.d/
for CONFIG in ${NGINX_EXTRA_CONF}
do
wget -q ${NGINX_EXTRA_CONF_URL}${CONFIG}
done
sed -i "s,pagespeed FileCachePath,#pagespeed FileCachePath,g" /etc/nginx/conf.d/pagespeed.conf
sed -i "s,pagespeed LogDir,#pagespeed LogDir,g" /etc/nginx/conf.d/pagespeed.conf
sed -i '/http {/a ## Pagespeed module\n pagespeed FileCachePath "/var/tmp/";\n pagespeed LogDir "/var/log/pagespeed";\n pagespeed ProcessScriptVariables on;\n' /etc/nginx/nginx.conf
read -p "Would you like to install Adminer for managing your MySQL databases now? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
cd "/var/www/html"
wget -q https://www.adminer.org/static/download/4.2.4/adminer-4.2.4-mysql.php
mv adminer-4.2.4-mysql.php adminer.php
else
exit 0
fi
echo "---> Let's install PostFix to handle sending mail:"
pause
read -e -p "---> What would you like your host to be? I like it to be something like mail.domain.com: " -i "" POSTFIX_SERVER
debconf-set-selections <<< "postfix postfix/mailname string ${POSTFIX_SERVER}"
debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
apt-get install -y postfix
read -p "Would you like to install Magento now?<y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
cd "/var/www/html"
rm "index.nginx-debian.html"
wget -q https://www.dwdonline.com/magento-1.9.2.4-2016-02-23-06-04-07.tar.gz
tar -xzvf magento-1.9.2.4-2016-02-23-06-04-07.tar.gz --strip 1
rm magento-1.9.2.4-2016-02-23-06-04-07.tar.gz
echo
read -e -p "---> What do you want to name your Magento MySQL database?: " -i "magento1924" MYSQL_DATABASE
read -e -p "---> What do you want to name your Magento MySQL user?: " -i "magento1924user" MYSQL_USER
read -e -p "---> What do you want your Magento MySQL password to be?: " -i "Yn3f3nDf" MYSQL_USER_PASSWORD
ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
echo "Please enter your MySQL root password below:"
mysql -u root -p -e "CREATE database ${MYSQL_DATABASE}; CREATE user '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_USER_PASSWORD}'; GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_USER_PASSWORD}';"
echo "Your database name is: ${MYSQL_DATABASE}"
echo "Your database user is: ${MYSQL_USER}"
echo "Your databse password is: ${MYSQL_USER_PASSWORD}"
else
exit 0
fi
read -p "Would you like to install WordPress now? <y/N> " prompt
if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]
then
cd "/var/www/html"
wget -q https://wordpress.org/latest.zip
unzip latest.zip
mv wordpress blog
echo
read -e -p "---> What do you want to name your WordPress MySQL database?: " -i "" WP_MYSQL_DATABASE
read -e -p "---> What do you want to name your WordPress MySQL user?: " -i "" WP_MYSQL_USER
read -e -p "---> What do you want your WordPress MySQL password to be?: " -i "" WP_MYSQL_USER_PASSWORD
echo "Please enter your MySQL root password below:"
mysql -u root -p -e "CREATE database ${MYSQL_DATABASE}; CREATE user '${WP_MYSQL_USER}'@'localhost' IDENTIFIED BY '${WP_MYSQL_USER_PASSWORD}'; GRANT ALL PRIVILEGES ON ${WP_MYSQL_DATABASE}.* TO '${WP_MYSQL_USER}'@'localhost' IDENTIFIED BY '${WP_MYSQL_USER_PASSWORD}';"
echo "Your database name is: ${WP_MYSQL_DATABASE}"
echo "Your database user is: ${WP_MYSQL_USER}"
echo "Your databse password is: ${WP_MYSQL_USER_PASSWORD}"
else
exit 0
fi
echo "---> Last thing, let's set the permissions for Magento and WordPresss:"
pause
echo "Lovely, this may take a few minutes. Dont fret."
cd "/var/www/html"
chown -R www-data.www-data *
find . -type f -exec chmod 400 {} \;
find . -type d -exec chmod 500 {} \;
find var/ -type f -exec chmod 600 {} \;
find media/ -type f -exec chmod 600 {} \;
find var/ -type d -exec chmod 700 {} \;
find media/ -type d -exec chmod 700 {} \;
chmod 700 includes
chmod 600 includes/config.php
chmod 777 "/var/www/html/app/etc"
find blog/wp-content/ -type f -exec chmod 600 {} \;
find blog/wp-content/ -type d -exec chmod 700 {} \;
echo "I just saved you a shitload of time and headache. You're welcome."