Working with Apache

Overview

These instructions assume that you installed CentOS as documented in Base Installation of a CentOS Server.

Install Apache

Install apache 2 daemon (called httpd).

yum install httpd

Configure httpd to run when the system initializes.

chkconfig httpd on

To start the daemon now with out rebooting, do the following.

service httpd start

Test your server by opening port 80, and then test with a browser. (See How to Open a Port if you don't know how to open port 80.)

If there is no index file in /var/www/html, then apache serves /var/www/error/noindex.html. Create file /var/www/html/index.html with some trivial content, and then test that you can retrieve it through a browser.

If you are going to use https, then you need to install mod_ssl.

yum install mod_ssl

Open port 443, restart the https service, and test that you can retrieve the same content using https.

If you want a recent version of PHP and MySQL from the remi repo, do the following.

cd /etc/yum.repos.d/
wget http://rpms.famillecollet.com/remi-enterprise.repo
yum --enablerepo remi install php mysql-server php-mysql mod_ssl

If you want a standard installation, do the following.

yum install php mysql-server php-mysql

To test that php was installed and is operational, create file /var/www/html/hi.php with the following contents.

<?php echo "hi"; ?>

Restart httpd, and then request this file though a browser, and verify that you see a page with the word hi.


How to Password Protect a Directory

Create a file called password_digests, generate a password digest for username turner, and add it to the file. (The -c flag causes htpasswd to create a new file.)

htpasswd -c /var/www/password_digests turner

To add additional password digests, do not include the file creation flag -c.

htpasswd /var/www/password_digests smith

Suppose you wish to protect the folder /var/www/wikis/sysadmin. Add the following lines to the <Directory "/var/www/wikis/sysadmin"> section in the appropriate apache configuration file.

   AuthType Basic
   AuthName "admin"
   AuthUserFile /var/www/password_digests
   Require user turner

How to setup accounts to let multiple users edit content

Note that the following procedure can lead to conflicts when more than one user tries to modiy the same file.

Create a group called web, add users to it, and set the SGID attribute on /var/www/html so that subfolders and files will inherit the web group, change group of html to web, and et the umask so that group members have same permissions on newly created folders.

groupadd web
usermod -a -G web turner
chmod g+s /var/www/html
chown -R apache:web /var/www/html

Modify /etc/bashrc so that umask is set to 002.