In this article, we are going to see how to set up a web server in Ubuntu Server. Before that, I want to give credit for this article to Mike of www.funwithlinux.net. I learnt how to install the web server from this article, made some mistakes initially but finally successful.
What is a web server? It is a server which hosts websites. Each and every website has a server. Most web servers are set up on Linux for the primary reason that it is free. I am going to set up my web server on Ubuntu Server 12.04.
To set up a web server we are going to install four components, Apache (server software), PHP (scripting language used to create webpages), MYSQL (database), PHP-MYSQL (MySQL support in PHP ). Login as root into Ubuntu server.
In the terminal type “apt-get install apache2″to install Apache package. Type ‘Y’ when system prompts you to continue.
To check whether apache packages have been installed or not type the command “wget localhost index.html” in the terminal. This will download the index.html file to the local directory. Type “ls”to see if the file has been downloaded or not. If it is present, apache has been correctly installed.
The apache2 config file is located at “/etc/apache2/”. In this same directory we have a directory named ‘conf.d’. Configuration files( files with the suffix .conf ) in this directory will be parsed by apache2 during startup. If we intend to run multiple sites from the same server, we need to put our config files here. Let’s create a file name “shunya.com.conf”.
In the file shunya.com.conf, add the following text and save the file. The first line tells Apache to listen on port 80. The second line shows the ServerAdmin and is optional. The third line shows our web server’s root directory. The fourth line is host header Apache2 will listen for, as sent by the end user’s browser. The fifth line is the file used for logging errors. This line is also optional but is very helpful. The settings not configured under <VirtualHost> tags will be inherited from apache2.conf or other configuration files. Close the file by typing “:wq”.
As we created the config file of our host, we need to create our root directory referenced in the config file i.e “/var/www/shunya.com”. Navigate to the directory by typing “cd /var/www/”. Create new directory named ‘shunya.com’ by typing “mkdir shunya.com”. Make the root user the owner of the directory by typing the command “chown root:www-data /var/www/shunya.com -R”. Make this directory readable and executable by typing the command “chmod 550 /var/www/shunya.com -R”.
Create a file named index.php in our root directory shunya.com.
Edit the file as below. We will echo some Archimedes in our index.php file. Save and exit the file.
Next, we have to install PHP. Type the command “apt-get install php5″.Type Y at appropriate prompts.
Reload the apache config file by typing “service apache2 reload”. Then restart the apache service using “service apache2 restart”.
Let’s see if our website is working. From a remote machine which has access to your web server open the browser and type the IP address of the web server. If we get “Eureka Eureka” displayed, then our server is working.
Install MySQL server by typing “apt-get install mysql-server”.
The system will prompt you to set a root user password for MYSQL. Set the password and confirm it again.
Type the command “apt-get install php5-mysql” to install MySQL support for PHP.
The latest release of Ubuntu Server is the 13.04 which includes the latest features including Grizzly release of OpenStack but this release is only supported for nine months. So in this guide I am going to show how to install Ubuntu server 12.04 LTS which is supported till 2017 here. If you want a torrent download, you can get it here. After downloading the image, burn it to a CD/DVD. Load the CD/DVD to drive and boot from it. The system will prompt us to select the language. Select English or whatever language you prefer.
Then click on “Install Ubuntu Server”.
Then choose the language to be used for the installation process which will also be set for the installed system. I chose English.
Then the system will ask you to select your location. This location will be used automatically set your time zone. There is a list of some countries. If your country is not displayed in the list click “Other otherwise click on your country. I selected India.
Then the system will ask whether you want it to detect the keyboard layout. If you don’t know your keyboard layout, select “Yes otherwise select “No”.
If you select No, it will ask you to select the keyboard layout. My selection is “English(US)”.
Then the system will start loading additional components.
Then the system will autoconfigure your network with DHCP.
Then the system will prompt you to enter a hostname for the computer. I named it as ubuntu.
Then the system will ask you to create an user account. The username should start with a lowercase letter and can be a combination of letters and numbers.
Then you are asked to set a password for the user account created. The password should contain a mixture of letters, numbers and punctuation.
Then you are asked to verify the password by typing it once again.
Then you are asked if you want to encrypt your home directory or not. Encryption prevents your files to be compromised even if your computer is stolen. I recommend you to select “Yes”.
Based on the location we chose above, our time zone is selected. If your time zone is correct, select “Yes” otherwise No to change it.
Then you are asked to choose your partitioning method.
Then you are asked to select the disk to be partitioned.
Then you are shown the summary of partitions to be formatted and whether you want to write the changes to the disks. Select “Yes”.
Then installation of base system is started.
If you want to connect with the outside world through HTTP proxy, give the information otherwise leave it blank.
Then configuration of apt starts.
After the configuration, installation of software starts.
Then you are asked to select how do you manage upgrades to the system. I recommend you to select “Automatic security updates”.
Then you are given a choice to install predefined software applications. If you intend to set a web server, you can select LAMP server here.
The system will install the selected features and it will clean up.
If this the only OS on your computer, the system will ask you if you want to install the GRUB bootloader.
After GRUB is installed, installation is completed. Remove your DVD.
You are asked to provide your authentication. Enter the credentials you gave while installing the system and this screen below should greet you.