• Home
  • RHCE Work With Apache HTTPD Web Service Part 6-Integrating Dynamic Web Content Serving PHP content Dev Ops Lanka

RHCE Work With Apache HTTPD Web Service Part 6-Integrating Dynamic Web Content Serving PHP content Dev Ops Lanka

Hello Friends previous lesson we have discuss how to serve dynamic web content and serving CGI scripts using Apache HTTPD.if you missed that lesson you can quick go through that lesson


Today lesson we are discuss about how to serve php content in apache httpd and serving dynamic python content.

Serving Dynamic PHP content in Apache HTTPD

For serving php content we need module called mod_php lets install mod_php

yum install mod_php

after installing mod_php now im changing directory to /var/www/devops and there is already index.html file so i have rename index.html as index.123 and create index.php file there

mv index.html index.123
nano index.php

now /var/www/devops/index.php file like this


echo "hello sameera";


then restart apache httpd

systemctl restart httpd

Then navigate to


now its showing php file

Serving Dynamic Python Content in Apache HTTPD

Python script also can be served via old CGI method but there is new Protocol Called WSGI(Web Server Gateway Interface) using this protocol.Apache HTTPD can server python script also.To do this there is two main step

  1. Install mod_wsgi package
  2. Add WSGIScriptAlias

Install mod_wsgi

yum install -y mod_wsgi

After that add WSGIScriptAlias to the virtual host file

easy way to do this is using readme file

nano /usr/share/doc/mod_wsgi*/README

example says

WSGIScriptAlias /myapp /usr/local/wsgi/scripts/myapp.wsgi

<Directory /usr/local/wsgi/scripts>
 Order allow,deny
 Allow from all

and sample wsgi file should like this myapp.wsgi

def application(environ, start_response):
        status = '200 OK'
        output = 'Hello World!'

        response_headers = [('Content-type', 'text/plain'),
                            ('Content-Length', str(len(output)))]
        start_response(status, response_headers)

        return [output]

so lets create sample example there and add it to our virtual host file

lets make directory

mkdir -p /usr/local/wsgi/scripts/

And create myapp.wsgi file there

nano /usr/local/wsgi/scripts/myapp.wsgi

now add to virtual host file

nano /etc/httpd/conf.d/devops.conf

add this block below of the virtual host file

WSGIScriptAlias /myapp /usr/local/wsgi/scripts/myapp.wsgi

<Directory /usr/local/wsgi/scripts>
 Order allow,deny
 Allow from all


checked with httpd -t syntax ok

restart apache httpd

httpd -t

systemctl restart httpd

Now everything is ok now navigate to


but this is showing error Forbidden

When you analize error log for apache httpd you can see “client denied by server configuration ..”


Client denied by server configuration wsgi Solved

To fix this issue in RHEL7

comment these lines in this block

#Order allow,deny

#Allow from all and add Require all granted line

WSGIScriptAlias /myapp /usr/local/wsgi/scripts/myapp.wsgi

<Directory /usr/local/wsgi/scripts>
#commented two lines
 #Order allow,deny
 #Allow from all
# Added new line
Require all granted

Then restart apache httpd

systemctl restart httpd

Now navigate to https://devopslanka.com/myapp

Its working Perfectly.

If you like this post please share on facebook,twitter and google plus.if you have any question please leave a comment below i’m happy to help you.See you in a another post

Have a Good Day

Sameera Dissanayaka




Leave A Comment