Installing Apache Server on Ubuntu

Links PageDownloadsPeopleVideoGames MenuEducational

LAMP Server - Linux (Ubuntu) + Apache + MySql + PHP/Pearl

Get on Our Mailing List

Installation Video Guide
Copy and Paste Package Manager Installs from Video

NOTE: Ubuntu, and Apache Server have been updated since the video above. This Procedure has been updated since the creation of the video.
The latest Ubuntu should be installed, and Updated using the update manager, prior to installing Apache Server, PHP, and SQL.

Installed Packages Listed by Video

Apache2
MySQL-Client
MySQL-Server
PHP5
PHP5-GD
PHP5-MySQL
PHPMyAdmin  (in universe repository)

PHP5-CGI  (add cgi support)

Open the Synaptics Package Manager.
Click the "Search Button" Copy and Paste each of the "Install Packages Listed by Video" above into the "Search" box, and Click "Search.
Locate the exact package you just searched for, and mark it for installation (It will automatically include it's dependencies).
When you have marked the entire list of packages, Click "Apply".
After Synaptics Package Manager has installed the list of packages above, proceed to the "Copy and Paste Command Lines from Video - Updated Procedure" below.

Copy and Paste Command Lines from Video - Updated Procedure

Summary/Example of the Terminal Command Lines I Use - In order
(With username of scott. You will need to change scott to your user name)

cd /etc
sudo chown -R scott apache2
ls -al
cd /etc/apache2/sites-enabled
sudo gedit 000-default

Edit the line  AllowOveride  from "None" to "All"  With Gedit then Save and exit.

sudo a2enmod rewrite
sudo /etc/init.d/apache2 restart
cd /var
sudo chown -R scott www

(Open "Terminal", then change to the etc directory/folder, with the (cd) change directory command - you can copy and paste at the Terminal Cursor)
 

(Take ownership of the apache2 directory recursively (-R) with the change owner (chown) command - If you are not sure what YOUR user name is, use the "list all" (ls -al) command on files and/or directories you know you own, like your Documents folder - replace UserName with your user name using gedit to edit the line below then copy and paste into "Terminal" at the cursor)
sudo chown -R UserName apache2

Verify that you have ownership of the apache2 directory.

ls -al

(You should see your user name listed in the row for the apache2 folder - If you only see root, you did not take ownership)

(Change to the sites-enabled directory/folder which is a sub-directory of the apache2 directory, with the (cd) change directory command)
cd /etc/apache2/sites-enabled

(List the files and sub-directories in the current directory you are in - sites-enabled)
ls

(Open the "000-default" file in Gedit (a text editor) with Root Ownership - The sudo command lets you execute commands with "root" ownership)
sudo gedit 000-default

(Change/Edit the line  AllowOveride  from "None" to "All"  With Gedit then Save the changes and exit gedit)
Example:
Look for the following lines near the top of the file:
Options Indexes FollowSymLinks Multiviews
Allow Override None

Change "Allow Override None" to:

Allow Override All

(Enable the rewrite apache module with root ownership)
sudo a2enmod rewrite

(Restart Apache Server - with root ownership)
sudo /etc/init.d/apache2 restart

(Change to the var sub-directory  using the cd command)
cd /var

ls

(Take ownership of the www directory with the change owner (chown) command - If you are not sure what YOUR user name is, use the "list all" (ls -al) command on files and/or directories you know you own, like your Documents folder - replace UserName with your user name using gedit to edit the line below then copy and paste into "Terminal" at the cursor)
sudo chown -R UserName www

Verify that you have ownership of the www directory.

ls -al

(Change to the www sub-directory  using the cd command - www is a sub-directory of the var directory)
cd /var/www

Take a look at what's there with the list command.

ls

You should see an index.html file.

Congratulations!!! You've just installed Apache Server!

Verify your apache Server is running, by opening your web browser, and typing, or copy and paste localhost in the browsers address bar. This will open the index.html file in the www directory, and display it in your browser.
Next try it using your computers IP address, by typing http:// (followed immediately and without a space by your computers IP address) in your browsers address bar. You can place your own web pages in the www directory, and when you access your Apache Server with a web browser, they will be displayed.

Test your Apache Server:

You can access Apache in your web browser using the address:  http://your server IP address or http://localhost
You can access phpMyAdmin in your web browser using the address http://localhost/phpmyadmin or  http://your server IP address/phpmyadmin
Default phpMyAdmin Log In User Name: root

Network Configuration

You will want to manually configure a static IP address on the computer hosting your server.
The static IP address can be used to access your Apache Server on your local area network (LAN), and to create your own intranet.
If you wish to access your Apache Server from the internet, you will need to edit your routers settings, to forward Port 80 to your servers IP address on your LAN.
A static IP address on the internet is also helpful for accessing your Apache Server from the internet.
Your ISP can usually provide you with a static IP address, sometimes free of charge, if you have the right type of service with them. There may even be a web interface on your ISP's web site, once you log into your account, which allows you to select a static (stable), or dynamic (changing) IP address.
If you cannot obtain a Static Internet IP address from your ISP, there are options available.
There are services available online, to provide static to dynamic IP address resolution.

Password Protecting Directories Hosted by Apache Server

There is a simple way to password protect folders in your Apache Server Hosted Directory.
You will need to create a .htaccess file, and place it in the folders you wish to password protect.
Make sure you include the dot (.) at the beginning of the file name.

Creating an .htaccess file:
You can copy and paste the following into gedit.
Edit the AuthName (If you desire), and AuthUserFile (to point to the path and filename you wish to store your User Names and passwords in, then save the file as .htaccess in every directory/folder you wish to protect with those User Names and Passwords:

AuthName "Log In"
AuthType Basic
AuthUserFile /etc/apache2/.htpasswd
require valid-user

AuthName is the Message the User Name and Password "Window" will display when asking users to log in.
AuthUserFile is the line with the path to the file that stores the usernames and encrypted passwords, that will be used for access to the folder you wish to password protect. The file does not have to be named .htpasswd, as in this example, but the .htaccess file in the folder you wish to password protect must point to it, and name it correctly.
For the sake of this guide, we will stick with the .htpasswd file name and the apache2 directory for it's location.
We took ownership of the apache2 folder/directory earlier, so this is convenient to work with for the sake of this guide.
Next we will want to create our User Name and Password List (.htpasswd) file:

Creating the .htpasswd file:

Open "Terminal" in Ubuntu.
Place the User Name you wish to add to your user name and password list, on the end of the following command line, in place of "UserName" (without quotes), then enter the desired password when prompted.
To create a NEW .htpasswd file in the apache2 folder/directory, where none exists use the -c option (create new).
Copy and Paste the following to "Terminal" at the prompt, and backspace/edit UserName (.htpasswd can also be edited/changed if you desire a different file name for your password list, but .htaccess must designate the name - handy if you have different access lists, for different directories.)

htpasswd -c /etc/apache2/.htpasswd UserName

For example to create a New .htpasswd file (the .htpasswd right before steve is the file name you are creating, which can be changed), with the initial/first user name entry of scott, you would enter:

htpasswd -c /etc/apache2/.htpasswd scott

Syntax: htpasswd optionalswitch path&filename username

Adding log ins to the .htpasswd file:

To ADD an additional log in to an existing .htpasswd file in the apache2 folder/directory (Notice the -c is NOT USED to add log ins):
Copy and Paste the following to "Terminal" at the prompt, and backspace/edit UserName (.htpasswd can also be edited/changed if you desire a different file name for your password list, but .htaccess must designate the name - handy if you have different access lists, for different directories.)

htpasswd /etc/apache2/.htpasswd UserName

Place the .htaccess file in the directory you wish to password protect with a path to the .htpasswd file.
.htpasswd can have other names, as long as the .htaccess file references it by the correct path and file name.
When .htaccess is placed in a folder/directory it password protects that directory, and all it's subdirectories.

Test Apache for PHP Support

Testing Apache for PHP Support:
To test weather your php is installed correctly, or not, create a test file using the following command:
sudo gedit /var/www/test.php

Insert (Copy and Paste) the following line into the new file:

<?php phpinfo();?>

Save this file.

Now access this page in your web browser using the address:  http://yourserverip/test.php
You should see a PHP Window with information about your Servers PHP.

Apache Server Configuration

The main configuration file located at /etc/apache2/apche2.conf in Windows, is located at  /etc/apache2/sites-enabled/000-default in Ubuntu.
We will be dealing with Apache2 in Ubunto (Linux).

All Apache configuration files in Ubuntu are located at:  /etc/apache2
The default "document root" for apache2 is located at:  /var/www

Document Root:
If you want to change the default document root you need to edit the  /etc/apache2/sites-available/000-default  file, and look for this line: DocumentRoot /var/www/
change /var/www/ to any location you want Apache Server to Host.
For example, if you want to change the default document root to  /home/www  the line would look like this:
DocumentRoot /home/www/

Port:
By default Apache2 is set to Listen on port 80. (For HTTP you will want to keep port 80 - it is the standard port for http - web browsing)
You may, however, wish to add ports to the list of ports Apache listens on.
If this is not desired, edit  /etc/apache2/ports.conf  and  /etc/apache2/sites-enabled/000-default as desired.
After changing the ports.conf , and 000-default files, you need restart apache server for your changes to take effect.

For example:
If you want to change your apache webserver port to 78 you need to edit /etc/apache2/ports.conf and /etc/apache2/sites-enabled/000-default

sudo gedit /etc/apache2/ports.conf

Look for the following line:

NameVirtualHost *:80
Listen 80

Replace with the following line (Change 80 to 78):

NameVirtualHost *:78
Listen 78

Save the edited file.

sudo gedit /etc/apache2/sites-enabled/000-default

Look for the following line:

<VirtualHost *:80>

Replace with the following line (Change 80 to 78):

<VirtualHost *:78>

Restart Apache Server:

sudo /etc/init.d/apache2 restart

PHP Configuration:
The php.ini file is the file used to configure php for Apache server. php.ini is located in the following location:

etc/php5/apache2/php.ini

The path to PHP sendmail is:

/usr/lib/sendmail

Enabling Apache Modules

If you want to enable some Apache modules (SSL, rewrite, suexec, and include)

sudo a2enmod ssl

sudo a2enmod rewrite

sudo a2enmod suexec

sudo a2enmod include

Restart Apache to put the changes in effect using the following line:

sudo /etc/init.d/apache2 restart

Additional Reading

Apache Server for Linux/Ubuntu 1
Apache Server for Linux/Ubuntu 2
Apache Server for Linux/Ubuntu 3

Apache Server Documentation
MySQL
PHP Documentation

Other Cool Additions to Consider

Additional Packages to Consider (Synaptics Package Manager):

libapache2-mod-perl2  (Pearl)
ruby  (Ruby)
python-apache-openid  (Python)
libapache2-mod-wsgi  (Python - Web Server Gateway Interface)
libapache2-mod-mono   (ASP.net for Apache)

Mail Server SMTP:
postfix
exim4

Mail Server IMAP/POP3:
courier-faxmail
dovecot-postfix

Spam Filtering:
spamassasin
dovecot-antispam

Browser Based Mail Interface:
squirrelmail  (Runs on top of any IMAP Server)
prayer ( webmail interface for IMAP servers )

FTP Servers:
ProFTPd
PureFTPd
wu-ftpd (powerful and widely used FTP server - Outdated)

DNS Server:
bind9
pdns-server  (PowerDNS - includes bind)

Log File Analyzers:
awstats (Advanced web statistics - Log file analyzer)
libnss (system log in with mySQL)
webdruid (A web server log file analysis tool)
visitors   (A web server log file analysis tool)

Configuration / Control Panel:
syscp   (system control panel for LAMP servers)
php-config ( http://pear.php.net/package/Config )
webgui (Content management platform to maintain complex web sites)

Security:
libapache2-webauth
libapache2-webkdc
pwauth
chroot
sugarplum ( contaminates spammers databases )
apache security   (Just a search in Synaptics package manager)

Blogging:
wordpress
b2evolution
zine
movabletype-opensource
tomboy-blogposter   (Blog Utility)

Wiki:
python-moinmoin

Photo Sharing:
memories

Web Site Builders:
pubtal
rest2web
simplyhtml

Social Networking / ePortfolio:
mahara-apache2   (ePortfolio - Social Netwrking Site)

Other:
tomcat6   (Java Server for Apache)
google (Google Gadgets for Linux)

Drupal

In Synaptics Package Manager In Terminal
drupal6 sudo apt-get install drupal6

 

 

 

Stream your music

This works with MP3, FLAC, Ogg Vorbis or MP4/AAC files.

Untested INSTALL PROCEDURE 1 (stream using musicindex and icecast2):

Package Installation

In Synaptics Package Manager:

In Terminal:

libapache2-mod-musicindex

icecast2

libogg-dev

 libvorbis-dev

libid3tag0-dev

libmad0-dev

libflac-dev

apt-get install libapache2-mod-musicindex icecast2 libogg-dev
apt-get install libvorbis-dev libid3tag0-dev libmad0-dev libflac-dev

Configuration

MusicIndex and IceCast2 run on two different ports. MusicIndex  links to the music files via IceCast2.

Edit the  /etc/icecast2/icecast.xml   file.
Changed the source-password, relay-password, admin-password, hostname and loglevel from the default file.

In Terminal   cd /usr/share/icecast2/web
InTerminal

Add a link to your mp3 directory

If your MP3's are in: /archive/mp3 type the following into Terminal:

ln -s /archive/mp3 mp3      in the   /usr/share/icecast2/web  directory
Make sure that the mod is listed in the /etc/apache2/mods-enabled directory.
This will set up the music index and configure it to point to the icecast server.
Add something like the following to your default site configuration or mod config file:

Alias /mp3/ "/archive/mp3/"

Options Indexes MultiViews FollowSymlinks
AllowOverride None
Order allow,deny
Allow from 127.0.0.0/255.0.0.0 ::1/128
Allow from 192.168.0.0/255.255.255.0
MusicLister On
MusicSortOrder album disc track artist filename title length bitrate filetype uri
MusicFields title artist length bitrate
MusicAllowDownload Off
MusicAllowStream On
MusicAllowSearch On
MusicPageTitle My MP3 Collection
MusicCssDefault musicindex.css
MusicCachePath /tmp/musicindex
MusicIceServer home.awtrey.com:8000
MusicCookieLife 300

In Terminal

cd /etc/default

Open this file in gedit

sudo gedit icecast2

Add this

"ENABLE=true"

Save the file, and close gedit
In Terminal

sudo /etc/init.d/icecast2 start

Untested INSTALL PROCEDURE 2 (stream using musicindex only):

Package Installation

 
libapache2-mod-musicindex

libogg-dev

 libvorbis-dev

libid3tag0-dev

libmad0-dev

libflac-dev

cd  /etc/apache2/sites-enabled
sudo gedit 000-default
Add this line to 000-default LoadModule musicindex_module /usr/lib/apache2/modules/mod_musicindex.so
Finally, edit the <Directory> you want to use
This example uses the /etc/apache2/conf.d/alias file

Assuming your music is in /home/foo/music the settings should look like these:

Code:
Alias /music /home/foo/music/
<Directory /home/foo/music/>
Options Indexes MultiViews FollowSymlinks
AllowOverride Indexes
MusicLister On
MusicSortOrder album disc track artist title length bitrate freq filet$
MusicFields title artist length bitrate
MusicAllowDownload Off
MusicAllowStream On
MusicAllowSearch On
# MusicRssItems Off
MusicPageTitle home
MusicCssDefault musicindex.css
MusicCachePath /tmp/musicindex
# MusicIceServer [ice.domain.my]:8000
# MusicCookieLife 300
sudo /etc/init.d/icecast2 start
This example you'd access @ http://localhost/music

Your Server is now ready to stream!

Cosmetic changes

The interface doesn't look so good out of the box I think.
A simple way to change it a bit is the file   /var/www/musicindex/musicindex.css
Change from Change to
table#directories div > a.rss {
font-size: 10pt;
}
table#directories div > a.rss {
font-size: 10pt;
margin-left:200px;
}
You'll have a much better view because of space between the directories
Other Web Servers Compatible with Ubuntu - Apache alternatives

cherokee   (GUI controlled web server)
lighttpd   (small web server)

Groupware Servers:
citadel-suite
kolabd

Other Related Topics of Interest
Ubuntu Install and Set Up Guide
Guide to setting up Networks & Wireless Networks
Get Help in the Ubuntu Classroom - IRC Chat Room
Links PageDownloadsPeopleVideoGames MenuEducational
 Copyright 2008  http://www.bestyoucanget.com All Rights Reserved See Terms of Use