Linux serverlinux web serverNETWORK ADMINISTRATIONS

Apache Web Server Linux

vmware workstation: www.vmware.com
virtual box: www.virtualbox.org
FTP Server Video: https://youtu.be/sGXH8br_pk4

Hello and welcome to the Robs 2 Bytes Channel where we grow it skills one video at a time with your host rob.
In todays episode we will be configuring an Apache web server. We will also configure 2 virtual hosts to serve 2 websites from a single IP server. This is a great way to set up a local test environment for your web development adventures

Currently, I am using OpenSUSE Tumbleweed in VMWare Workstation Pro. You can download a free version of VMWare WorkStation. You may use another virtual software offered by Oracle called Virtual Box which is completely free. Alternatively, you may configure this natively on your pc or turn that old spare pc into a dedicated server.

By the end of this tutorial you’ll be able to access these websites from the server as well as other computers in your network.

So lets begin by updating our system
sudo zypper update

Now that our system is updated lets install the Apache Web Service
sudo zypper in apache2

Once Apache Service is installed, we need to start the service by typing

sudo systemctl start apache2

Also, we want to ensure Apache starts when the system is turned on
sudo systemctl enable apache2

A few other useful commands to know are how to stop, restart, reload, and status apache
sudo systemctl stop apache2
sudo systemctl restart apache2
sudo systemctl status apache2

Now that we have verified Apache service is running lets navigate to directory where Apache stores the web documents and directories in OpenSUSE. This is were you will store all your webpages and web directories.

/srv/www/htdocs

Here we will create a simple web page to test in our browser

sudo nano htdocs/index.html
Hello and welcome to my apache server
ctrl+S
ctrl+X

After creating our test page, lets Open our web browser and type in local host – our page should appear.

Ok so now that we have verified Apache is working lets start working on Site1 and Site2. Here we will make 2 directories:

sudo mkdir htdocs/site1
sudo mkdir htdocs/site2

To make things easier, lets change the ownership and permissions of the htdocs directory to the Apache user and group
sudo chown wwwrun:www -R htdocs
sudo chmod 775 htdocs

Now lets make a simple index.html for site1 & site2 for testing the Apache Configuration

navigate to htdocs directory
cd htdocs and

sudo nano site1/index.html
This is our Site 1 Welcome page
ctrl+S
ctrl+X

sudo nano site2/index.html
This is our Site 2 Welcome page
ctrl+S
ctrl+X

With site1 and site2 test pages created, lets create our virtual host config. Here we will navigate to where our virtual host configuration files will be stored.
/etc/apache/vhosts.d

Lets create virtual host for site1

sudo nano site1.com.conf

VirtualHost *:80
ServerName www.site1.com
ServerAlias site1.com
DocumentRoot /srv/www/htdocs/site1
ErrorLog /srv/www/htdocs/site1/error.log
CustomLog /srv/www/htdocs/site1/requests.log combined
/VirtualHost
ctrl+S
ctrl+X

And now for site2

sudo cp site1.com.conf site2.com.conf
sudo nano site2.com.conf
change site1 to site2
ctrl+S
ctrl+X

Once we created our virtual host we need to verify our IP address and edit the hosts file so apache knows were to find site1 and site2

sudo ip addr

sudo nano /etc/hosts

192.168.111.139 site1.com
192.168.111.139 site2.com
ctrl+S
ctrl+X

Anytime we make changes to the configuration like adding virtual hosts or updating the hosts file we need to reload the Apache Service

sudo systemctl reload apache
clear browser history
navigate to site1.com
navigate to site2.com

So now that we have access on our local pc to site1 and site2, lets now provide access to other pc’s on our network. To do this we need to open the firewall to allow http requests through. To do so we

verify firewall is working
sudo systemctl status firewalld
sudo firewall-cmd –get-default-zone
sudo firewall-cmd –list-services
sudo firewall-cmd –zone=public –add-service=http –permanent
sudo firewall-cmd –reload
sudo firewall-cmd –list-services

Finally we have to update the host files on the other pc to point to our Web Servers single IP for site1 and site2.

in windows the host file is located in

Windows c:WindowsSystem32Driversetchosts

And There you have it folks

In this video we installed:
Apache Web Server
Create 2 separate test pages
Setup 2 Virtual Hosts
configured the firewall to allow http requests from other computers on the network
That’s all there is to setting up an webserver

If you found this video helpful please let me know in the comments below. Also, please like or subscribe.

Thank you and see you in the next episode

source

by Robs 2 Bytes

linux http server