Article From:
Reference resources:
1. Yum Installation:
1、yum install httpd
Enter y and continue.
2、See a similar return, indicating that the installation was successful
3、Because Linux Red hat defaults to httpd as a system service, httpd can be added to boot-up according to actual needs.
The command to see if a service is booted separately: chkconfig — list service name
A command to open a service separately; chkconfig service name on
Command to close a service separately; chkconfig service name off
View the status of a service: service httpd status
2. Offline Installation of httpd
tar -zxvf httpd-2.4.33.tar.gz
yum install pcre pcre-devel -y
Hundreds of words are omitted below.
3. Common configurations of httpd:
1、Configure httpd to support CGI
vim /etc/httpd/conf/httpd.conf
If this line is commented, remove the comment
LoadModule cgi_module modules/
Set up the CGI directory:
ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”
The configuration is as follows:
<Directory “/var/www/cgi-bin/”>
AllowOverride None
Options FollowSymLinks +ExecCGI
Order allow,deny
Allow from all
Add the CGI extension: (Remove comments)
AddHandler cgi-script .cgi .py
2、Configure httpd to support
a、Install Python
c、Test whether was successfully installed and accessible
code.pyThe contents are as follows:
import web urls = ( ‘/’, ‘index’ ) class index: def GET(self): return “Hello, world!” if __name__ == “__main__”: app = web.application(urls, globals())
Test whether was installed successfully.
python 8080 &
Seeing the following results, the test passed:
d、Configure httpd to support
You can replace’appname’with your own project name.
You can replace’’with your own file name.
/var/www/webpy-app The directory path for the folder that contains your code. py.
/var/www/webpy-app/ Is the full path to your Python file.
Install mod_wsgi: Yum install mod_wsgi (the system defaults to Python 2.6)
Verify that is in this directory/usr/lib64/httpd/modules/
vim /etc/httpd/conf/httpd.conf
Configure Apache to load mod_wsgi module and your project in httpd.conf. Add the following script at the end of the configuration file:
LoadModule wsgi_module modules/
WSGIScriptAlias /appname /var/www/webpy-app/
Alias /appname/static /var/www/webpy-app/static/
AddType text/html .py
<Directory /var/www/webpy-app/>
Order deny,allow
Allow from all
Demo file
import web
urls = (
‘/.*’, ‘hello’,
class hello:
def GET(self):
return “Hello, world.”
application = web.application(urls, globals()).wsgifunc()
Enter’http://your_server_name/appname’in your browser’s address bar to verify its availability.
#Note: After testing, code. py can not import other modules in the current directory. It can be temporarily placed in python’s site-packgs directory.
#Note: mod_wsgi + sessions
If you need to use sessions in mod_wsgi, you can change your code as follows:
app = web.application(urls, globals())
curdir = os.path.dirname(__file__)
session = web.session.Session(app, web.session.DiskStore(curdir + ‘/’ + ‘sessions’),)
application = app.wsgifunc()
#mod_wsgi Performance: For the performance of mod_wsgi, please refer to the wiki page of mod_wsgi: wsgi/wiki/Performance Estimates.

Leave a Reply

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