Setup a website on the Pi


Setup a VirtualHost on the Pi

http://httpd.apache.org/docs/2.4/vhosts/

We'll create a website named joebob.com

We must first setup the virtual host on the Pi, then define the hostname on the machine we'll load it from (Windows)

On the Pi

  • We'll use gedit instead of vi as a text editor.
    You can use either, just substitue one for the other or install gedit
    
    $ sudo apt install gedit
    
  1. Navigate to /var/www/html and create a new directory named vhosts:
    If it doesn't already exist
    
    $ sudo mkdir /var/www/html/vhosts
        
  2. Create a new directory within the vhosts directory
    
    -- enter the vhosts directory  
    $ cd /var/www/html/vhosts    
    
    -- create a new sub-directory
    $ sudo mkdir joebob.com
        
  3. Create a new index.html file within the new directory
    
    -- enter the joebob.com directory  
    $ cd joebob.com    
    
    -- create a new file
    $ sudo touch index.html
    
    -- open the file in an editor (in our case gedit - cuz vi sux)
    $ sudo gedit index.html
        
    ...and add this to the file:
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Hosted!</title>
    </head>
    <body>
      <h1>This is a hosted site</h1>
    </bodyv
    </html>    
        
  4. Create a new .conf file in the /etc/apache2/sites-available directory by copying the default one in there:
    
    -- change to the sites-available directory
    $ sudo cd /etc/apache2/sites-available    
    
    -- copy the file
    $ sudo cp 000-default.conf joebob.com.conf  
        
  5. Edit the file that was just created:
    
    $ sudo gedit joebob.com.conf    
        
    and define the following:
    
    ...    
    ServerName joebob.com
    ServerAlias www.joebob.com         -- optional
    ServerAdmin wemaster@joebob.com    -- optional
    DocumentRoot /var/www/html/vhosts/joebob.com/
    ...
        
  6. Activate the host by running the apache command:
    
    $ sudo a2ensite joebob.com    
        
  7. Reload the apache server:
    
    $ sudo systemctl reload apache2    
        

On Windows

Navigate to C:/Windows/System32/drivers/etc and edit the hosts file

Add the IP and domain name to the end of the file


...
10.163.37.227  joebob.com