Dysmey Post > Projects & Stuff > Janovac > Web

Web

Setting up Apache and PHP, which makes the Web site run.

Apache Configuration

The Web Server option in the Fedora installation includes the Apache Web server and the PHP scripting language. Although other Web servers are available, Apache and PHP are selected for installation by default.

Apache is listed among the startup services, but is not launched by default. This is because Apache's configuration file, httpd.conf in the folder /etc/httpd/conf, must be set up first.

The Apache configuration file uses variables called directives to set up how the Web server runs and where the Web site and its pages are. The paramount directives (to me) are these.

directive description default
Listen The port that Apache gets its HTTP information from. 80
ServerAdmin Server administrator's e-mail address. root@localhost
ServerName The name (or URL) of the Web site, optionally including its port. server's hostname
DocumentRoot The folder in the server where the home page of the Web site is. /var/www/html

To change the configuration file:

  1. Launch Terminal (Fedora → System Tools → Terminal).
  2. Run su and provide the root password.
  3. Navigate to /etc/httpd/conf
  4. Back up the configuration file by copying httpd.conf to httpd.conf.bak.
  5. Edit the configuration file with the vim editor.
  6. Run service httpd start
  7. Run exit twice (to leave the root account and then Terminal itself).

Launch Firefox or some other Web browser. In the address bar type http://janovac. If you are successful, you should see the Fedora Test Page.

Web Site Loading

You are not ready to load your Web site yet, because in Fedora's eyes you do not own the Web folder /var/www/html and its contents. This needs to be fixed first.

  1. At the menu bar launch System → Administration → Users and Groups.
  2. Under the Groups tab, highlight Apache.
    1. Press Properties.
    2. Under the Group Users tab, checkmark your account.
  3. Close Users and Groups.
  4. Launch Terminal.
  5. Run su and enter the root password.
  6. Navigate to /var/www.
  7. Run this: chown -R φ:apache html, where φ is your account name.
  8. Run this: chmod -R ug+rw html.
  9. Log out of root and exit Terminal.

The chown step assigns ownership of the /var/www/html folder and all its contents to your account. The chmod step gives you the ability to read and write files in /var/www/html. This is necessary to be able to edit the Web site from a Windows box, logged in to your account using Samba.

You can now load the Web site onto /var/www/html. Navigate to the root folder of the Web site on its backup medium (in Fedora, /media/diskname/ξ, where ξ is the root folder), and run cp -R . /var/www/html

PHP

If Apache is running, so is PHP. Finding out whether PHP is working is simple: In /var/www/html create or load a file named phpinfo.php with just one line: <?php phpinfo(); ?>. You should see a long informational page when you visit phpinfo.php on your Web browser. Seeing the one-liner only means that something is wrong with PHP.


Written by Andy West on 14 July 2009; updated 25 November 2009.