Step-by-step guide:
- Install CentOS (minimal version will work) in your virtual box
- Install httpd :
yum install httpd
- Install httpd-devel
yum install httpd-devel
The above command will build and compile several modules into the http server. The one that will be used for this exercise is called apsx (Apache Extension Tool). To see which modules are currently compiled into the http server, you can use the -l command line option. You can also see what modules are loaded dynamically using the -M command line option. - Install gcc
yum install gcc
- Install mod_wsgi module for Apache httpd server
pip install mod_wsgi>
- To verify that the installation was successful, use the following command:
mod_wsgi-express start-server
This will start a foreground process running Apache/mod_wsgi server - To start the Apache/mod_wsgi server in daemon mode:
- change the user to root:
su root
orsudo sh
- make sure the PATH environment variable of the root is prepended with the correct python dependencies.
e.g.,export PATH=/opt/anaconda/bin:$PATH
- from the base directory of your django app type in the following command
python manage.py runmodwsgi --setup-only --port=8001 --user apache --group apache --server-root=/etc/name-of-the-directory-where-you-want-your-web-app-to-be-served
The above command will start httpd/wsgi server at the localhost, but if you want other people can have access to your website, simply add –host argument to the above command with the ip address of the host server where the application is being deployed:
python manage.py runmodwsgi --setup-only --host=99.123.234.456 --port=8001 --user apache --group apache --server-root=/etc/name-of-the-directory-where-you-want-your-web-app-to-be-served.
Before you run the above command, make sure you have either ‘*’ or the host’s ip address listed as one of the allowed hosts in the settings file of your Django app. - The above command will create apachectl file in the above server root folder. Run this file with “start” argument to start the Apache/mod_wsgi server. The server can be stopped and restarted with stop and start arguments respectively.
For example:/etc/mod_wsgi-8001/apachectl start
- change the user to root: