<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: .</title>
    <description>The latest articles on DEV Community by . (@drey).</description>
    <link>https://dev.to/drey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F317457%2F0fc63d63-5eeb-4c56-9bf6-5deee3f96f2c.jpeg</url>
      <title>DEV Community: .</title>
      <link>https://dev.to/drey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/drey"/>
    <language>en</language>
    <item>
      <title>How to host several websites on a single Linux server</title>
      <dc:creator>.</dc:creator>
      <pubDate>Tue, 08 Feb 2022 17:53:46 +0000</pubDate>
      <link>https://dev.to/drey/how-to-host-several-websites-on-a-single-linux-server-h4e</link>
      <guid>https://dev.to/drey/how-to-host-several-websites-on-a-single-linux-server-h4e</guid>
      <description>&lt;p&gt;Most of the time, we deploy web applications on popular hosting sites like Hostinger, whogohost, etc., who give us spaces to host our application files (known as shared hosting). Depending on our subscription model however, we may find that we are limited in what we can actually do by way of SSH access, number of cronjobs, database limits and so on. &lt;/p&gt;

&lt;p&gt;We can go the way of getting a dedicated cloud hosting from AWS, Google or Azure, where we can provision virtual Linux machines &lt;br&gt;
 on which we can deploy our applications while maintaining full control. I explained how to do that with &lt;a href="https://dev.to/dreysongz/how-to-deploy-a-laravel-app-on-an-azure-ubuntu-server-1fl"&gt;Azure here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Of course, it is normal that we might have several websites/applications with different domain names all consolidated on the same server instance, this means we can self-host as many websites as we have on the same server as long as space allows for it. This is possible by the Virtual Hosting feature of Apache.&lt;/p&gt;

&lt;p&gt;Steps: &lt;/p&gt;

&lt;p&gt;1.SSH to the Linux server using Putty&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fikb0ivvzk68wrl3v7p74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fikb0ivvzk68wrl3v7p74.png" alt="putty" width="449" height="433"&gt;&lt;/a&gt;&lt;br&gt;
2.We need to create a separate directory in the web directory that Apache uses to serve web pages (/var/www/html). Create a new folder thus: /var/www/html/new-website. This is the folder all requests to our website will be routed to. You can upload all your website files in this directory.&lt;/p&gt;

&lt;p&gt;3.We want to copy and modify the default web config file in the apache config directory. Copy the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cd /etc/apache2/sites-available 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copy the default web config file (000-default.conf) and paste with a name for our new website we want to add.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo cp 000-default.conf new-website.com.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.We will now edit the newly-copied file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo nano new-website.com.conf

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.Once the file opens, you should see something like this, with some lines commented out:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdax6trrp8rfk6is2jvft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdax6trrp8rfk6is2jvft.png" alt="Virtual Host" width="633" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Edit the file by coming down to the &lt;strong&gt;ServerName&lt;/strong&gt;, uncomment it by removing the # character, remove &lt;a href="http://www.example.com"&gt;www.example.com&lt;/a&gt; and type the address of our website, new-website.com&lt;br&gt;
Come down to &lt;strong&gt;DocumentRoot&lt;/strong&gt;, remove /var/www/html, replace with the directory that you have created for the new site under (/var/www/html), something like /var/www/html/new-website.. this is the directory that visitors will be re-directed to whenever they type in the web address. &lt;br&gt;
Your changes should look like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39dijox3za2j4t9tyl5a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F39dijox3za2j4t9tyl5a.png" alt="final" width="401" height="82"&gt;&lt;/a&gt;. Save and exit.&lt;/p&gt;

&lt;p&gt;6.After doing this we need to tell Apache to activate this particular setting, only then the configuration can be complete:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo a2ensite new-website.com.conf

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;7.Restart Apache server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service apache2 restart

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;8.We have taken care of the Server end, we need to point the DNS records for our domain to the Linux server IP address in case we have not done so before.&lt;br&gt;
Simply go to the DNS settings of your domain, create a new A record with the value of the server's IP address. &lt;/p&gt;

&lt;p&gt;Wait for 1-2 hours to propagate. All done. Repeat the entire process for as many sites we wish to configure on the server.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
