<?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: Arvind Rawat</title>
    <description>The latest articles on DEV Community by Arvind Rawat (@arvindr226).</description>
    <link>https://dev.to/arvindr226</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%2F488638%2F777347ef-0350-4d34-9bc2-815cd7ac23f2.jpeg</url>
      <title>DEV Community: Arvind Rawat</title>
      <link>https://dev.to/arvindr226</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arvindr226"/>
    <language>en</language>
    <item>
      <title>Install apache2 on ubuntu and configure user home as webroot</title>
      <dc:creator>Arvind Rawat</dc:creator>
      <pubDate>Sat, 23 Oct 2021 08:37:12 +0000</pubDate>
      <link>https://dev.to/arvindr226/install-apache2-on-ubuntu-and-configure-user-home-as-webroot-2man</link>
      <guid>https://dev.to/arvindr226/install-apache2-on-ubuntu-and-configure-user-home-as-webroot-2man</guid>
      <description>&lt;h3&gt;
  
  
  Step 1: Install apache2 server on ubuntu server
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt update
sudo apt install -y apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Add user to the ubuntu server.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo adduser &amp;lt;username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: add below line at &lt;code&gt;/etc/apache2/apache2.conf&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Directory /home/&amp;gt;
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
&amp;lt;/Directory&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
Include ports.conf
&amp;lt;Directory /&amp;gt;
    Options FollowSymLinks
    AllowOverride None
    Require all denied
&amp;lt;/Directory&amp;gt;
&amp;lt;Directory /usr/share&amp;gt;
    AllowOverride None
    Require all granted
&amp;lt;/Directory&amp;gt;
&amp;lt;Directory /var/www/&amp;gt;
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
&amp;lt;/Directory&amp;gt;
&amp;lt;Directory /home/&amp;gt;
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
&amp;lt;/Directory&amp;gt;
AccessFileName .htaccess
&amp;lt;FilesMatch "^\.ht"&amp;gt;
    Require all denied
&amp;lt;/FilesMatch&amp;gt;
LogFormat "%v:%p %h %l %u %t \"%r\" %&amp;gt;s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %&amp;gt;s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %&amp;gt;s %O" common
LogFormat "%{Referer}i -&amp;gt; %U" referer
LogFormat "%{User-agent}i" agent
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Update the default virtual host of the apache2 &lt;code&gt;/etc/apache2/sites-available/000-default.conf&lt;/code&gt;.
&lt;/h3&gt;

&lt;p&gt;Update the &lt;code&gt;DocumentRoot /home/&amp;lt;username&amp;gt;/&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 5: Restart the apache2 server.
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;Additional steps to enable basic authentication, here your username: &lt;code&gt;admin&lt;/code&gt; and password: &lt;code&gt;gotechnies&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;htpasswd -cbs /etc/global.htpasswd admin gotechnies
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update the virtual host file &lt;code&gt;/etc/apache2/sites-available/000-default.conf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
    ServerAdmin webmaster@localhost
    DocumentRoot /home/arvind/

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    &amp;lt;Directory "/home/username"&amp;gt;
        AuthType Basic
        AuthName "Restricted Content"
        AuthUserFile /etc/global.htpasswd 
        Require valid-user
    &amp;lt;/Directory&amp;gt;
&amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the apache2 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 systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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