Step-by-step guide: creating a website using VPS


  1. Get a VPS
  2. Connect to the remote server
  3. Update the system
  4. Configuring Apache
  5. Configuring MySQL
  6. Uploading your files using SFTP
  7. Final Word

A VPS aka virtual private server hosting, allows you to get dedicated resources to host your website on a shared server. So basically, a VPS hosting is part-shared and part-dedicated. A VPS is one of the several ways you can host your website on the internet. It’s normally preferred over both shared and dedicated hosting servers because a) It beats a shared hosting in resilience, availability and performance and b) It’s a lot cheaper compared to a completely dedicated hosting.

Within a VPS hosting, files of many different websites are present but each set of files are housed in a separate virtual environment, which allows website owners to enjoy the advantages of dedicated resources at a fraction of the price. In this article, we will be sharing a step-by-step guide for creating a website using a VPS hosting. We will start by explaining the main components and applications that you will be using including Apache, MySQL, Perl/CGI and PHP. After that, we will show you the way to upload your website’s contents using FTP.
This tutorial is meant to cater to the needs of beginners and experts alike, so it doesn’t matter if you have never hosted a website before, this tutorial should be all you need to host your very first one using VPS:

Get a VPS

Get a VPS

The first thing you need to do is get a VPS hosting from a reliable VPS hosting platform. After you clear the payment, you should be given your login information which will be needed to continue with the setup.

Connect to the remote server

In order to get connected to the remote VPS server, you will use the ssh command as follows:
ssh root@X.X.X.X where root is the username provided to you and X.X.X.X is the IP where the server is hosted. Once prompted, enter your password to continue.

Update the system

As a recommended preliminary step, you should update your system’s packages. This is especially important because we are going to be installing PHP and Apache next which often have a ton of dependencies that a system-wide update automatically fetches. Depending on which Linux distribution your server is running, use the apt-get or yum commands (as follows) to update your system:

  1. Sudo apt-get update
  2. Sudo yum update

Installing the necessary tools:

Now we need to install our web server, Apache, database application, MySQL, and code interpreters, Perl and PHP. Use yum install httpd php php-mysql perl mysql mysql-server or
Apt-get install httpd php php-mysql perl mysql mysql-server

Configuring Apache

Now we are moving to the slightly technical part of this tutorial. If you are intending to host a single website, all you have to do is copy your files in the default /var/www category and see the magic happen. However, you can also host multiple websites on the VPS server to harness its true potential. In order to keep things secure, it’s recommended to create a user for every website and then keep the files for that website in the public_html folder within the main /home directory. This creates a clean, easily maintainable directory structure and also adds security to the mix. Let’s begin the process:

1. Add a new user: useradd john

2. Set a password for the newly created user: passwd john

3. Create a new directory within the /home folder: mkdir /home/john/public_html

4. Give ownership of the newly created folder to the newly created user: chown john:john/home/john/public_html/

5. Set permissions for the folder: chmod 755 /home/john/public_html/ && chown 711 /home/example/

6. Edit the /etc/httpd/conf/httpd.conf file using your favorite editor. For this example, we will be using vi: vi /etc/httpd/conf/httpd.conf

Scroll down to the bottom of the file and enter the following code to add a virtual host:
NameVirtualHost *:80
RewriteEngine on
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]
ServerAlias www.
DocumentRoot /home/john/public_html
ErrorLog /var/log/ johnswebsite.com_error_log
CustomLog /var/log/ johnswebsite.com_access_log combined
DirectoryIndex index.html index.htm index.php index.php4 index.php5
SetOutputFilter DEFLATE
Options -Indexes +IncludesNOEXEC +SymLinksifOwnerMatch +ExecCGI
allow from all
AllowOverride All

In the above lines of code, modify the /home/john/public_html path according to your username, wherever you see it. Also change to your website’s domain name wherever necessary. Save the file and close it.

7. Now, we need to make sure Apache starts as soon as the machine boots up.
/etc/init.d/httpd start
chkconfig httpd on

8. As a last step, we need to point the DNS’ A record to your server’s IP address. This will map your domain to the IP address of the machine, ensuring that whenever your domain name is hit, the request is sent to your server. After you have done this, you can visit your domain to see if you are taken to a default Apache page. If all is good, continue.

Configuring MySQL

1. As a first step, start the MySQL server and set it to start at bootup.
/etc/init.d/mysqld start
chkconfig mysqld on

2. Set the password for the root user for MySQL. Use the following commands to do so:
mysql -u root
UPDATE mysql.user SET Password = PASSWORD(‘P@ssw0rd’) WHERE User = ‘root’;
Replace the string “P@ssw0rd” with the password you want to set.

3. Next up, create the database and grant the necessary privileges for it to the pertinent user.
mysql -u root -p
create database test;
grant all privileges on test.* to john@localhost ;

Obviously, you will replace test and john@localhost with the desired name for your database and your username respectively.

Uploading your files using SFTP

Now that MySQL and Apache are setup, you simply need to upload your website’s files. You can use any SFTP (SSH file transfer protocol) client but we recommend using FileZilla. Follow these steps:

1. Connect to your server using the username you created.

2. Select all your website’s files and upload them to the /home/public_html directory.
That’s it. Now when you fire up your domain name on the browser, you should be taken to your website’s homepage.

If you are searching for an easier way to create a website, you can try online services like Wix

Create Website Wix

Final Word

A VPS hosting is a cost-efficient way to enjoy the benefits of a dedicated hosting server without having to pay the full price. In this tutorial, we walked you through all the steps necessary to host your first website on a VPS hosting server. Once your website is up, you can tweak it as you see fit.

Get started image

Ready to get started?

Get the expert support you need

Related Articles

30 Tips to Improve Internet Advertising

by Team ZenBusiness, on April 23, 2024

16 Worthwhile Ideas For Your Website Popup

by Team ZenBusiness, on March 28, 2024

Start Your LLC Today