Code

aa349f9b455ea3b9214409ea73dcf80fb0e34863
[gosa.git] / doc / guide / admin / en / manual_gosa_en_apache.tex
1 \chapter{Apache And PHP}
2 \section{Apache Introduction}
4 GOsa is an application written in the PHP programming language.
6 Although everybody knows what is a Web page, we will review some basic points: 
8 \begin{description}
9 \item[WWW]
10 The World Wide Web is the main core of what we know as the Internet, it is a space information where each resource is identified by its URI (Universal Resource Identifier), it defines the protocol necessary to accede to the information, the machine that has it and where it is placed. 
12 The WWW is the great revolution of our time, is an enormous source of information. And because this all the applications are being Internet oriented. GOsa uses the WWW for a simple reason, distribution of the program, a Internet oriented application that can be used from any place and any time. GOsa does not need to be acceded in the same machine that has it executed, and another thing, each one of the servers whom it controls even can be in different machines and remote places. 
14 \item[HTTP]
15 \htmladdnormallink{HTTP}{http://www.w3.org/Protocols/}\cite{2616} is the acronym of HyperText Transfer Protocol, whose importantest purpose is the publication and reception of "Web pages". 
17 It is a application level protocol invented for distributed systems of hypermedia information. It has been being used for the WWW from 1990, the current version is HTTP/1.1. 
19 The practical operation can be reduced to a client whom makes a request and a server whom manages that request makes an answer. 
21 \item[HTML] 
22 If the request of the client and the answer of the server are correct, the answer of the server will contain some type of hypermedia, the most habitual is \htmladdnormallink{HTML}{http://www.w3.org/TR/1998/REC-html40-19980424/} (HyperText Markup Language), a language thought for publication with contents and a easy navigation by them. It is a protocol in constant development, the present version is HTML4.01 and in publication XHTML2.0 
23 \end{description}
25 \htmladdnormallink{APACHE}{http://httpd.apache.org/} is the \htmladdnormallink{most used}{http://news.netcraft.com/archives/web_server_survey.html} server for HTTP , secure, efficient and modular. 
27 This manual will be centered around this server, since this is the most used and has a opensource license. 
29 More information about this server is in \htmladdnormallink{http://httpd.apache.org/docs-2.0/}{http://httpd.apache.org/docs-2.0/}
32 \section{PHP Introduction}
34 PHP (PHP: Hypertext Preprocessor), is an interpreted high level language, specially thought for the design of web pages. The syntax is a mixture of C, Perl and Java. It is embed in HTML pages and is executed by the HTTP server.
36 PHP is widely extended and has a numerous group of developer, a \htmladdnormallink{extensive documentation}{http://www.php.net/docs.php} and numerous web sites with documentation and examples. 
38 \newpage
40 \section{Installation} 
41 \subsection{Unloading and Installing Apache} 
42 \label{down_apache}
43 As in the previous chapter, Apache is practically in all the distributions, although we will see its installation from the sources. We are going to focus on the most advanced versions of apache, the 2.0.XX stables series.
45 It is recommended install the same packages that are needed for openLDAP\ref{down_ldap}. 
47 It is possible to be downloaded of: \htmladdnormallink{http://httpd.apache.org/download.cgi}{http://httpd.apache.org/download.cgi}, the version which we are going to download and decompress in/usr/src is the httpd-2.0.XX.tar.gz 
49 We executed \htmladdnormallink{./configure}{http://warping.sourceforge.net/gosa/contrib/en/configure-apache.sh} with the following options:
51 \begin{itemize}
52 \item[]Generals\\
53 \begin{tabular}{|ll|} \hline
54 --enable-so & $\rightarrow$ Support of Dynamic Shared Objects (DSO)\\
55 --with-program-name=apache2 & \\
56 --with-dbm=db42 & $\rightarrow$ Version of Berkeley DB that we are going to use\\
57 --with-external-pcre=/usr & \\
58 --enable-logio & $\rightarrow$ Input and Output Log\\
59 --with-ldap=yes & \\
60 --with-ldap-include=/usr/include & \\
61 --with-ldap-lib=/usr/lib & \\
62 \hline \end{tabular}
63  
64 \item[]suexec Support\\
65 \begin{tabular}{|ll|}\hline 
66 --with-suexec-caller=www-data & \\
67 --with-suexec-bin=/usr/lib/apache2/suexec2 & \\
68 --with-suexec-docroot=/var/www & \\
69 --with-suexec-userdir=public\_html & \\
70 --with-suexec-logfile=/var/log/apache2/suexec.log & \\
71 \hline \end{tabular}
73 \item[]
74 \begin{longtable}{|ll|}
75 \hline
76 \multicolumn{2}{|c|}{\textbf{Modules}}\\
77 \hline
78 \endfirsthead
79 \hline
80 \endhead
81 \hline
82 \multicolumn{2}{|c|}{Continue $\ldots$}\\
83 \hline
84 \endfoot
85 \hline
86 \multicolumn{2}{|c|}{\textbf{End}}\\
87 \hline
88 \endlastfoot
89 --enable-userdir=shared & $\rightarrow$ mod\_userdir, module for user directories\\
90 --enable-ssl=shared & $\rightarrow$ mod\_ssl, module of secure connectivity SSL\\
91 --enable-deflate=shared & $\rightarrow$ mod\_deflate, module to compress the information\\
92 --enable-ldap=shared & $\rightarrow$ mod\_ldap\_userdir, module for ldap cache and connections\\
93 --enable-auth-ldap=shared & $\rightarrow$ mod\_ldap, module of authentication in ldap\\
94 --enable-speling=shared & $\rightarrow$ mod\_speling, module for the correction of failures in URL\\
95 --enable-include=shared & $\rightarrow$ mod\_include, module for the inclusion of other configurations \\ 
96 --enable-rewrite=shared & $\rightarrow$ mod\_rewrite, allows the URL manipulations \\ 
97 --enable-cgid=shared & $\rightarrow$ CGI script\\
98 --enable-vhost-alias=shared & $\rightarrow$ module for aliasing of virtual domains \\ 
99 --enable-info=shared & $\rightarrow$ Information of the server\\
100 --enable-suexec=shared & $\rightarrow$ Change the user and the group of the processes\\
101 --enable-unique-id=shared & $\rightarrow$ unique Identifier by request\\
102 --enable-usertrack=shared & $\rightarrow$ Track of the user session\\
103 --enable-expires=shared & $\rightarrow$ Module for sending of expiration headers\\
104 --enable-cern-meta=shared & $\rightarrow$ Files meta type CERN\\
105 --enable-mime-magic=shared & $\rightarrow$ Obtain automatically mimetype\\
106 --enable-headers=shared & $\rightarrow$ Control HTTP headers\\
107 --enable-auth-anon=shared & $\rightarrow$ Access to anonymous users\\
108 --enable-proxy=shared & $\rightarrow$ Allow the use of Apache as a proxy\\
109 --enable-dav=shared & $\rightarrow$ Able to handle to the WebDav protocol\\
110 --enable-dav-fs=shared & $\rightarrow$  Supplier DAV for the file system\\
111 --enable-auth-dbm=shared & $\rightarrow$ Authentication based on database DBM\\
112 --enable-cgi=shared & $\rightarrow$ Allow CGI scripts\\
113 --enable-asis=shared & $\rightarrow$ Types of archives as they are\\
114 --enable-imap=shared & $\rightarrow$ Server side image maps\\
115 --enable-ext-filter=shared & $\rightarrow$ Module for external filters\\
116 --enable-authn-dbm=shared & \\
117 --enable-authn-anon=shared & \\
118 --enable-authz-dbm=shared & \\
119 --enable-auth-digest=shared & $\rightarrow$ Collection of authentications according to RFC2617\\
120 --enable-actions=shared & $\rightarrow$ Active actions according to requests\\
121 --enable-file-cache=shared & $\rightarrow$ File Cache\\
122 --enable-cache=shared & $\rightarrow$ Dynamic Cache of archives\\
123 --enable-disk-cache=shared & $\rightarrow$ Disc cache\\
124 --enable-mem-cache=shared & $\rightarrow$ Mamory cache\\
125 \end{longtable}
126 \end{itemize}
128 Once configured, we must do:\\
129 \\
130 \begin{tabular}{|l|}\hline 
131 \#make \&\& make install\\
132 \hline \end{tabular}
133 \newpage
135 \subsection{Installing PHP in Apache} 
137 Can be downloaded of \htmladdnormallink{http://www.php.net/downloads.php}{http://www.php.net/downloads.php} being the version necessary to the date of this manual for comaptibility with GOsa, the 4.3.XX, since versions 5.0.XX are not supported yet. We will download and decompress in/usr/src. 
139 In order to be able to compile the necessary modules, we need the developer libraries of servers section \ref{servers}, in addition to same that openLDAP\ref{down_ldap} and the Apache\ref{down_apache}, we will need some library more: 
141 \begin{itemize}
142 \item[libbz2] 
143 We can download it of \htmladdnormallink{http://sources.redhat.com/bzip2/}{http://sources.redhat.com/bzip2/} as module of compression BZ2. 
144 \item[e2fsprogs]
145 For access to the file system, can be downloaded of \htmladdnormallink{http://e2fsprogs.sourceforge.net}{http://e2fsprogs.sourceforge.net}
146 \item[expat] 
147 Download from \htmladdnormallink{http://expat.sourceforge.net/}{http://expat.sourceforge.net/}, A XML parser. 
148 \item[zziplib] 
149 Download from \htmladdnormallink{http://zziplib.sourceforge.net/}{http://zziplib.sourceforge.net/}, to access to ZIP archives.
150 \item[zlib] 
151 Download from \htmladdnormallink{http://www.gzip.org/zlib/}{http://www.gzip.org/zlib/} for GZIP compression. 
152 \item[file] 
153 Download from \htmladdnormallink{http://www.darwinsys.com/freeware/file.html}{http://www.darwinsys.com/freeware/file.html} to get control of archives. 
154 \item[sed] 
155 Download from \htmladdnormallink{http://www.gnu.org/software/sed/sed.html}{http://www.gnu.org/software/sed/sed.html}, one of the most powerful tools for text handling.
156 \item[libcurl] 
157 Powerful tool to handle remote archives, download from \htmladdnormallink{http://curl.haxx.se/}{http://curl.haxx.se/}. 
158 \item[gettext] 
159 GNU Tool for support of several languages, download from \htmladdnormallink{http://www.gnu.org/software/gettext/gettext.html}{http://www.gnu.org/software/gettext/gettext.html}.
160 \item[libgd] 
161 For the manipulation and creation of images, download from: \htmladdnormallink{http://www.boutell.com/gd}{/http://www.boutell.com/gd/}.
162 \item[libjpeg] 
163 Manipulation of JPEG images, download from \htmladdnormallink{http://www.ijg.org/}{http://www.ijg.org/}.
164 \item[libpng] 
165 Manipulation of PNG images, donwload from \htmladdnormallink{http://www.libpng.org/pub/png/libpng.html}{http://www.libpng.org/pub/png/libpng.html}.
166 \item[mcal] 
167 Library for access to remote Calendars, download from \htmladdnormallink{http://mcal.chek.com/}{http://mcal.chek.com/}.
168 \item[libmysql] 
169 Support of most famous database, is essential for php, download from \htmladdnormallink{http://www.mysql.com/}{http://www.mysql.com/} 
170 \end{itemize}
171 \vspace{1cm}
174 A recommended configuration will be like this: 
177 \begin{itemize}
178 \item[]Apache2\\
179 \begin{tabular}{|ll|}\hline 
180 --prefix=/usr --with-apxs2=/usr/bin/apxs2 & \\
181 --with-config-file-path=/etc/php4/apache2 & \\
182 \hline \end{tabular}
185  
186 \item[]Options of compilation\\
187 \begin{tabular}{|ll|}\hline
188 --enable-memory-limit & \# Compiled with memory limit\\
189 --disable-debug & \# To compile without debug symbols\\
190 --disable-static & \# Without static libraries\\
191 --with-pic & \# To use PIC and nonPIC objects\\
192 --with-layout=GNU & \\
193 --enable-sysvsem & \# sysvmsg Support\\
194 --enable-sysvshm & \# sysvshm Support\\
195 --enable-sysvmsg & \# System V shared memory support\\
196 --disable-rpath & \# Disable to be able to pass routes to extra librerias to the binary\\
197 --without-mm & \# To disable memoty sessions support\\
198 \hline \end{tabular}
200 \item[]Session\\
201 \begin{tabular}{|ll|}\hline
202 --enable-track-vars & \\
203 --enable-trans-sid & \\
204 \hline \end{tabular}
206 \item[]Support\\
207 \begin{tabular}{|ll|}\hline
208 --enable-sockets & \# sockets support\\
209 --with-mime-magic=/usr/share/misc/file/magic.mime & \\
210 --with-exec-dir=/usr/lib/php4/libexec & \\
211 \hline \end{tabular}
213 \item[]pear\\
214 \begin{tabular}{|ll|}\hline
215 --with-pear=/usr/share/php & \# Where we are going to install PEAR\\
216 \hline \end{tabular}
217   
218 \item[]functions\\
219 \begin{tabular}{|ll|}\hline
220 --enable-ctype & \# Control of characters functions support\\
221 --with-iconv & iconv functions support \\
222 --with-bz2 & BZ2 Compression support\\
223 --with-regex=php & Type of library of regular expressions\\
224 --enable-calendar & Calendar conversion functions\\
225 --enable-bcmath & Mathematics of arbitrary precision support\\
226 --with-db4 & DBA: Berkeley DB version 4 support \\
227 --enable-exif & exif functions support, for JPG and TIFF metadata reading\\
228 --enable-ftp & FTP functions support \\
229 --with-gettext & Localization support\\
230 --enable-mbstring & \\
231 --with-pcre-regex=/usr & \\
232 --enable-shmop & shared memory functions\\
233 --disable-xml --with-expat-dir=/usr & use expat xml instead of which comes with php\\
234 --with-xmlrpc & \\
235 --with-zlib & \\
236 --with-zlib-dir=/usr & \\
237 --with-imap=shared,/usr & imap generic support\\
238 --with-kerberos=/usr & Imap with Kerberos authentication\\
239 --with-imap-ssl & Imap with SSL secure access\\
240 --with-openssl=/usr & \\
241 --with-zip=/usr & \\
242 --enable-dbx & Layer of abstraction with databases\\
243 \hline \end{tabular}
245 \item[]external modules\\
246 \begin{tabular}{|ll|}\hline
247 --with-curl=shared,/usr & remote Handling of archives\\
248 --with-dom=shared,/usr --with-dom-xslt=shared,/usr --with-dom-exslt=shared,/usr & With xmlrpc already integrated\\
249 --with-gd=shared,/usr --enable-gd-native-ttf & Images handling support\\
250 --with-jpeg-dir=shared,/usr &  GD Support for JPEG\\
251 --with-png-dir=shared,/usr & GD Support for png\\
252 --with-ldap=shared,/usr & Support for ldap\\
253 --with-mcal=shared,/usr & Support of calendars\\
254 --with-mhash=shared,/usr & Module for several key generation algorithms\\
255 --with-mysql=shared,/usr & Support of Mysql database\\    
256 \hline \end{tabular}
257 \end{itemize}
259 Then do:\\
260 \#make \&\& make install 
261 \newpage
262 \section{Apache2 Configuration}
264 The apache configuration is saved in the directory /etc/apache2 in the following files and directories:
265 \begin{itemize}
266 \item[]File apache2.conf:\\
267 Main configuration of apache2, it have the necesary configuration to run apache.\\
268 We don\'t need to edit this file.
269 \item[]File ports.conf\\
270 What port apache listen, we need two, port 80 for HTTP and port 443 for HTTPS, we will edit the file, and leave like this:\\
271 \begin{tabular}{|l|}\hline
272 Listen 80,443\\
273 \hline \end{tabular}
274 \item[]Directory conf.d:\\
275 Directory for especial configuration, we don\'t need it.
276 \item[]Directories mods-available and mods-enabled:\\
277 This directory have all the modules we can use of apache2, to enable a module is neccesary link it to the directory mods-enabled.\\
278 \item[]Directories sites-available and sites-enabled:\\
279 In sites available we must configure the sites we can use.\\
280 For example we are going to create a no secure gosa site gosa, we can use it to redirect the request to the secure server.
282 Gosa Configuration (sites-available/gosa) can be like this:\\
283 \begin{tabular}{|l|}\hline
284 \noindent NameVirtual *\\
285 <VirtualHost *>\\
286 \verb|    |ServerName gosa.chaosdimension.org\\
287 \\
288 \verb|    |Redirect /gosa https://gosa.chaosdimension.org/gosa\\
289 \\
290 \verb|    |CustomLog /var/log/apache/gosa.log combined\\
291 \verb|    |ErrorLog /var/log/apache/gosa.log\\
292 \\
293 </VirtualHost>\\
294 \hline \end{tabular}
296 And when is saved, can be enabled making this:\\
297 \\
298 \begin{tabular}{|l|}\hline
299 \#>ln -s /etc/apache2/sites-available/gosa.conf /etc/apache2/sites-enabled/gosa.conf\\
300 \hline \end{tabular}
301 \\
302 \item[]Directory ssl:\\
303 Directory for Secure Socket Layer configuration, this will see in the next section.
304 \end{itemize}
305 \newpage
306 \subsection{Security}
308 The security is one of the most important points when running a apache server, we will need to make a safe environment where not to allow that the users manipulate and accede to code or programs. 
310 The way to obtain this is using cryptography, in which we secure the communications between clients and servers so that nobody else can accede to the data. This is obtained with cryptography and key exchange.
312 The other way to secure the system is that if some failure exists in the system or the code, and if a intruder tries to execute code, this person can be disabled, since powerful limitations exist, like not allowing that he executes commands, reads code of others scripts. He cannot modify nothing because he has a user with very limited resources. 
314 \subsubsection{SSL Certificates}
316 \noindent There are a great amount of documentation on cryptography and concretely on SSL, a system of encryption with public and private key. \\ 
317 \\ 
318 \noindent As the package openSSL was already installed from the previous steps, we must create the certificates that we will use in our Web server. \\ 
319 \\ 
320 \noindent we will save the certificates in/etc/apache2/ssl/gosa.pem \\ 
321 \\
322 \begin{tabular}{|l|}\hline
323 \#>FILE=/ect/apache2/ssl/gosa.pem\\
324 \#>export RANDFILE=/dev/random\\
325 \#>openssl req -new -x509 -nodes -out \$FILE -keyout /etc/apache2/ssl/apache.pem\\
326 \#>chmod 600 \$FILE\\
327 \#>ln -sf \$FILE /etc/apache2/ssl/`/usr/bin/openssl x509 -noout -hash < \$FILE`.0\\
328 \hline \end{tabular}
329 \vspace{0.5cm}
331 \noindent With this we have created a certificate that allows SSL access to our pages. \\ 
332 \\ 
333 \noindent If what we want is a configuration that allows us not only that traffic is codified, but that in addition the client guarantees that he is a valid user, we must force the server to requests a client certification \\ 
334 \\ 
335 \noindent In this way we will follow a longer procedure, first will be creation of a certification of CA: \\ 
336 \\
337 \begin{tabular}{|l|}\hline
338 \#>CAFILE=/ect/apache2/ssl/gosa.ca\\
339 \#>KEY=/etc/apache2/ssl/gosa.key\\
340 \#>REQFILE=/etc/apache2/ssl/gosa.req\\
341 \#>CERTFILE=/ect/apache2/ssl/gosa.cert\\
342 \#>DAYS=365\\
343 \#>export RANDFILE=/dev/random\\
344 \#>openssl req -x509 -keyout \$CAKEY -out \$CAFILE \$DAYS\\
345 \hline \end{tabular}
346 \vspace{0.5cm}
348 \noindent After several questions we will have a CA, now we make a requirement to the created CA: \\ 
349 \\
350 \begin{tabular}{|l|}\hline
351 \#>openssl req -new -keyout \$REQFILE -out \$REQFILE \$DAYS\\
352 \hline \end{tabular}
353 \vspace{0.5cm}
355 \noindent Sign the new certificate: \\ 
356 \\
357 \begin{tabular}{|l|}\hline
358 \#>openssl ca -policy policy\_anything -out \$CERFILE -infiles \$REQFILE\\
359 \hline \end{tabular}
360 \vspace{0.5cm}
362 \noindent and we created a pkcs12 certidicate to configure the clients: \\
363 \\ 
364 \begin{tabular}{|l|}\hline
365 \#>openssl pkcs12 -export -inkey \$KEY -in \$CERTFILE -out certificado\_cliente.pkcs12\\
366 \hline \end{tabular}
367 \vspace{0.5cm}
369 \noindent This certificate will be installed in the client, and in the the configuration of the Web server in the way explained in the following point, we will have the security that the clients who will accede the server are in a secure machine and its communication will be strictly confidential. \ \ 
371 \subsubsection{Configuring mod-SSL}
372 \noindent The SSL module comes with apache2, this will simplify our work. In order to know if already is enabled: \\
373 \\
374 \begin{tabular}{|l|}\hline
375 \#> if [ -h /etc/apache2/mods-enabled/ssl.load ]; then echo "enabled module";else echo "disabled module"; fi\\
376 \hline \end{tabular}
377 \vspace{0.4cm}
379 \noindent To enabled it we will do it following: \\ 
380 \\
381 \begin{tabular}{|l|}\hline
382 \#>ln -s /etc/apache2/mods-available/ssl.conf /etc/apache2/mods-enabled/ssl.conf\\
383 \#>ln -s /etc/apache2/mods-available/ssl.load /etc/apache2/mods-enabled/ssl.load\\
384 \hline \end{tabular}
385 \vspace{0.5cm}
387 \noindent This will enable the module in apache2 and we will be able to use it after restarting the server with: \\
388 \\
389 \begin{tabular}{|l|}\hline
390 \#>/etc/init.d/apache2 restart\\
391 \hline \end{tabular}
392 \vspace{0.5cm}
394 \noindent If we only want a secure configuration, we will make this in /etc/apache2/sites-available, gosa-SSL: \\ 
395 \\
396 \begin{tabular}{|l|}\hline
397 \noindent NameVirtual *:443\\
398 <VirtualHost *:443>\\
399 \verb|    |ServerName gosa.chaosdimension.org\\
400 \verb|    |alias /gosa /usr/share/gosa/html\\
401 \\
402 \verb|    |DocumentRoot /var/www/gosa.chaosdimension.org\\
403 \verb|    |CustomLog /var/log/apache/gosa.log combined\\
404 \verb|    |ErrorLog /var/log/apache/gosa.log\\
405 \\
406 \verb|    |SSLEngine On\\
407 \verb|    |SSLCertificateFile    /etc/apache2/ssl/gosa.cert\\
408 \verb|    |SSLCertificateKeyFile /etc/apache2/ssl/gosa.key\\
409 \verb|    |SSLCertificateChainFile /etc/apache2/ssl/gosa.cert\\
410 \verb|    |SSLCertificateKeyFile /etc/apache2/ssl/gosa.key\\
411 \verb|    |SSLCACertificateFile /etc/apache2/ssl/gosa.ca\\
412 \verb|    |SSLCACertificatePath /etc/apache2/ssl/\\
413 \verb|    |SSLLogLevel error\\
414 \verb|    |SSLLog /var/log/apache2/ssl-gosa.log\\
415 \\
416 </VirtualHost>\\
417 \hline \end{tabular}
418 \vspace{0.5cm}
420 \noindent For a secure communication in which we verified the certificate of the client: \\
421 \begin{tabular}{|l|}\hline
422 \noindent NameVirtual *:443\\
423 <VirtualHost *:443>\\
424 \verb|    |ServerName gosa.chaosdimension.org\\
425 \\
426 \verb|    |alias /gosa /usr/share/gosa/html\\
427 \\
428 \verb|    |DocumentRoot /var/www/gosa.chaosdimension.org\\
429 \verb|    |CustomLog /var/log/apache/gosa.log combined\\
430 \verb|    |ErrorLog /var/log/apache/gosa.log\\
431 \\
432 \verb|    |SSLEngine On\\
433 \verb|    |SSLCertificateFile    /etc/apache2/ssl/gosa.cert\\
434 \verb|    |SSLCertificateKeyFile /etc/apache2/ssl/gosa.key\\
435 \verb|    |SSLCertificateChainFile /etc/apache2/ssl/gosa.cert\\
436 \verb|    |SSLCertificateKeyFile /etc/apache2/ssl/gosa.key\\
437 \verb|    |SSLCACertificateFile /etc/apache2/ssl/gosa.ca\\
438 \verb|    |SSLCACertificatePath /etc/apache2/ssl/\\
439 \verb|    |SSLLogLevel error\\
440 \verb|    |SSLLog /var/log/apache2/ssl-gosa.log\\
441 \\      
442 \verb|    |<Directory /usr/share/gosa >\\
443 \verb|    |\verb|    |SSLVerifyClient require\\
444 \verb|    |\verb|    |SSLVerifyDepth 1\\
445 \verb|    |</Directory>\\
446 </VirtualHost>\\
447 \hline \end{tabular}
448 \vspace{0.5cm}
450 \subsubsection{Configuring suphp}
451 \noindent
452 Suphp is a module for apache and php that allows to execute processes of php with a different user of which apache uses to execute php pages. 
454 It consists of two parts, one is a module for apache who "captures" requests of php pages, verifies the user of the file, its group, and sends the information to the other part, that is suid-root executable that sends the information to php4-cgi with the owner of the file as user, then gives back the result to the module of the apache. 
456 The idea is to lower the damage that would cause a possible failure of the system being exploited, in this way the user enter the system with an nonqualified account, without permissions of execution and possibility to access to another code or programs. 
458 Suphp can be downloaded of \htmladdnormallink{http://www.suphp.org/Home.html}{http://www.suphp.org/Home.html}, decompressing the package in/usr/src and compiled with the following options:\\
459 \\
460 \begin{tabular}{|l|}\hline
461 \#>./configure --prefix=/usr \textbackslash \\
462 \verb|    |--with-apxs=/usr/bin/apxs2 \textbackslash \\
463 \verb|    |--with-apache-user=www-data \textbackslash \\
464 \verb|    |--with-php=/usr/lib/cgi-bin/php4 \textbackslash \\
465 \verb|    |--sbindir=/usr/lib/suphp \textbackslash \\
466 \verb|    |--with-logfile=/var/log/suphp/suphp.log \textbackslash \\
467 \verb|    |-with-setid-mode \textbackslash \\
468 \verb|    |--disable-checkpath \\
469 \hline \end{tabular}
470 \vspace{0.5cm}
472 \noindent Of course we will need to have compiled in php for cgi, this means returning to compilation of php, but clearing the configuration for apache2 and adding: \\ 
473 \\
474 \begin{tabular}{|l|}\hline
475 \verb|    |--prefix=/usr --enable-force-cgi-redirect --enable-fastcgi \textbackslash\\
476 \verb|    |--with-config-file-path=/etc/php4/cgi\\
477 \hline \end{tabular}
478 \vspace{0.5cm}
480 \noindent To configure in apache we will do the same as for SSL, first we verify if is enabled: \\
481 \\ 
482 \begin{tabular}{|l|}\hline
483 \#> if [ -h /etc/apache2/mods-enabled/suphp.load ]; then echo "enabled module";else echo "disabled module"; fi\\
484 \hline \end{tabular}
485 \vspace{0.5cm}
487 \noindent to activate it we will do the following: \\ 
488 \\ 
489 \begin{tabular}{|l|}\hline
490 \#>ln -s /etc/apache2/mods-available/suphp.conf /etc/apache2/mods-enabled/suphp.conf\\
491 \#>ln -s /etc/apache2/mods-available/suphp.load /etc/apache2/mods-enabled/suphp.load\\
492 \hline \end{tabular}
493 \vspace{0.5cm}
495 \noindent This will enable the module in apache2 and we will be able to use it after restarting the server with: \ 
496 \\ 
497 \begin{tabular}{|l|}\hline
498 \#>/etc/init.d/apache2 restart\\
499 \hline \end{tabular}
500 \vspace{0.5cm}
502 \noindent The configuration of the secure site with suphp included would be like this: \\ 
503 \\
504 \begin{tabular}{|l|}\hline
505 \noindent NameVirtual *:443\\
506 <VirtualHost *:443>\\
507 \verb|    |ServerName gosa.chaosdimension.org\\
508 \\
509 \verb|    |DocumentRoot /usr/share/gosa/html\\
510 \verb|    |alias /gosa /usr/share/gosa/html\\
511 \verb|    |CustomLog /var/log/apache/gosa.log combined\\
512 \verb|    |ErrorLog /var/log/apache/gosa.log\\
513 \\
514 \verb|    |suPHP\_Engine on\\
515 \\
516 \verb|    |SSLEngine On\\
517 \verb|    |SSLCertificateFile    /etc/apache2/ssl/gosa.cert\\
518 \verb|    |SSLCertificateKeyFile /etc/apache2/ssl/gosa.key\\
519 \verb|    |SSLCertificateChainFile /etc/apache2/ssl/gosa.cert\\
520 \verb|    |SSLCertificateKeyFile /etc/apache2/ssl/gosa.key\\
521 \verb|    |SSLCACertificateFile /etc/apache2/ssl/gosa.ca\\
522 \verb|    |SSLCACertificatePath /etc/apache2/ssl/\\
523 \verb|    |SSLLogLevel error\\
524 \verb|    |SSLLog /var/log/apache2/ssl-gosa.log\\
525 \\      
526 \verb|    |<Directory /usr/share/gosa >\\
527 \verb|    |\verb|    |SSLVerifyClient require\\
528 \verb|    |\verb|    |SSLVerifyDepth 1\\
529 \verb|    |</Directory>\\
530 </VirtualHost>\\
531 \hline \end{tabular}
532 \vspace{0.5cm}
534 \noindent We must decide which user we are going to use, in this case I am going to create one called "gosa", that will be is used for suphp:\\
535 \\
536 \begin{tabular}{|l|}\hline
537 \verb|    |\#>useradd -d /usr/share/gosa/html gosa\\
538 \verb|    |\#>passwd -l gosa\\
539 \verb|    |\#>cd /usr/share/gosa\\
540 \verb|    |\#>find /usr/share/gosa -name "*.php" -exec chown gosa {} ";"\\
541 \verb|    |\#>find /usr/share/gosa -name "*.php" -exec chmod 600 {} ";"\\
542 \hline \end{tabular}
543 \vspace{0.5cm}
544 \newpage
545 \section{PHP4 Configuration}
546 The configuration for mod\_php will be in the path that we had configured in the compilation of php4. In our case it is/etc/php4/apache2. 
548 The configuration file we always be named php.ini and we will enable the modules. 
550 A basic configuration will be like this:\\
551 \\
552 \begin{center}
553 \begin{longtable}{|l|}
554 \caption{PHP4 Configuration}\\
555 \hline
556 \multicolumn{1}{|c|}{\textbf{PHP4 Configuration}}\\
557 \hline
558 \endfirsthead
559 \hline
560 \endhead
561 \hline
562 \multicolumn{1}{|c|}{Continue $\ldots$}\\
563 \hline
564 \endfoot
565 \hline
566 \multicolumn{1}{|c|}{\textbf{End}}\\
567 \hline
568 \endlastfoot
569 ; Engine \\ 
570 \verb|    |engine   = On ; Activates PHP\\
571 \verb|    |short\_open\_tag = On ; allows to use <? to simplify <?php\\
572 \verb|    |asp\_tags  = Off ; We did not allow to labels style ASP: <\% \%>\\
573 \verb|    |precision  = 14 ; Number of significant digits shown in numbers in floating comma\\
574 \verb|    |output\_buffering = Off ; Only will be allowed send headers before send the content.\\
575 \verb|    |implicit\_flush  = Off ; We did not force to php to that cleans the exit buffer after each block.\\
576 \\ 
577 ; Safe Mode \\ 
578 \verb|    |\label{sm} safe\_mode  = Off ; We do not want the safe way\\
579 \verb|    |\label{smed} safe\_mode\_exec\_dir = ; Directory where PHP is executed\\
580 \verb|    |\label{smid} safe\_mode\_include\_dir = Directory where PHP will search PHP libraries\\
581 \verb|    |\label{smaev} safe\_mode\_allowed\_env\_vars = PHP\_     ; Only is allowed to the users\\
582 \verb|    |\verb|    |\verb|    |;to create system variables that begin with PHP\_\\
583 \verb|    |\label{smpev} safe\_mode\_protected\_env\_vars = LD\_LIBRARY\_PATH  ; List of system variables that\\
584 \verb|    |\verb|    |\verb|    |; can not be changed by security reasons.\\
585 \verb|    |\label{df} disable\_functions =        ; Functions that will be disabled for security reasons\\
586 \verb|    |\label{auf} allow\_url\_fopen = Yes ; We allowed that they open to archives from PHP\\
587 \verb|    |\label{ob} open\_basedir = ;\\
588 \ \ 
589 ;   Colors for the way of colored syntax. \ \ 
590 \verb|    |highlight.string = \#DD0000\\
591 \verb|    |highlight.comment = \#FF8000\\
592 \verb|    |highlight.keyword = \#007700\\
593 \verb|    |highlight.bg  = \#FFFFFF\\
594 \verb|    |highlight.default = \#0000BB\\
595 \verb|    |highlight.html  = \#000000\\
596 \\
597 ; Misc\\
598 \verb|    |\label{ep}expose\_php = On  ; It indicates in the message of the Web server if it is installed or no.\\
599 \\
600 ; Resource Limits ;\\
601 \verb|    |max\_execution\_time = 30     ; Maximum time of execution of script.\\
602 \verb|    |memory\_limit = 16M   ; Maximun memory allowed that can consume the script.\\
603 \\
604 ; Error handling and logging ;\\
605 \verb|    |error\_reporting = E\_ALL; We indicated that shows all the errors and warnings.\\
606 \verb|    |display\_errors = Off ; Does not print in screen.\\
607 \verb|    |display\_startup\_errors = Off  ; That does not show the errors of PHP starting.\\
608 \verb|    |log\_errors  = On ; That sends the errors to a file.\\
609 \verb|    |track\_errors = On ; That \$php\_errormsg keeps the last Error / Warning (boolean)\\
610 \verb|    |error\_log = /var/log/php/php4.log ; File that will keep the errors\\
611 \verb|    |warn\_plus\_overloading = Off  ; We did not warn if operator + is used with strings\\
612 \\
613 ; Data Handling ;\\
614 \verb|    |variables\_order  = "EGPCS" ; This directive describes the order in which\\
615 \verb|    |; will be registered the PHP variables (Being G=GET, P=POST, C=Cookie,\\
616 \verb|    |;  E = System, S = Own of PHP, all is indicated like EGPCS) \\
617 \verb|    |\label{rg} register\_globals = Off  ; We do not want that the EGPCS are registered like globals.\\
618 \verb|    |register\_argc\_argv = Off  ; We did not declare ARGV and ARGC for its use in scripts.\\
619 \verb|    |post\_max\_size  = 8M  ; Maximum size of sending POST that will accept PHP.\\
620 \\
621 ; Magic quotes\\
622 \verb|    |\label{mqq}magic\_quotes\_gpc = On  ; Quotes added fro GPC(GET/POST/Cookie data)\\
623 \verb|    |magic\_quotes\_runtime= Off  ; Quotes added for system generated data, \\
624 \verb|    |;for example from SQL, exec(), etc.\\
625 \verb|    |magic\_quotes\_sybase = Off  ; Use Sybase style added quotes.\\
626 \verb|    ;(escape ' with '' instead of \')|\\
627 \\
628 ; PHP default type of file and default codification.\\
629 \verb|    |default\_mimetype = "text/html"\\
630 \verb|    |default\_charset = "iso-8859-1"\\
631 \\
632 ; Routes and directories ;\\
633 \verb|    |\label{ip} include\_path = . ;\\
634 \verb|    |doc\_root  =     ; Root of the php pages, better is to leave in blank.\\
635 \verb|    |user\_dir  =     ; Where php executes scripts,better is to leave in blank.\\
636 \verb|    |;extension\_dir = /usr/lib/php4/apache   ; ¿Where the modules are?\\
637 \verb|    |enable\_dl  = Off    ; Allow or No the dymanic load of modules with the dl() function.\\
638 \\
639 ; Upload files to the server;\\
640 \verb|    |file\_uploads = On    ; Allow upload files to the server.\\
641 \verb|    |upload\_max\_filesize = 2M      ; Maximum size of the files we are going to upload.\\
642 \\
643 ; Dynamic Extensions ;\\
644 \verb|    |extension=gd.so         ; Graphics\\
645 \verb|    |extension=mysql.so      ; Mysql\\
646 \verb|    |extension=ldap.so       ; Ldap\\
647 \verb|    |extension=mhash.so      ; Mhash\\
648 \verb|    |extension=imap.so       ; Imap\\
649 \verb|    |extension=kadm5.so      ; Kerberos\\
650 \verb|    |extension=cups.so       ; Cupsys\\
651 \\
652 ; System Log \\
653 \verb|[Syslog]|\\
654 \verb|    |define\_syslog\_variables = Off ; We disabled the definition of syslog variables.\\
655 \\
656 ; mail functions\\
657 \verb|[mail function]|\\
658 \verb|    |;sendmail\_path =      ;In unix system, where is located sendmail (is 'sendmail -t -i' by default)\\
659 \\
660 ; debug\\
661 \verb|[Debugger]|\\
662 \verb|    |debugger.host = localhost ; Where is the debugger.\\
663 \verb|    |debugger.port = 7869    ; The port it is listening.\\
664 \verb|    |debugger.enabled = False ; We suppose there is not a debugger.\\
665 \\
666 ; SQL Options\\
667 \verb|[SQL]|\\
668 \verb|    |sql.safe\_mode = Off    ; SQL safe mode, we will disabled it.\\
669 \\
670 ; Mysql Options\\
671 \verb|[MySQL]|\\
672 \verb|    |mysql.allow\_persistent = Off ; We will disable the persistent links for security reasons.\\
673 \verb|    |mysql.max\_persistent = -1 ; Number of persistent connections, is not used when is disabled.\\
674 \verb|    |mysql.max\_links   = -1 ; Maximum number of connections, -1 is without limits.\\
675 \verb|    |mysql.default\_port  =  3306; Default port of mysql.\\
676 \verb|    |mysql.default\_socket =  ; Socket name that will be used for local mysql connections.\\
677 \verb|    |;If is void, will be use the default compilation configuration of PHP.\\
678 \verb|    |mysql.default\_host  =  ; No default host configured.\\
679 \verb|    |mysql.default\_user  =  ; No default user configured.\\
680 \verb|    |mysql.default\_password =  ; No default password configured.\\
681 \\
682 ; session control\\
683 \verb|[Session]|\\
684 \verb|    |session.save\_handler      = files   ; We saved the session information in files.\\
685 \verb|    |\label{ss} session.save\_path         = /var/lib/php4    ; Directory where is going to be saved the session files.\\
686 \verb|    |session.use\_cookies       = 1       ; We will use cookies for the session tracking.\\
687 \verb|    |session.name              = PHPSESSID   ; Name of the session that will be used in the name of the cookie.\\
688 \verb|    |session.auto\_start        = 0       ; We did not initiate session automatically.\\
689 \verb|    |session.cookie\_lifetime   = 0       ;  Time of life of a session cookie or 0 if we wait him to closes the navigator.\\
690 \verb|    |session.cookie\_path       = /       ; The path for which the cookie is valid.\\
691 \verb|    |session.cookie\_domain     =         ; The domain for which the cookie is valid.\\
692 \verb|    |session.serialize\_handler = php     ; Used manipulator to serialize the data.\\
693 \verb|    |session.gc\_probability    = 1       ; Probability in percentage that the garbage collector activates in each session.\\
694 \verb|    |session.gc\_maxlifetime    = 1440    ; After this time in seconds, the saved information\\
695 \verb|    |; will be look like garbage for the garbage collector.\\
696 \verb|    |session.referer\_check     =         ; Verifies HTTP Referer to invalidate externals URLs containing ids\\
697 \verb|    |session.entropy\_length    = 0       ; Number of bytes to be readed of the entropy file.\\
698 \verb|    |session.entropy\_file      =         ; The file that will generate the entropy.\\
699 \verb|    |session.cache\_limiter     = nocache ; Without session cache.\\
700 \verb|    |session.cache\_expire      = 180     ; document expiration time.\\
701 \verb|    |session.use\_trans\_sid     = 0       ; To use translate sid if is enabled in compilation time.\\
702 \\
703 \end{longtable}
704 \end{center}
706 \subsection{Security}
708 PHP is a powerful scripting language, it allows its users to have enough control over the system and to malicious attackers too many options to reach its objective. 
710 An system administrator does not have to suppose that a system is completely safe with only having installed security updates, a system that shows code to the outside is not safe, although the result is HTML, it is exposed to attacks of very diverse forms and failures of security not even know. 
712 Limit to the maximum the access that allows php is then a necessity. 
714 \subsection{Configuring safe php}
716 PHP has a mode \htmladdnormallink{safe-mode}{http://www.php.net/manual/en/features.safe-mode.php} that allows a greater security, a recommended configuration for Safe mode is: 
718 \begin{tabular}{|l|}\hline
719 \\
720 \verb|    |\ref{mqq} magic\_quotes\_qpc = On\\
721 \\
722 \verb|    |\ref{auf} allow\_url\_fopen = No\\
723 \\
724 \verb|    |\ref{rg} register\_globals = Off\\
725 \\
726 \verb|    |\ref{sm} safe\_mode = On\\
727 \\
728 \verb|    |\ref{smid} safe\_mode\_include\_dir = "/usr/share/gosa:/var/spool/gosa"\\
729 \\
730 \verb|    |\ref{smed} safe\_mode\_exec\_dir = "/usr/lib/gosa"\\
731 \\
732 \verb|    |\ref{smaev} safe\_mode\_allowed\_env\_vars = PHP\_,LANG\\
733 \\
734 \verb|    |\ref{ob} open\_basedir = "/etc/gosa:/var/spool/gosa:/var/cache/gosa:/usr/share/gosa:/tmp"\\
735 \\
736 \verb|    |\ref{ip} include\_path = ".:/usr/share/php:/usr/share/gosa:/var/spool/gosa:/usr/share/gosa/safe\_bin"\\
737 \\
738 \verb|    |\ref{df} disable\_functions = system, shell\_exec, passthru, phpinfo, show\_source\\
739 \\
740 \hline \end{tabular}
743 In the case we are going to use SuPHP, we must give the following permissions to the directory /var/lib/php4:\\
745 \begin{tabular}{|l|}\hline
746 \#>chmod 1777 /var/lib/php4\\
747 \hline \end{tabular}
749 Since each user who executes PHP kept the session with that user.
751 \section{Necessary PHP Modules}
753 In this section are explained the steps to be able to compile and to use the necessary or important modules for GOsa, is recommended to install all the modules, even those that are not necessary. 
755 \subsection{ldap.so}
757 NECCESARY MODULE
759 \indent This module does not need any special configuration to work.
760 Only knows a problem: PHP+Apache with cannot be connected with a LDAP server who requests valid Certificate. The communication will be safe, since SSL can be used, but will not be guaranteed. 
762 \subsection{mysql.so}
764 OPTIONAL MODULE
766 \indent This module does not need any special configuration to work. 
768 \indent Necessary to save the imap - sieve plugin configuration.
770 \subsection{imap.so}
772 OPTIONAL MODULE
774 \indent The installed module when compiling PHP work, but it will have an important deficiency, the function getacl that gives control on the folders, so we will need a patch and steps to compile the module for its use in GOsa. 
776 We download the patch from \htmladdnormallink{php4-imap-getacl.patch}{ftp://ftp.gonicus.de/gosa/contrib/php4-imap-getacl.patch} and we put it in/usr/src, as we have the sources of PHP in /usr/src, we executed the following command: 
778 \begin{tabular}{|l|}\hline
779 \#>cd /usr/src/php4.3-XXX/extensions/imap\\
780 \#>make clear\\
781 \#>patch -p1 </usr/src/patch/php4-imap-getacl.patch\\
782 \#>phpize\\
783 \#>./configure\\
784 \#>make\\
785 \#>make install\\
786 \hline \end{tabular}
788 This make and install the module correctly. 
790 \subsection{gd.so}
792 OPTIONAL MODULE
794 \indent This module does not need any special configuration to work. 
796 \indent The module is used for the handling of graphs, also used by the system of smarty templates. 
798 \subsection{cups}
800 OPTIONAL MODULE
802 \indent To use the Cups module for the selection of the printer in Posix, we must download the cups sources from \htmladdnormallink{http://www.cups.org/software.php}{http://www.cups.org/software.php} and decompress en /usr/src, then we executing the next commands:
803 \\
804 \noindent \begin{tabular}{|l|}\hline
805 \#cd /usr/src/cups-1.1.XX/scripting/php\\
806 \#phpize\\
807 \#./configure\\
808 \#make\\
809 \#make install\\
810 \#echo \verb|"extension=cups.so" >>| /etc/php4/apache2/php.init\\
811 \#/etc/init.d/apache2 reload\\
812 \hline \end{tabular}
815 \subsection{krb}
817 OPTIONAL MODULE
819 \indent This module need to have the MIT Kerberos sources installed, because it can not be compiled with the Heimdal Kerberos sources.
821 \indent The module will connect with the Kerberos servers to update the keys of the users.
823 Will download from \htmladdnormallink{PECL}{http://pecl.php.net/kadm5}, and descompress in /usr/src, we must have the MIT Kerberos sources also, descompress in /usr/src, with it will execute this: (changing X.X for the actual version of the programs):\\
824 \\
825 \noindent \begin{tabular}{|l|}\hline
826 \#cd /usr/src/kadm5-0.X.X/scripting/php\\
827 \#cp config.m4 config.m4.2\\
828 \#sed \verb|s/krb5-1\.2\.4\/src\/include/krb5-1\.X\.X\/src\/lib/| config.m4.2 >config.m4\\
829 \#rm -f config.m4.2\\
830 \#phpize\\
831 \#./configure\\
832 \#make\\
833 \#make install\\
834 \#echo \verb|"extension=kadm5.so" >>| /etc/php4/apache2/php.ini\\
835 \#/etc/init.d/apache2 reload\\
836 \hline \end{tabular}