Skip to content
DBDeependra Bhatta~/notes
Linux#devops · #technology · #linux · #ai · #apache2 · #apache2sitedeploy · #networking · #security · #webserver

Apache web server

The Apache HTTP server, commonly known as Apache is a free and open-source web server, that delivers web content through the internet. As open-source software, its original source code is freely…

· updated · 5 min read
ON THIS PAGE

The Apache HTTP server, commonly known as Apache is a free and open-source web server, that delivers web content through the internet. As open-source software, its original source code is freely available for developers to view and collaborate. This has made Apache a favorite among developers who create and configure Apache models to expand its functionality and improve on its core features.

Why webserver

  • To deliver app securely
  • To remove downtime
  • For load balancing

Difference between Apache web server and nginx web server

Apache web server screenshot 1

NGINX also supports reverse proxy.
Reverse proxy: A server that sits between client device [web browser] and backend server and then returning the server’s response to the client. Acts as a actual server hiding existence of characteristics of backend server.

Watch the video on YouTube

To install apache2

  • apt install apache2
  • sudo systemctl status apache2
  • sudo systemctl enable apache2
  • sudo systemctl start apache2

Commands

  • a2enmod: To enable module
  • a2ensite: To enable the site
  • a2enconf: To enable configuration
  • a2dismod:
  • a3dissite:
  • a2disconf:

Apache2 configuration overview

TXTPlain text
/etc/apache2/
|-- apache2.conf
|       `--  ports.conf
|-- mods-enabled
|       |-- *.load
|       `-- *.conf
|-- conf-enabled
|       `-- *.conf
|-- sites-enabled
|       `-- *.conf
  • apache2.conf
    • Master configuration file that pulls in all other settings like modules, ports, sites,etc.
  • ports.conf
    • Specifies the TCP ports Apache listens on
      • Example: Port 80 for HTTP request and 443 for HTTPs.
  • mods-available and mods-enabled
    • mods-available holds all the module defination [load to load code and conf to configure code]
    • mods-enabled contains syslinks to subset actually in use
  • Conf-enabled and conf-available
    • Conf-enabled holds syslinks to the active snippets.
    • conf-available store the global snippets.
  • Sites available and sites enables:
    • Sites available contains all virtual hosts defination
    • sites enabled has syslinks to the ones currently served to clients
  • envars
    • Define apache’s own environmetn variables [ Ex: log directory, PID file, Run user ] that get loaded when using apache2ctl or init script.
  • Magic
    • Contains magic number rules for defining a file MIME type based on its initial bytes [EG: %pdf for pdf]
  • logrotate
    • It determines for how much time we need to place the logs.
    • This is the linux utility that manages the automatic rotation, compression and removal of log files.
    • Prevents log files from consuming excessive disk space.

To load a website in apache2

  • Download a site from toolplate : download>>inspect >> network >> name.zip file >>copy URL of the of the zip file here is 2103_central.zip. This file name is based on the template name.

Apache web server screenshot 2

  • wget /tmp or any location you want to.
  • unzip the URL by using command unzip -R filename.
  • Copy the unzipped files to /srv/dirname
  • Now copy the /etc/apache2/000-default file and create a new file for example newfile.conf and in file change root = /srv/dirname. This is the path where you have copied file earlier.
  • Now activate the site a2ensite newfile.conf
  • a2dissite 000-default.conf
  • chown -R www-data:www-data /srv/: When apache reads static files like HTML, CSS and javascript it as www-data user. So we need to change ownership of directory to www-data.
  • vim /etc/apache2/apache2.conf
    • #Simply uncomment this line
  • Now systemctl restart apache2
  • Now that custom website will be launched.
  • To access locally curl localhost.

Other Docs

Vagrant

  1. Vagrant Architecture
  2. To setup vagrant VM
  3. Commands
  4. Other Configurations

Shell Scripting

  1. Writing our first script
  2. Variable
  3. To take input from user we use
  4. Positional Argument
  5. Command substitute
  6. If
  7. For
  8. While

Linux commands[2]

  1. Linux Links
    1. Soft links
    2. Hard Link
    3. Inode
  2. Packet Management
    1. APT [Advanced Packaging Tool]
    2. APT-CACHE
    3. Aptitude
    4. dpkg
  3. Users and Groups
    1. Types of users
    2. Files related to users and groups
    3. User Commands
    4. Group commands
  4. File permissions
    1. Changing permissions
    2. Changing ownership of file
    3. Changing group ownership for file/dir
    4. Managing file and group ownership simultaneously
    5. Special permission
      1. Sticky-bit
      2. SUID-bit
      3. SGID Bit
  5. Archiving and Compressing
    1. Archiving:
    2. Compression
  6. Sudo
  7. Processes
    1. top
    2. Process status(ps)

Linux Commands

  1. To see Ip address of the machine
  2. Systemctl commands
  3. Change directory [cd]
  4. Listing command [ls]
  5. Basic commands
  6. Copy command
  7. Move command
  8. Remove Command
  9. To get help and see suggestion in linux
  10. To view/print contents of file
    1. Head
    2. Tail
    3. More
    4. Less
    5. Find
    6. Locate
  11. Grep
  12. Sed [Stream Editor]
  13. Cut
  14. AWK
  15. VIM
    1. Navigation
    2. Extended mode
  16. Input/Output redirection
    1. Input redirection
    2. Output redirection
    3. Standard error output
  17. To download using links

Linux Introduction

  1. Overview
    1. Operating System
    2. Principles
    3. Why Linux?
  2. Architecture
  3. Linux Terminology
    1. Linux Kernel
    2. Linux Distribution
    3. Linux BootLoader
    4. Linux Service
    5. Linux File System
    6. Linux X Windows System
    7. Linux Desktop Environment
    8. Linux Command Line
    9. Linux Shell
    10. Linux Distros
  4. Linux File Structure
    1. / – Root
    2. /bin – User Binaries.
    3. /sbin – System Binaries
    4. /etc – Configuration Files
    5. /dev – Device Files
    6. /proc – Process Information
    7. /var – Variable Files
    8. /tmp – Temporary Files
    9. /usr – User Programs
    10. /home – Home Directories
    11. /boot – Boot Loader Files
    12. /lib – System Libraries
    13. /opt – Optional Add-on Applications
    14. /mnt – Mount Directory
    15. /media – Removable Media Devices
    16. /srv – Service Data
  5. Interface and logging in via terminal
    1. Remote login via ssh
  6. Linux File system
  • Shell Scripting

    It is a way to automate tasks by writing a series of commands in a text file called script that Linux shell can execute. It’s like creating a ‘to do list’ for your computer to follow step by step…

  • To create a service file for Tomcat Server

    /etc/systemd/system/multi-user.target.wants/apache2.service First we need to create a file inside /etc/systemd/system. For now i have created a file with name tomcat1.service. After that write a…

  • Linux Commands

    To see Ip address of the machine ip addr show :Shows all the interfaces ip ip -4 addr show: Show only ipv4 address ifconfig: Same as ip addr show but it needs net tools to show ip address. Systemctl…