Tung httpd conf

From CDOT Wiki
Revision as of 21:16, 27 July 2011 by Tpcheun1 (talk | contribs)
Jump to: navigation, search

Running and Configuring Apache Server

Introduction

In this page, you are going to set up a Apache server and allow a user create his own personal web page.

Creating a Public Web Page

  1. Login as root user
  2. Configure the Apache server to start when the Fedora is booted: chkconfig httpd on
  3. Start the Apache server: service httpd start
  4. Create index.html in /var/www/html/ directory, write some html code in the file
  5. Open a browser, and enter http://localhost . Your page should display.
  6. Make web page accesses by other hosts: iptables -I INPUT -p tcp --dport http -j ACCEPT

Serving Personal Home Page

  1. Login as root user
  2. Edit Apache Server configuration file /etc/httpd/conf/httpd.conf
    • Inside IfModule tag, comment “UserDir disable” and uncomment “UserDir public_html”
      <IfModule mod_userdir.c>
      #UserDir disable
      UserDir public_html
      </IfModule>
  3. Restart the Apache server: service httpd restart
  4. Logout root
  5. Create a public_html directory inside your home directory
  6. Change the permission of your home directory and the public_html to read and execute for other, so that the server can assess files in public_html by name. Enter follow command:
    • chmod 705 /home/user/public_html
    • chmod 705 /home/user
  7. Create index.html in public_html directory, write some html code in the file.
  8. Change the permission of index.htm to read only for other: chmod 704 /home/user/public_html/index.html
  9. By default, selinux doesn't allow Apache Server to read file inside user's home. Change the default setting: setsebool -P httpd_enable_homedirs 1
  10. Check the context of public_html and index
    • By default, selinux has context type httpd_user_content_t for /home/[^/]*/((www)|(web)|(public_html))(/.+)?
    • Confirm the context type is correct: ls -Z public_html
  11. Open a browser, and enter http://hostname/~your-user-id/. Your personal page should display.

Create a web script in user's home

  1. Login as a root
  2. Edit configuration file /etc/httpd/conf/httpd.conf again. Add lines
  3. Restart the Apache server: service httpd restart
  4. By default, selinux doesn't allow Apache Server to read file inside user's home. Change the default setting: setsebool -P httpd_enable_cgi 1
  5. Add context type to make script exexutable. To do that you need to add expressions for cgi file and public_html that more specific that the default expression.
    • For public_html: semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html"
    • For cgi files: semanage fcontext -at httpd_sys_script_exec_t "/home/[^/]*/public_html/.+\.cgi"
    • For non-cgi files: semanage fcontext -at httpd_user_content_t "/home/[^/]*/public_html/.+"
  6. Apply the context: restorecon -vRF public_html
  7. Logout root
  8. Create diskfree.cgi and change its permission to executable: chmod 705 /home/user/public_html/*.cgi
  9. Write lines in diskfree.cgi
  10. Open a browser, and enter http://hostname/~your-user-id/diskfree.cgi . The disk usage of your computer should be displayed.