RHCE Work With Apache HTTPD Web Service Part 5-Intergrating Dynamic web Content Dev Ops Lanka

Apache HTTPD serving dynamic web content

What is dynamic web content ?

Previous lessons https://devopslanka.com/category/apache-httpd/.we have discuss how to serve static html content using Apache httpd. But most of the website in internet does not serve static web pages. They have serve dynamic webpages that interact with the user inputs and requirements.as example think about user login page . There is user login page that have created with html ,css ,java script and ajax and more.When user enter user name and password user input fields captured and analyze with back end.May be back end can be php,python or any web development language.And compare with the records on the data base  .Data base solution can be MY SQL ,Mongo DB or anything.After authenticate user then showing next page.This is basic scenario of dynamic web content.

Common Gateway Interface(CGI)

This is the oldest method of generating the dynamic web content called as common gateway interface AKA CGI.if cgi content requested apache httpd does not server the CGI Content.CGI content most of time written by scripting language like Python ,Perl even bash script also run. To serve cgi content apache httpd should have to configure.

Set Up Apache HTTPD CGI on RHEL 7

Previous post i have discuss how to add ssl to domain and serve ssl with apache httpd.Today im continue with the previous post.if you are not refer that just take a look at previous post..

https://devopslanka.com/2018/01/24/rhce-work-apache-httpd-web-service-part-4-configuring-https/

Now we have devopslanka.com with SSL.Because i have add DNS record to the /etc/host file

/etc/hosts

Today im going to execute shell script via navigating the https://devopslanka.com/cgi-bin/time.sh

Ok lets get’s started

First grep and check ScriptAlias for /etc/httpd/conf/httpd.conf

it will show result like this.

so there is

 

in default httpd.conf file so if we put shell script there.it should execute and give a result.lets display today date and time

create file

First we are defining what type of script is this this is bash script so we add #!/bin/bash.Then we are teling what type of content should provide this is html or you can use text.

After that add executable permission to the bash file

Then run script manually and check its working.

This is result

Now lets try to execute this script via url

first restart the apache httpd

then open web browser and navigate to

But instead of executing the script web browser consider this as normal web file.

 

CGI script downloads instead executing

simply change the extension time.sh to time.cgi

then navigate to https://devopslanka.com/cgi-bin/time.cgi

How to Running scripts outside of the cgi-bin default directory

Lets create different directory inside /home/myscript

then check context type for previous time.sh file created inside /var/www/cgi-bin/time.sh

context type is httpd_sys_script_exec_t

ok lets copy /var/www/cgi-bin/time.sh file to /home/myscript/time.sh

check context type of /home/myscript/time.sh

see new file don’t have context type

lets add context type to it

search man page for semanage example

select man page semanage-fcontext

then shift+g to go down

there is example

change example as your requirement

 

get context type from cgi-bin folder and change it as below

after that execute restorecon -R -v /web

Now check context type again for new location /home/myscript

now context type is changed.

Ok now lets go back to /etc/httpd/conf/httpd.conf file and change ScriptAlias for our custom one before changing the script alias i have commented previous one for backup.

this is original one

i’m changing this to this

And addition im adding directory tag also.so everything looks like this

check for syntax errors

Then restart apache httpd

Now open web browser and navigate to https://devopslanka.com/sam/time.sh

but you will face previous error.file not executing instead of executing browser asking for download file.

change time.sh file to time.cgi

i tried this method also but it wont help

https://devopslanka.com/sam/time.cgi is working perfectly

well we have done the all the things with /etc/httpd/conf/httpd.conf default file.lets take a look how to do this in virtual host file.

 

How to Running scripts outside of the cgi-bin default directory with Virtual host file

we have created virtual host file called devops.conf inside /etc/httpd/conf.d/devops.conf in previous lesson

https://devopslanka.com/2018/01/24/rhce-work-apache-httpd-web-service-part-4-configuring-https/

Now comment ScriptAlias tag in /etc/httpd/conf/httpd.conf file and copy the content that we previously created.

This content

you can see i have commented that #ScriptAlias /sam/ “/home/myscript/” tag in default httpd.conf file

then open our virtual host file located in

add this copied content to the below of your virtual host file

so final everything is looks like this

 

Then navigate to https://devopslanka.com/sam/time.sh

its working perfectly

I hope you will learn something from this tutorial.if you like this tutorial please share with your friends.Share ow facebook ,twitter,google plus.

next tutorial i will discuss about how to use Dynamic web content Python,php and mysql.See you in next tutorial.

Thanks for watching

Have a good day

Sameera Dissanayaka

 

 

 

5 thoughts on “RHCE Work With Apache HTTPD Web Service Part 5-Intergrating Dynamic web Content Dev Ops Lanka

  1. Desire to say your article is as astonishing simply.

    The clarity in your
    post is just cool and i can assume you are a specialist on this subject matter.

    Well with your permission i want to to seize your Feed to keep updated
    with forthcoming post. Thanks a lot a million and
    please keep on the
    gratifying work.

Leave a Reply

Your email address will not be published. Required fields are marked *