Lab 2 : Creating Web Server
Objectives:
1. Use linux Command Line Interface (CLI) to setup applications
2. Learn how Operating System (OS) work with file system
3. Learn OS File file structure
Label:
$ : user environment of CLI
# : superuser environment of CLI
> : mysql environment of CLI
**: note that you must take an action
1. display OS info:
$ cat /etc/*rel*
-The most
basic and common usage of the cat command is to read the contents of
files.
-For
example, the following command will display the contents of the /etc/*rel* file on the terminal:
2. be root:
$ sudo su -
-The sudo command lets us use our account and password
to execute system commands with root privileges, whereas the su command allows
us to switch to a different user and execute one or more commands in the shell
without logging out from our current session.
3. Insert ubuntu password
-su prompts the user for the password of the
target user account, while sudo prompts the user for their own password. su
gives the user full access to the privileges of the target user account, while
sudo only grants temporary privileges for a specific command.
4. check update:
# apt update
- -The
sudo apt-get update command is used to download package information from
all configured sources.
- -The
sources often defined in the /etc/apt/sources. ...
- -So
when run update command, it downloads the package information from the
Internet.
5. install apache web
server:
# apt install apache2 net-tools -y
-This how-to will help you
with your install and configuration of Apache on your Ubuntu 22.04
server.
6. Change directory
# cd /etc/apache2/sites-available/
-sites-available/directory contains virtual host file
configurations. Configurations within this folder will establish which content
gets served for which requests. This is enabled through linking to the sites-enabled directory, which stores activated virtual
host configuration files. When Apache starts or reloads, it reads the
configuration files and links from within the sites-enabled directory as it compiles a full
configuration.
7. copy file:
# cp 000-default.conf (name).conf
-Virtual host
files are the files that specify the actual configuration of our virtual hosts
and dictate how the Apache web server will respond to various domain requests.
-Apache comes
with a default virtual host file called 000-default.conf that we can use as a jumping off point. We
are going to copy it over to create a virtual host file for each of our
domains.
8. modify file:
# nano (name).conf
-Nano is an easy to use command line text editor for
Unix and Linux operating systems. It includes all the basic functionality you’d
expect from a regular text editor, like syntax highlighting, multiple buffers,
search and replace with regular expression support, spellchecking, UTF-8
encoding, and more.
-
In this case nano is used to modified the file.
9. change directory:
# cd /var/www/html/
-/var/www/html is created when you install Apache HTTP server.
10. list file and
directory:
# ls
-The ls command is used to list files.
"ls" on its own lists all files in the current directory except for
hidden files.
11. create directory:
# mkdir (name).com
-The command mkdir stands for “make directory”. It
creates each directory specifed on the command line in the order given. It
reports an error if DIRECTORY already exists, unless the -p option is given.
12. enter the directory:
# cd (name).com/
-The cd command, also known as chdir (change
directory), is a command-line shell command used to change the current
working directory in various operating systems.
13. create html file:
# nano index.html
-Comments nano [filename]. Opens the file
in nano for editing.
check public IP:
# curl ifconfig.co
-ifconfig.co is a web service that displays
information about your connection, including IP address, hostname and User
Agent string. Helpfully it provides a simplified interface that can be easily
queried to get this information from the command line.
**if no culr then install
# apt install curl
-curl command is a tool to download or transfer
files/data from or to a server using FTP, HTTP, HTTPS, SCP, SFTP, SMB and other
supported protocols on Linux or Unix-like system. One can easily install and
use the curl command on a Debian Linux using the apt command or apt-get command
to use the curl.
check dns server:
# nslookup (name).tk
-nslookup is an abbreviation of name server lookup
and allows you to query your DNS service. The tool is typically used to
obtain a domain name via your command line interface (CLI), receive IP address
mapping details, and lookup DNS records.
14. change directory to
site-available:
# cd /etc/apache2/sites-available/
# ls
-This directory contains site files which are enabled.
Basically, you want to setup your vhost files (. conf files) in
sites-available and then create a symbolic link in sites-enabled for each one.
This way, you only update the configs in sites-available.
15. disable default-ssl.conf:
# a2dissite 000-default.conf
-The 000-default.conf site
is a catch-all for any request the server does not have a configuration
file for.
# a2dissite default-ssl.conf
-enables
the specified site (which contains a <VirtualHost> block) within the
apache2 configuration.
16. Restart the apache
service
# systemctl reload apache2
-The
reload option of the systemctl command will reload the apache configuration
file, without restarting the entire HTTP Process
17.
enable "your" site:
# a2ensite (name).conf
-a2ensite is a command used to enable an Apache2
web server configuration file, known as a site, on an Ubuntu system.
18. check syntax:
# apache2ctl -t
-apache2ctl is a front end to the Apache
HyperText Transfer Protocol (HTTP) server. It is designed to help the
administrator control the functioning of the Apache apache2 daemon.
19. restart web server
#systemctl restart
apache2.service
-Stops
and then starts the Apache service. reload : Gracefully restarts the Apache
service. On reload, the main Apache process shuts down the child processes, loads
the new configuration, and starts new child processes.
20. open web browser
(firefox) then type localhost IP:
-Search 127.0.0.1 in firefox
-The webserver displayed