aboutsummaryrefslogtreecommitdiffstats
path: root/mayor-installer-fcgi/fcgi_install.d/25apache.sh
blob: d2aa12c7bb616d378533144ae6f839d1c3fdaf22 (plain)
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
#!/bin/bash
#

cat <<EOF
Az Apache (2) webszerver beállítása

Az elektronikus napló használata feltétlenül HTTPS protokollt igényel.
Ehhez engedélyeznie kell az ssl modul használatát, és tanusítványra is
szükség van. A telepítő "self-signed" tanusítványt generál (ehhez meg kell
adnia a szerver teljes domain nevét), valamint engedélyezi a rewrite modul
használatát is, végül létrehoz és engedélyez mayor néven egy site
konfigurációt is.

Valamint itt történik a mod_suexec és a mod_fcgid konfigurálása is.

EOF

read -n 1 -p "Az Apache web-szerver módosítható? (i/N)" -s DO
if [ "$DO" != "i" ]; then echo -e "\nAz Apache web szerver beállításait nem módosítottam.\n"; exit 1; fi

if [ "$MAYORDIR" = "" ]; then echo "A MAYORDIR változó üres. Kilépek."; exit 1; fi

echo -e "\nApache beállítások"


echo "    Tanusítvány generálás"
if [ ! -e /etc/apache2/ssl ]; then 
    mkdir /etc/apache2/ssl
fi
make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache_mayor.pem

echo "  Szükséges modulok ellenőrzése:"
echo -n "    - ModSSL engedélyezése ... "
if [ ! -e /etc/apache2/mods-enabled/ssl.load ]; then
    a2enmod ssl > /dev/null
    echo ok
else
    echo "már engedélyezett"
fi
    echo -n "    - ModReWrite engedélyezése ... "
if [ ! -e /etc/apache2/mods-enabled/rewrite.load ]; then
    a2enmod rewrite > /dev/null
    echo ok
else
    echo "már engedélyezett"
fi

echo -n "    - mod_suexec engedélyezése ... "
if [ ! -e /etc/apache2/mods-enabled/suexec.load ]; then
    a2enmod suexec > /dev/null
    echo ok
else
    echo "már engedélyezett"
fi

echo -n "    - mod_fcgid engedélyezése ... "
if [ ! -e /etc/apache2/mods-enabled/fcgid.load ]; then
    a2enmod fcgid > /dev/null
    echo ok
else
    echo "már engedélyezett"
fi

echo -n "    - mod_actions engedélyezése ... "
if [ ! -e /etc/apache2/mods-enabled/actions.load ]; then
    a2enmod actions > /dev/null
    echo ok
else
    echo "már engedélyezett"
fi


echo -n "    - mod_php kikapcsolása (a www-data php értelmezője)"
if [ -e /etc/apache2/mods-enabled/php7.0.load ]; then
    a2dismod php7.0 > /dev/null
    echo ok
else
    echo "nincs bekapcsolava"
fi

echo -n "    - mod_headers engedélyezése"
if [ ! -e /etc/apache2/mods-enabled/headers.load ]; then
    a2enmod headers > /dev/null
    echo ok
else
    echo "nincs bekapcsolava"
fi


echo -n "    - Apache2 mod_worker és mod_event, amíg a php nem lesz thread-safe. "
if [ -e /etc/apache2/mods-enabled/mpm_event.load ] || [ -e /etc/apache2/mods-enabled/mpm_worker.load ]; then
    a2dismod mpm_event > /dev/null
    a2dismod mpm_worker > /dev/null
    a2enmod mpm_prefork > /dev/null
    echo ok
else
    echo "nincs bekapcsolava"
fi

echo "ok."


echo -e "  Apache2 konfiguráció létrehozása\n"
cat > /etc/apache2/sites-available/mayor_naplo.conf <<EOT
<VirtualHost *:443>
	ServerName your.mayor.server.hu
#        ServerAlias your.mayor.server.hu    your.mayor.server.iskola.sulinet.hu


	ServerAdmin webmaster@localhost

        SuexecUserGroup mayor-user mayor-user
        DocumentRoot mayor-docroot
        ScriptAlias /wbin/ mayor-web-bin
						
        AddHandler php-fcgi .php
        Action php-fcgi /wbin/php7.fcgi	 
        AddType application/x-httpd-php .php
        
	<IfModule mod_fcgid.c>
            FcgidProcessLifeTime 3600   
            FcgidIOTimeout       320          
            FcgidMaxRequestInMem 16777216 
            FcgidMaxRequestLen   33554432   
            FcgidBusyTimeout     600        
##          FcgidOutputBufferSize 0      
            FcgidIdleTimeout     400          
        </IfModule>

#						Részletesebben:
#	    FcgidProcessLifeTime 3600		##(seconds) A php max futási ideje (a (hagyományos) mod_php-nál is ennyi)
#	    FcgidIOTimeout 320			##(seconds) A php generál valamit, elkldi a böngészőnek, vagy a böngésző küld adatot a php-nak, ennyi ideig tarthat. (pl: 120sec)  
#	    FcgidMaxRequestInMem 16777216	##(bytes) Amikor a böngésző küld adatokat a php-nak, ennyi megy a pufferbe. (16MB elég)		
#	    FcgidMaxRequestLen 33554432		##(bytes) Amikor a böngésző küld adatot a php-nak, az adat max hossza bájtokabn. (32MB elég)
#	    FcgidBusyTimeout 600		##(seconds) A php max ennyi ideig gondolkozhat egy futáson/kérésen, ha túllépi, ki lesz lőve.
#	    FcgidOutputBufferSize   0		##(bytes) Pufer, amikor a php generál valami adatot, és azt elküldené a böngészőnek. {ezt még át kéne nézni}
#	    FcgidIdleTimeout 400		##(seconds) A php-értelmező ennyi pihenés után le lesz állítva.(**)
# 						##(**)  Figyelem! Itt a "php-értelmező" külön gyermekprocesszként fut, ami az oldal meglátogatásakor indul automatikusan, 
#						##	és FcgidIdleTimeout-nyi pihenés után magától leáll.
	<IfModule autoindex>
	    IndexIgnore *
	</IfModule>

						## A php-csomagoló, és php.ini fájlok közvetlen elérésének tiltása
        <Directory mayor-web-bin >	
                Require all granted	
             <Files "php7.fcgi">		
                Require env REDIRECT_STATUS	
             </Files>
             <Files "php.ini">
                Require all denied
             </Files>
	     <Files "php.ini.mayor">
                Require all denied             
             </Files>
        </Directory>

        DirectoryIndex index.php index.html index.htm

       <Directory />		
                Options FollowSymLinks
                AllowOverride None
        </Directory>

        <Directory /var/mayor/www/>
                Options -Indexes +FollowSymLinks +MultiViews
                AllowOverride None
                # Apache 2.2 # Order allow,deny
                # Apache 2.2 # allow from all
                # Apache 2.4 # Require all granted
                <IfVersion >= 2.3>
                    Require all granted
                </IfVersion>
                <IfVersion < 2.3>
                    order allow,deny
                    allow from all
                </IfVersion>
                RewriteEngine on
                RewriteBase /
                RewriteCond %{SERVER_PORT} ^80$
                RewriteCond %{THE_REQUEST}  .*(policy=private|page=auth|page=password).*
                RewriteRule (.*)$ https://%{HTTP_HOST}/$1 [L]
        </Directory>


	SSLEngine On
#								## A gyenge titkosítások tiltása	
	SSLProtocol        all -SSLv2 -SSLv3 -TLSv1	
	SSLCertificateFile /etc/apache2/ssl/apache_mayor.pem
# #	SSLCertificateFile /etc/apache2/ssl/crt/name-cert.pem
# #	SSLCertificateKeyFile /etc/apache2/ssl/key/name-key.pem


	<IfModule mod_headers.c>		
        	Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
	</IfModule>


	ErrorLog \${APACHE_LOG_DIR}/mayor_error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel info ssl:warn fcgid:debug

	CustomLog  \${APACHE_LOG_DIR}/mayor_access.log combined
	ServerSignature On

</VirtualHost>
EOT



SERVERNAME=""
while [ "$SERVERNAME" = "" ]
do
    read -p "  A web szerver teljes domain neve (pl: mayor.tesztsuli.hu): " SERVERNAME
done

#cat $MAYORDIR/install/base/apache2/mayor.conf | sed "s/ServerName your.mayor.server.hu/ServerName $SERVERNAME/" > /etc/apache2/sites-available/mayor.conf

# A 2.4-es apache esetén módosítani kell a konfig állományt!
APACHE_VERSION=$(dpkg -l apache2 | grep apache2 | tr -s ' ' | cut -d ' ' -f 3 | cut -d '-' -f 1 | sed 's/\..$//')

echo -e "  Apache2 finomhangolása\n"

sed -e "s/ServerName your.mayor.server.hu/ServerName $SERVERNAME/g" -i /etc/apache2/sites-available/mayor_naplo.conf
sed -e "s/SuexecUserGroup mayor-user mayor-user/SuexecUserGroup $MAYORUSER $MAYORUSER/g" -i /etc/apache2/sites-available/mayor_naplo.conf
sed -e "s/DocumentRoot mayor-docroot/DocumentRoot \/home\/$MAYORUSER\/mayor\/www\/ /g" -i /etc/apache2/sites-available/mayor_naplo.conf
sed -e "s/ScriptAlias \/wbin\/ mayor-web-bin/ScriptAlias \/wbin\/ \/home\/$MAYORUSER\/mayor\/www-bin\/ /g" -i /etc/apache2/sites-available/mayor_naplo.conf
sed -e "s/<Directory mayor-web-bin >/<Directory \/home\/$MAYORUSER\/mayor\/www-bin\/ > /g" -i /etc/apache2/sites-available/mayor_naplo.conf
sed -e "s/<Directory \/var\/mayor\/www\/>/<Directory \/home\/$MAYORUSER\/mayor\/www\/> /g" -i  /etc/apache2/sites-available/mayor_naplo.conf

echo -e " a suexec beállítása\n"
sed -e 's/\/var\/www/\/home\n\/var\/www/g' -i /etc/apache2/suexec/www-data

echo " A php-csomagoló elkészítése"
mkdir -p "/home/$MAYORUSER/mayor/www-bin/"

csomagolo="#!/bin/sh \n exec /usr/bin/php-cgi7.0 "
echo -e $csomagolo > "/home/$MAYORUSER/mayor/www-bin/php7.fcgi"
chmod +x "/home/$MAYORUSER/mayor/www-bin/php7.fcgi"

echo "  A php.ini beszerzése"
cp "/etc/php/7.0/cgi/php.ini" "/home/$MAYORUSER/mayor/www-bin/php.ini"
chown -R "$MAYORUSER:$MAYORUSER"  "/home/$MAYORUSER/mayor/www-bin"


if [ ! -e /etc/apache2/sites-enabled/mayor_naplo.conf ]; then
    echo "  A mayor site engedélyezése"
    a2ensite mayor_naplo.conf > /dev/null
fi

echo "  A web-szerver újraindítása"
/etc/init.d/apache2 restart