-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapache2-php7-install.sh
executable file
·176 lines (119 loc) · 4.8 KB
/
apache2-php7-install.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
#!/bin/bash
if [ $UID -ne 0 ] ; then
echo " 403 Error !!. Please run me as root"
exit
fi
echo "#################################################################################################################"
echo "# #"
echo "# Welcome!! This script will install php-backend eviroment #"
echo "# #"
echo "#################################################################################################################"
echo -e "\n\n\n"
echo " Updating System files... "
echo -e "\n\n\n"
apt-get update -y
echo -e "\n\n\n"
echo " Done Updating... "
echo -e "\n\n\n";
echo " Installing Apache... "
# Install apache2
apt-get install -y apache2
apt-get install libapache2-mod-php7.0 -y
apt-get install libapache2-modsecurity -y
echo -e "\n\n\n"
echo " Apache Installed "
echo -e "\n\n\n"
echo " Installing PHP 7..."
echo -e "\n\n\n"
#install php7
apt-get -y install php7.0*
apt-get remove php7.0-snmp -y
echo -e "\n\n\n"
echo " PHP 7 Installed. "
echo -e "\n\n\n"
echo -e "\n\n\n"
echo " Installing MySql Client... "
echo -e "\n\n\n"
# install MySql
apt-get install -y mysql-client
echo -e "\n\n\n"
echo " Mysql client installed"
echo -e "\n\n\n"
# Enable Various module's
echo "Enabling Various Modules"
a2enmod php7.0
a2enconf php7.0-fpm
a2enmod rewrite
a2enmod proxy_fcgi setenv
a2enmod headers
a2enmod mod-security
echo -e "\n\n\n"
echo " Required Modules Enabled"
echo -e "\n\n\n"
# Increase post_max_size to 20 M
sed -i 's/post_max_size = 8M/post_max_size = 20M/' /etc/php/7.0/apache2/php.ini
#Increase upload_max_size
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 20M/' /etc/php/7.0/apache2/php.ini
#Increase KeepAliveTimeout
sed -i 's/KeepAliveTimeout 5/KeepAliveTimeout 60/' /etc/apache2/apache2.conf
# Making Apache Server Secure
echo " Header set X-XSS-Protection "1; mode=block" " >> /etc/apache2/apache2.conf
echo "Header always set X-Content-Type-Options "nosniff" " >>/etc/apache2/apache2.conf
echo 'Header always set Strict-Transport-Security "max-age=63072000;includeSubDomains"' >>/etc/apache2/apache2.conf
# Stop Click JAcking
echo "Header always append X-Frame-Options SAMEORIGIN" >> /etc/apache2/apache2.conf
# Stop displaying Apache Version
echo "ServerSignature Off" >> /etc/apache2/apache2.conf
# Show servertoken as Apache
echo "ServerTokens Prod" >> /etc/apache2/apache2.conf
#Disable Etag
echo "FileETag None" >>/etc/apache2/apache2.conf
#Disable Trace
echo " TraceEnable off" >>/etc/apache2/apache2.conf
# enable actual Ip Logging
sed -i 's/LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined/LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined/' /etc/apache2/apache2.conf
#Enable Directory permissions
#echo -e "<Directory /var/www/html> \n Options FollowSymLinks\n AllowOverride all \n Require all granted \n </Directory>" >> /etc/apache2/sites-enabled/000-default.conf
sed -i '/var/a<Directory /var/www/html/>\nOptions FollowSymLinks\nAllowOverride all\nRequire all granted\n</Directory>\nRewriteEngine On\nRewriteCond %{HTTPS} off\nRewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}' /etc/apache2/sites-enabled/000-default.conf
echo " Restarting Apache "
echo -e "\n\n\n"
systemctl restart apache2
echo " Apache Restarted"
echo -e " \n\n\n "
echo -e "\n\n\n\n\n\n"
echo -e "\n\n\n\n\n\n"
echo "Creating a New User...."
echo -e " \n\n\n "
echo " Please enter the name of user: "
# Take input from user
read usr_name
# Create a directory for user
mkdir -p /var/www/html/$usr_name
# Make a new user and set his Password
useradd $usr_name -d /var/www/html/$usr_name -s /bin/bash
chown -R $usr_name:$usr_name /var/www/html/$usr_name
echo "$usr_name:$usr_name-123#@"|chpasswd
# Enable SSH login
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
service ssh restart
echo -e "\n\n\n\n\n\n"
echo -e "\n\n\n\n\n\n"
echo "SSH via Password Authentication enabled"
echo "$usr_name ALL=NOPASSWD:ALL #Sudo rights for $usr_name " >>/etc/sudoers
echo "Sudo rights to $usr_name has been been provided with NOPASSWD Authentication"
echo -e "\n\n\n\n\n\n"
echo "Synchronizing System Time"
apt-get install -y ntp
echo -e "\n\n\n\n\n\n"
echo -e "\n\n\n\n\n\n"
echo "Enter Hostname. To identify different servers i.e Dev,Qa,Satging, Production ..... "
# Get Hostname from user
read h_name
hostnamectl set-hostname $h_name
# Making enteries in /etc/hosts file
echo "127.0.0.1 $h_name" >> /etc/hosts
# tell apache to use localhost as Hostname
echo "ServerName localhost" >> /etc/apache2/apache2.conf
#install postfix
apt-get install -y postfix
apt-get install -y zip unzip