Setting up your own web server can be a fun thing, simply because you can customize the things you want and optimize it to perform at the highest level. Previously, we have shown you how to install a LAMP server in your Ubuntu machine, but that is using a GUI and it won’t work if you are administering a remote host. Here’s how you can setup a Ubuntu web server on a remote host.
Note: Before we start, we have to assume that:
1. You already have SSH access to your remote host. For security sake, you might want to setup a public/private SSH key to secure your SSH connection.
2. The remote host is in a fresh state. No additional software have been installed or any other user has been created.
1. Open a terminal (if you are using Windows, use Putty) and SSH to your remote host.
2. The first thing to do is to update your remote host so that it is running the latest version of all software.
sudo apt-get update sudo apt-get upgrade
3. If you are logging in as the root user, it is best to change the default password for the root user and also create a new user account. It is not a good practice to log in as the root user. Once the new user account is created, you will administer the remote host with this account.
Change the password for the root user.
Create new user account.
adduser username #replace "username" with your own your user name.
It will prompt you to enter your user password and info.
Add the new user to the “sudo” group.
adduser username sudo
Once this is done, you will need to exit the current SSH session and re-login with the new user account.
4. Install LAMP Server. There is no Synaptic or Ubuntu Software Center here, so we have to install everything via the terminal. While you can install a whole bunch of files here, an easier way is to use the tasksel package.
sudo apt-get install tasksel sudo tasksel install lamp-server
During the installation, it will prompt you a few questions.
Once the installation is done, go to your web browser and type in the domain name (or IP address) associated with the remote host. If you see the “It Works” screen, you are on track.
9. Secure MySQL
It will prompt you a few questions:
- Change the root password? – If you have set a secure password previously, you can safely type ‘n’.
- Remove anonymous users? – Type ‘y’.
- Disallow root login remotely? – Type ‘y’.
- Remove test database and access to it? – Type ‘y’.
- Reload privilege table now? – Type ‘y’.
That’s it. You have successfully setup a web server in the remote host.
Here are some optional stuff you can install/do:
PhpMyAdmin is a frontend GUI that allows you to configure and setup database easily. Since it is accessible via web interface, many people feel that it is unsecured and could be the loophole for hackers to brute-force into your database.
Here’s how to install:
sudo apt-get install phpmyadmin
Open a browser and go to http://your-ip-address/phpmyadmin. If you see the phpMyAdmin page, your installation is successfully. If not, you will have to add an extra line to the Apache conf file.
sudo nano /etc/apache2/apache2.conf
Add the following line to the end of the file.
Save (Ctrl + O) and exit (Ctrl + X).
sudo /etc/init.d/apache2 restart
2. Configure Apache
There are tons of things that you can do with Apache. I won’t discuss the detail here. Check out this Apache tutorial for the instruction.
3. Install FTP server
If you need to access your remote host via FTP, you will need to install a FTP server. There are several FTP software that you can use. Here, we will be using vsftp.
sudo apt-get install vsftpd
Don’t forget to add the current user to ftp group.
sudo adduser username ftp
4. Install Webmin
Webmin is a free web-based control panel for administrators to manage their servers without having to go into the command line.
sudo nano /etc/apt/sources.list
Add the following to the end of the file:
deb http://download.webmin.com/download/repository sarge contrib deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib
Import the GPG key:
wget http://www.webmin.com/jcameron-key.asc sudo apt-key add jcameron-key.asc
sudo apt-get update sudo apt-get install webmin
Once installed, you can access webmin in your browser at the URL https://your-ip-address:10000/.