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
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php
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
#last used....this is the ip address we get from our aws EC2 server
# 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
# Secure (SSL/TLS) connections....we need this file found in the extra folder in order to config ssl
# add ServerAlias for sub directories
# add this to allow users access to files, require all replaces allow from all i think, see above for instructions
#Options Indexes FollowSymLinks
Require all granted
allow from all
# 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
Redirect / https://blog.javasqlweb.org/
#add a 3rd vhost...note that we redirect the http version to https version which is found in the extra folder \ ssl page
Redirect / https://cookiefreecoders.com/
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
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…….