Easy guide to installing a Web server (Apache & MySQL) on Ubuntu



How to set up a Web server on your Ubuntu (Lucid Lynx and others) system? This tutorial will help you install an Apache server with MySQL and PHP. We will also have phpMyadmin for easy control over database, and Webmin to have access to the server via your Web browser. Execute the following commands in Applications -> Accessories -> Terminal.

If any command refuses to execute due to limited privileges, add sudo before it. E.g., sudo command.

Install Apache

sudo apt-get install apache2

Install PHP5

sudo apt-get install php5 libapache2-mod-php5

Restart Apache to activate PHP

sudo /etc/init.d/apache2 restart

Enable mod rewrite: Mod-Rewrite is required to be enabled some functions such as beautiful URLs in Wordpress. Run the following command to enable.

a2enmod rewrite

If problem exists, edit the Apache file.

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

Now find the following and change AllowOverride None to AllowOverride All.


Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
# Uncomment this directive is you want to see apache2's
# default start page (in /apache2-default) when you go to /
#RedirectMatch ^/$ /apache2-default/

Install MySQL: Run the command given below and set the password for "root" user on prompt.

sudo apt-get install mysql-server mysql-client php5-mysql

Edit the "Bind Address" This is required only if you have to access the server on network. It's not required if the server will work only on the local computer.

gksudo gedit /etc/mysql/my.cnf

Change the IP address (127.0.0.1) to your IP address in the following line.

bind-address = 127.0.0.1

Install phpMyadmin: This provides an easy web-based access to MySQl control. Run the following command.

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

It will lead you to a screen asking you to select the Web server that needs to be automatically configure with phpMyadmin. Use <Tab> key to highlight the Apache option and select it by pressing the <Space> bar. Make sure that the Apache option has been selected; you will see an asterisk [*] mark by its side. Now use the <Tab> key to highlight the OK option and press <Enter> key.

It will take you to another screen providing some details. Continue the process by pressing the <Enter> key.

A screen will appear asking if you want to configure a new database called dbconfig-common. As we are installing the a fresh server, use the key to select Yes and press <Enter>.

Now you will be prompted to enter the password for the administrator user "root". Type the password that you had given while installing MySQL. Use <Tab> key to highlight the OK option and press <Enter> key.

Now you will asked to set a password for phpMyAdmin. For sake of ease, enter  the password same as that for MySQL. Retype the password on prompt and hit <Enter>.

Restart Apache

sudo /etc/init.d/apache2 restart

Now your Apache server and MySQL are ready. You can access your server by typing http://localhost/. To access phpMyadmin page use the following URL: http://localhost/phpmyadmin. Use "root" as the user name and the password set in the above process for getting access.

If there's any problem in the phpMyadmin,
you may have to edit php.ini file to make PHP work with MySQL.

gksudo gedit /etc/php5/apache2/php.ini

Now, find this line:

;extension=mysql.so

Remove the semicolon to make it active.

extension=mysql.so

Restart Apache.

sudo /etc/init.d/apache2 restart

Access phpMyadmin page by using the following URL: http://localhost/phpmyadmin.

Install Webmin (optional): Webmin allows you to control your server from a Web browser. It will allow you to stop or restrart Apache, create aliases (used to point URLs to a folder on the local computer) and lot more.

Download the latest version (.deb) of Webmin and install the application by running it. Now log in to Webmin using the following URL: http://localhost:10000, or http://ipaddress:10000.

By default, http://localhost/ points to Home/var/www/. To create new domains or aliases, say http://localhost/blog, using Webmin, go to Servers -> Apache webserver ->Default Server. Now click on the "Aliases" icon. In the page that opens, under "Document directory aliases" section, enter "/blog" under "From" list and "/var/www/blog/" under the "To" list. This means that whenever we will type http://localhost/blog, we will be redirected to /var/www/blog folder. But right now there is no folder called blog in var/www/ folder. Let's create it.

Since only root has the right to make changes to var/www/ folder, we will log in as "root".

su

Now create the folder.

mkdir /var/www/blog

Now you can save the files that you want to appear under this domain. If you wish a Wordpress blog to be set up here, just move the entire content of Wordpress folder here. Make the necessary changes in database, etc., to get your Wordpress blog at http://localhost/blog/. Learn about installing Wordpress in this post.

PS: This is the last in a series on switching to Ubuntu from Windows, for non-geeks. Hope you are now comfortable with your Ubuntu system. This doesn't stop me from writing more about my primary OS -- Ubuntu.

Ubuntu series:
Part1: Easy guide to getting started with Ubuntu
Part2: Dual-boot Ubuntu and Windows with common storage drives
Part3: Make Ubuntu mount partitions and drives automatically at startup
Part4: Activating restricted music formats, Java and Flash on Ubuntu
Part5: Installing some basic applications on your Ubuntu system
Part6: How to install and completely remove Wine?
Part7: Easily tweak Ubuntu with Ubuntu Tweak
Part8: Tasque manages to-do list locally or integrates with Remember The Milk
Part9: AllTray: Dock every application in tray
Part10: Install a Web server on Ubuntu home computer

Labels:  , ,

Author: Pritam P Hans

Date: Saturday, March 14, 2009

0 comments | Leave a comment

0 Responses to "Easy guide to installing a Web server (Apache & MySQL) on Ubuntu"

Post a Comment