|
|
Line 1: |
Line 1: |
− | ==Running and Configuring Apache Server==
| |
| | | |
− | <big><b>Introduction</b>
| |
− |
| |
− | <font face="Georgia">In this page, you are going to set up a Apache server and allow a user create his own personal web page.
| |
− | </font></big>
| |
− |
| |
− |
| |
− | ===Creating a Public Web Page===
| |
− | # Login as root user
| |
− | # Configure the Apache server to start when the Fedora is booted: <b><code><font color=green >chkconfig httpd on</font></code></b>
| |
− | # Start the Apache server: <b><code><font color=green >service httpd start</font></code></b>
| |
− | # Create index.html in <b><code><font color=brown >/var/www/html/ </font></code></b>directory, write some html code in the file
| |
− | # Open a browser, and enter <code> http://localhost </code>. Your page should display.
| |
− | # Make web page available to other hosts: <b><code><font color=green >iptables -I INPUT -p tcp --dport http -j ACCEPT</font></code></b>
| |
− |
| |
− | ===Serving Personal Home Page===
| |
− |
| |
− | # Login as root user
| |
− | # Edit Apache Server configuration file <b><code><font color=brown > /etc/httpd/conf/httpd.conf </font></code></b>
| |
− | #* Inside IfModule tag, comment <b>“UserDir disable”</b> and uncomment <b>“UserDir public_html”</b>
| |
− | #*:<font color=orange ><code><IfModule mod_userdir.c>
| |
− | #*:: #UserDir disable
| |
− | #*:: UserDir public_html
| |
− | #*:</IfModule></code></font>
| |
− | # Restart the Apache server: <b><code><font color=green > service httpd restart</font></code></b>
| |
− | # Logout root
| |
− | # Create a <b>public_html</b> directory inside your home directory
| |
− | # Change the permission of your home directory and the <b>public_html</b> to read and execute for other, so that the server can access files in <b>public_html</b> by name. Enter follow command:
| |
− | #* <b><code><font color=green > chmod 705 /home/user/public_html </font></code></b>
| |
− | #* <b><code><font color=green > chmod 705 /home/user </font></code></b>
| |
− | # Create index.html in <b>public_html</b> directory, write some html code in the file.
| |
− | # Change the permission of index.htm to read only for other: <b><code><font color=green >chmod 704 /home/user/public_html/index.html </font></code></b>
| |
− | # By default, selinux doesn't allow Apache Server to read file inside user's home. Change the default setting: <b><code><font color=green >setsebool -P httpd_enable_homedirs 1 </font></code></b>
| |
− | # Check the context of public_html and index
| |
− | #* By default, selinux has <code><font color=purple >context type httpd_user_content_t</font></code> for <code><font color=purple >/home/[^/]*/((www)|(web)|(public_html))(/.+)?</font></code>
| |
− | #* Confirm the context type is correct: <b><code><font color=green >ls -Z public_html</font></code></b>
| |
− | # Open a browser, and enter <code> http://hostname/~user/</code>. Your personal page should display.
| |
− |
| |
− | ===Create a cgi script in user's home===
| |
− | #Login as a root
| |
− | #Edit configuration file <b><code><font color=brown >/etc/httpd/conf/httpd.conf </font></code></b>again. Add handler for .cgi and exec cgi option
| |
− | #:<font color=orange ><code><Directory /home/*/public_html>
| |
− | #:: Options +ExecCGI
| |
− | #:: AddHandler cgi-script .cgi
| |
− | #:</Directory> </code></font>
| |
− | #Restart the Apache server: <b><code><font color=green >service httpd restart</font></code></b>
| |
− | #By default, selinux doesn't allow Apache Server to read file inside user's home.
| |
− | #:Change the default setting:<b><code><font color=green > setsebool -P httpd_enable_cgi 1</font></code></b>
| |
− | #Add context type to make script exexutable. The expressions for cgi file and public_html must be more specific than the default expression:<b><code><font color=purple>" /home/[^/]*/((www)|(web)|(public_html))(/.+)?" </font></code></b>.
| |
− | #*For public_html: <b><code><font color=green >semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html"</font></code></b>
| |
− | #*For cgi files: <b><code><font color=green >semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html/.+\.cgi"</font></code></b>
| |
− | #*For non-cgi files: <b><code><font color=green >semanage fcontext -at httpd_user_content_t "/home/[^/]*/public_html/.+"</font></code></b>
| |
− | #Apply the context: restorecon <b><code><font color=green >-vRF public_html</font></code></b>
| |
− | #Confirm the context types are correct: <b><code><font color=green >ls -Z public_html</font></code></b>
| |
− | #Logout root
| |
− | #Create diskfree.cgi and change its permission to executable: <b><code><font color=green >chmod 705 /home/user/public_html/*.cgi</font></code></b>
| |
− | #Edit diskfree.cgi and write below code to the file
| |
− | #:<font color=orange ><code>#!/bin/bash
| |
− | #:echo "Content-type: text/plain"
| |
− | #:echo ""
| |
− | #:df -h </code></font>
| |
− | #Open a browser, and enter <code>http://hostname/~user/diskfree.cgi</code> . The disk usage of your computer should be displayed.
| |
− |
| |
− |
| |
− | [[File:Diskfree cgi.png| border ]]
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− |
| |
− | [[File:Apache logo xyz.png]]
| |