Thanks to the Host1Free VPS offer, I was able to administrator the server directly in the cloud without using any local resources, for the testing purpose at least. The advantages of using this free VPS is obviously its price of free, as well as the freedom of installing and experimenting with different utilities at system level compared to what you can do in the shared hosting environment. Although this free VPS configuration is not very fast, it can help me to learn everything about server administration and maintenance before I’m able to afford VPS with more power or even a dedicated server.
Anyway, here are the steps to use this VPS as a web development server.
- Make sure you have SSH client installed. Mac OS and Linux already have SSH installed. For those using Windows can use PuTTY. By using Mac OS or Linux, I assume that you already know how to use terminal. If not, you can google for the SSH GUI alternative for Mac OS or Linux.
- Once you verified that you have SSH client installed, the next step is to connect the VPS through SSH. Find out the IP address of your VPS. It’s generally displayed in your VPS control panel, in XXX.XXX.XXX.XXX format (126.96.36.199 for instance). Ask me in the comment section below if you cannot find the IP address for your VPS.
- Open the terminal and type the following line (if you are using a GUI app, please refer to its documentation for help):
Replace 188.8.131.52 with your VPS IP address.
- If this is your first time SSH to the server, it will display a confirmation message confirming you to connect to the server. Type “yes” to confirm.
- After pressing enter and wait a while, you are now in your VPS server.
Note: If you restored the VPS image through your control panel and used SSH to access the server before, you need to delete the known_hosts file in .ssh folder in your user directory. Otherwise, you won’t be able to access the server again due to different host key:
Create a New User
In order to avoid being hacked and protect root account, we need to create a user account which does not have root privilege.
- Enter the following command:
usernamewith the username of your choice.
- Follow the prompts to enter the new password for your account, as well as detailed information about you. If you don’t want to enter any of your personal information, you just simply press enter to continue to the next field.
- When you are finished, type “y” to confirm that it’s the correct information.
- Your username has been created. Now you can login to the VPS with this username instead of root.
- Make sure to add your newly created username to /etc/sudoers to have temporary root privilege. Otherwise, you won’t be able to do system tasks such as upgrade in the next section.
Locate the following section and press “i” to edit file
# User privilege specification
Go to the end of this section and press enter to create a new line. Go up one line and type the following to add your username to the list:
username ALL=(ALL:ALL) ALL
Make sure to replace “username” with your username. Press esc to exit the edit mode and type “:x!” to save this read-only file.
- If you want to learn more about vi text editor, or if you have any problem regarding the above steps, please let me know in the comments section below.
- Enter the following command to logout from your server:
- Connect to the server using your newly created account:
ssh [email protected]
usernamewith the username you created in the last section, and replace
xxx.xxx.xxx.xxxwith the IP address for your server which you supposed to find out at the beginning of this tutoail.
- Enter the password when you created your username.
Update & Upgrade
If you just created this VPS or this is your first time logging into this VPS, the first task is to issue a upgrade command. Otherwise, most of the commands mentioned below won’t work.
- Type the following command and press enter:
sudo apt-get update
- After the above command finished executing, issue the following command:
- There will be a lot of packages that need to be upgraded if this is a brand new VPS. After the upgrades are found, press y to confirm to install them.
- Wait until the system is upgraded. This will take a while.
- After the system is upgraded, it’s recommended to restart server before continuing:
LAMP on Ubuntu VPS
Now we are ready to begin the LAMP installation process.
- Login to the server once more with SSH due to the restart in the last step.
- Enter the following command (or copy and paste into the terminal if you don’t know how to type “^”) to start the LAMP installation:
apt-get install lamp-server^
Note: Ubuntu 12.04 seems to work very well for me when installing the LAMP server. Ubuntu 13.10 (which is the latest available version in my VPS control panel, the latest Ubuntu version as of this writing is 14.04) always hang during the installation of MySQL server, after it displays the MySQL change password error message.
- If you want to store the web server files to your home directory for backup purpose, you can edit the apache2 configuration file.
sudo vi /etc/apache2/sites-enabled/000-default
Press i and replace the two places of “/var/www” to “/home/username/public_html”. Replace the username with your username.
Press esc and type “:x” to save.
Don’t forget to create the public_html folder inside your home directory.
And to apply the new Apache configuration, restart Apache.
sudo service apache2 restart
You have finished LAMP installation. Now you can visit your empty website by going to the IP address of your VPS. Well, it is empty until you upload some web pages.
With SSH set up in the first section of this tutorial, you can now also use SFTP to transfer files between local files and your server. The setup is easy. Just use your favorite FTP client to connect to the server. Make sure to select SFTP in the Protocol field for your client and fill out other necessary fields to connect to the server. Once connected, you are ready to publish your website.
With a VPS, you always can use the latest version of PHP and a variety of PHP extensions if you want. You can also install Ruby on Rails, Node.js, Git, and other additions you need without any restrictions set by the shared hosting. However, since you are basically using other people’s resources, it’s important to have a contingency plan to backing up all the files in the home directory on the VPS in case anything happens to the VPS server.