Apache 24 http Server - the web server inside of windows EC2 server

First of all, what exactly is an http server? It is software that hosts and runs HTML and PHP web pages. Why Apache? We can also use nginx (pronounced engine-x) or if we are Microsoft ‘only’ buffs we can use IIS. When serving up java servlet web pages using jdbc we can use Apache Tomcat. But Apache 24 is my favorite. It is one of the most popular for 25 years. And we cannot run PHP without it (apache XAMPP web server).

After creating our AWS EC2 server, we need to download apache24 and add php capability only if that is the way u want to go. But I chose to use only html as a beginner. We will use our EC2 instance and Apache together. EC2 provides the windows environment and ip routing and apache serves up virtual web hosts based on domain name(s) and corresponding pages.

Where index.html or index.php lives

After downloading, the main file in Apache24 is httpd.conf which can be found in the conf folder, the main configuration file where we provide instructions to apache about how to act. In this file we configure virtual hosts to route our web pages from route 53 to the users screen. We also do ssl here among other operations. I recommend a bare bones config which looks similar to this:


# this is a very much condensed sample of httpd.conf file

# I recommend u view this from a desktop because on a mobile phone some lines may run into other lines

# it contains key lines needed for virtual hosting and ssl

# open ur own httpd.conf file and re configure it similar to below

# enable php

LoadModule php7_module "c:/php7/php7apache2_4.dll

PHPIniDir "c:/php7"

AddHandler application/x-httpd-php .php

AddType application/x-httpd-php .php

ServerRoot "c:/httpd-2.4.33-win64-VC15/Apache24"

Listen 80

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_http_module modules/mod_proxy_http.so

LoadModule rewrite_module modules/mod_rewrite.so

LoadModule setenvif_module modules/mod_setenvif.so

LoadModule socache_shmcb_module modules/mod_socache_shmcb.so

LoadModule ssl_module modules/mod_ssl.so

# 'Main' server configuration

ServerAdmin admin@example.com

   #last used....this is the ip address we get from our aws EC2 server

ServerName 18.191.142.3:80

DocumentRoot "c:/httpd-2.4.33-win64-VC15/Apache24/htdocs"

# Supplemental configuration

#

# The configuration files in the conf/extra/ directory can be

# included to add extra features or to modify the default configuration of

# the server, or you may simply copy their contents here and change as

# necessary.

# Secure (SSL/TLS) connections....we need this file found in the extra folder in order to config ssl


Include conf/extra/httpd-ssl.conf

<VirtualHost *:80>

  ServerName javasqlweb.com:80

   # add ServerAlias for sub directories

DocumentRoot "c:/httpd-2.4.33-win64-VC15/Apache24/htdocs/java"

    # add this to allow users access to files, require all replaces allow from all i think, see above for instructions

<Directory "c:/httpd-2.4.33-win64-VC15/Apache24/htdocs/java">

    #Options Indexes FollowSymLinks

    AllowOverride None

    Require all granted

Order allow,deny

allow from all

</Directory>

</VirtualHost>

# add a second vhost and so on..if user enters http instead of https these below directives redirect user to ssl file in extra folder

<VirtualHost *:80>

ServerName blog.javasqlweb.org:80

#DocumentRoot "c:/httpd-2.4.33-win64-VC15/Apache24/htdocs"

Redirect / https://blog.javasqlweb.org/

</VirtualHost>

#add a 3rd vhost...note that we redirect the http version to https version which is found in the extra folder \ ssl page

<VirtualHost *:80>

ServerName cookiefreecoders.com:80

#DocumentRoot "c:/httpd-2.4.33-win64-VC15/Apache24/htdocs/cookie_free"

Redirect / https://cookiefreecoders.com/

</VirtualHost>


note also to configure the ssl file, httpd-ssl.conf, found in the extra folder ****this is VERY important to enable https pages where u will also install ur ssl certs

Next, Notice also that we have a dotdocs folder. This is where index.html lives or index.php whichever u prefer. For the beginner, PHP is wildly popular because of its front and backend javascript, but it can be a bit more complicated than basic html which I recommend we start with.

To get started we listen for an ip address where with http protocol the user types in https://our domain name.com. This is a Request by the Client.

So basically the apache server does 2 things. It listens for a request and then serves up the response which is the web page. Request and response is the foundation for http protocol also known as the client-server computing model.

Create v host(s)

You can also host ssl certs

And optional put tomcat behind apache

And use...Rewrite Conditions for hiding the html and/or php extension. I originally wanted to hide extensions so no one would know I was using php sessions for tracking.

When I first used apache I did not have a domain name yet but I had an IP address so I assigned it to the name ServerName directive. It was then ok to http into this address. But if u have a domain name u can use vhost section of apache to register that name that is routed to ur ip address by aws route 53.

So in the beginning I could have someone at my workplace http into my ip address to see my files and servlets. For local testing I would use localhost or 127.0.0.1 as my ServerName. Also originally I did not have port 80 open but instead I was listening on port 8071 as a security measure. At some point u must listen on port 80 because it is where public requests come in and get responded to.

Next Up... request / response model, then http://localhost then http then https

More to come…….