You are currently viewing How to Setup VPS Prosses Step By Step With Ubuntu (LAMP)

How to Setup VPS Prosses Step By Step With Ubuntu (LAMP)

How to Setup VPS – It is very easy to set up back, if you pay attention to the smal. In this tutorial, we will learn to setup a VPS step by step, I will tell you from the beginning, till the end, you will become an expert. lest things. Otherwise it can be very difficult to setup. lets start

Step 1

You dont know How to Setup VPS ? You will need a command prompt (CMD) to setup VPS. you can also use PUTTY & SHELL i proffered you CMD. First of all we have to connect CMD to our VPS server. We will need SSH to connect. You can easily install SSH. you need to do few step to install SSH to  your system as per image bellow.

In search bar type “Feature” >> manage optional features >> find SHH and install it. approx. 10mb size of SSH.

SSH installation

Step 2

Now you can make connection with your VPS server. we need VPS server ip and password for make connection. those details are provide by your providers. Open your CMD and type those command to make connection. How to Setup VPS

ssh root@youripAddress

After this hit Enter then you have SSH key message type ‘Yes” and Enter then you have to copy past your password and hit enter. if successful. you have this type message like bellow image.

SHH to server connect via command prompt

Step 3

If you select Ubuntu and LAMP when you buy VPS it will preinstall.

If LAMP was correctly installed, i.e., PATH is already set for php,mysql and apache2, then run following commands from CMD:-

php -v  // Return PHP version

apache2 -v // Returns apache version

mysql --version // Returns mysql version

if all of the above command returns their respective versions, then it means LAMP is installed.

BUT if it doesn’t then there might be two cases:-

1) LAMP might be installed but is not added to path.

2) LAMP is not installed, Install it.

As for the first case, if it is installed but not runnable from terminal, then just run following commands to see where LAMP components are installed:-

Find file with name “apache2” in your pc. It will return list of path where a file name called “apache2” exists. You can then cross examine it further.

sudo find / -name apache2

sudo find / -name mysql

sudo find / -name php

If any of the mentioned dependencies are not install and you want to install the LAMP use the following command,

sudo apt-get install lamp-server^

If Everything ok just run Update Command

sudo apt-get update

Step 3 (How To Set Up Apache Virtual Hosts on Ubuntu 18.04)

Run your ip address in browser if you get Apache default page its mean everything ok you have go ahead to add domain as virtual host.

Apache Virtual Hosts allows you to run more than one website on a single machine. With Virtual Hosts, you can specify the site document root (the directory which contains the website files), create a separate security policy for each site, use different SSL certificates and much more.

Make sure that you have met the following prerequisites before continuing with this tutorial:

  1. You have a domain name pointing to your public server IP. We’ll use example.com.
  2. You have Apache installed by following these instructions .
  3. You are logged in as a user with sudo privileges .

Step 4 (Create the Directory Structure)

The document root is the directory where the website files for a domain name are stored and served in response to requests. You can set the document root to any location you want, in this guide we will use the following directory structure:

/var/www/
├── domain1.com
│   └── public_html
├── domain2.com
│   └── public_html
├── domain3.com
│   └── public_html

Basically, we will create a separate directory for each domain we want to host on our server inside the /var/www directory. Within each of these directories, we will create a public_html directory that will store the domain website files.

Start by creating the root directory for the example.com domain:

sudo mkdir -p /var/www/example.com/public_html

For testing purposes also create an index.html file inside the domain document root directory.

Open your editor and create the demo file:

<html>
  <head>
    <title>Welcome to Example.com!</title>
  </head>
  <body>
    <h1>Success! The example.com virtual host is working!</h1>
  </body>
</html>

In this guide, we are running the commands as a sudo user and the newly created files and directories are owned by the root user.

To avoid any permission issues we can change the ownership of the domain document root directory to the apache user (www-data) :

sudo chown -R www-data: /var/www/example.com

By default on Ubuntu systems, Apache Virtual Hosts configuration files are stored in /etc/apache2/sites-available directory and can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory.

Open your editor of choice and create the following basic Virtual Host configuration file:

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

ServerName: The domain that should match for this virtual host configuration. This should be your domain name.

  • ServerAlias: All other domains that should match for this virtual host as well, such as the www subdomain.
  • DocumentRoot: The directory from which Apache will serve the domain files.
  • Options: This directive controls which server features are available in a specific directory.
  • -Indexes: Prevents directory listings.
  • FollowSymLinks: This option tells your web server to follow the symbolic links.
  • AllowOverride: Specifies which directives declared in the .htaccess file can override the configuration directives.
  • ErrorLog, CustomLog: Specifies the location for log files.

You can name the configuration file as you like but the best practice is to use the domain name as the name of the virtual host configuration file.

To enable the new virtual host file we need to create a symbolic link from the virtual host file to the sites-enabled directory, which is read by apache2 during startup.

The easiest way to enable the virtual host is by using the a2ensite helper:

sudo a2ensite example.com

The other option is to manually create a symlink as shown below:

sudo ln -s /etc/apache2/sites-available/example.com.conf /etc/apache2/sites-enabled/

Once done, test the configuration for any syntax errors with:

sudo apachectl configtest

If there are no errors you will see the following output:

output
Syntex OK

Restart the Apache service for the changes to take effect:

sudo systemctl restart apache2

You have learned how to create an apache virtual host configuration to host multiple domains on a single Ubuntu server. You can repeat the steps we outlined above and create additional virtual hosts for all your domains.

If you are facing any problems, feel free to leave a comment.

Leave a Reply