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
If this line is commented, remove the comment
LoadModule cgi_module modules/mod_cgi.so
Set up the CGI directory:
ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”
The configuration is as follows:
Options FollowSymLinks +ExecCGI
Allow from all
Add the CGI extension: (Remove comments)
AddHandler cgi-script .cgi .py
2、Configure httpd to support web.py
c、Test whether web.py 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()) app.run()
Test whether web.py was installed successfully.
python code.py 8080 &
Seeing the following results, the test passed:
d、Configure httpd to support web.py
You can replace’appname’with your own project name.
You can replace’code.py’with your own file name.
/var/www/webpy-app The directory path for the folder that contains your code. py.
/var/www/webpy-app/code.py Is the full path to your Python file.
Install mod_wsgi: Yum install mod_wsgi (the system defaults to Python 2.6)
Verify that mod_wsgi.so is in this directory/usr/lib64/httpd/modules/
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/mod_wsgi.so
WSGIScriptAlias /appname /var/www/webpy-app/code.py/
Alias /appname/static /var/www/webpy-app/static/
AddType text/html .py
Allow from all
Demo file code.py
urls = (
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: http://code.google.com/p/mod wsgi/wiki/Performance Estimates.
Link of this Article: Httpd installation and configuration (cgi, wsgi)