How to install and configure web2py on CentOS 7

Install Web2Py on CentOS 7

Web2Py is a simple yet powerful Python framework for developing web applications. In this tutorial we will show how to install the Web2Py framework on a CentOS 7 VPS.

First things first. Once you have the VPS make sure that you update it so that you can have the latest software.

# yum update

Create your application directory. In this example, we will be working in the /opt directory but you can use a directory of your choice.

# mkdir /opt/web2pyapp
# git clone --recursive /opt/web2pyapp

We will need an SSL key and a certificate so that we can later access the administrative interface. For safety reasons, it is best if we put them in a different directory.

# mkdir /opt/web2pyapp_keys
# cd /opt/web2pyapp_keys
# openssl req -x509 -new -newkey rsa:4096 -days 3652 -nodes -keyout web2pyapp.key -out web2pyapp.crt

Generating a 4096 bit RSA private key
writing new private key to 'web2pyapp.key'
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [XX]:US
State or Province Name (full name) []:Missouri
Locality Name (eg, city) [Default City]:St. Louis
Organization Name (eg, company) [Default Company Ltd]:Web2Py
Organizational Unit Name (eg, section) []:Web2Py
Common Name (eg, your name or your server's hostname) []
Email Address []:

### Set proper privileges for the ssl certificate
cd /opt
# chmod 700 web2pyapp_keys
# chmod -R 600 web2pyapp_keys/*

If everything is done correctly by this step, this is how should our layout in /opt should look like.

# ls -l /opt
total 8
drwxr-xr-x 13 root root 4096 Nov 12 11:21 web2pyapp
drwx------  2 root root 4096 Nov 12 11:04 web2pyapp_keys

# ls -l /opt/web2pyapp
total 1268
-rw-r--r-- 1 root root     214 Nov 12 09:46 ABOUT
-rw-r--r-- 1 root root   12965 Nov 12 09:46
drwxr-xr-x 5 root root    4096 Nov 12 10:37 applications
-rw-r--r-- 1 root root     747 Nov 12 09:46 appveyor.yml
-rw-r--r-- 1 root root   65085 Nov 12 09:46 CHANGELOG
drwxr-xr-x 2 root root    4096 Nov 12 10:01 deposit
drwxr-xr-x 2 root root    4096 Nov 12 09:46 docs
drwxr-xr-x 2 root root    4096 Nov 12 09:46 examples
drwxr-xr-x 4 root root    4096 Nov 12 09:46 extras
-rw-r--r-- 1 root root    6067 Nov 12 09:46
drwxr-xr-x 5 root root    4096 Nov 12 10:37 gluon
drwxr-xr-x 2 root root    4096 Nov 12 09:46 handlers
-rw-r--r-- 1 root root   18338 Nov 12 11:21 httpserver.log
-rw-r--r-- 1 root root    5727 Nov 12 09:46 LICENSE
drwxr-xr-x 2 root root    4096 Nov 12 10:01 logs
-rw-r--r-- 1 root root    5684 Nov 12 09:46 Makefile
-rw-r--r-- 1 root root      24 Nov 12 09:46
-rw------- 1 root root     756 Nov 12 11:10 nohup.out
-rw-r--r-- 1 root root      92 Nov 12 11:20
-rw-r--r-- 1 root root    3896 Nov 12 09:46 README.markdown
drwxr-xr-x 2 root root    4096 Nov 12 09:46 scripts
-rw-r--r-- 1 root root    3320 Nov 12 09:46
drwxr-xr-x 2 root root    4096 Nov 12 09:46 site-packages
-rw-r--r-- 1 root root     337 Nov 12 09:46 tox.ini
-rw-r--r-- 1 root root      52 Nov 12 09:46 VERSION
-rwxr-xr-x 1 root root     900 Nov 12 09:46
-rw-r--r-- 1 root root 1089202 Nov 12 10:01 welcome.w2p

# ls -l /opt/web2pyapp_keys
total 8
-rw------- 1 root root 2057 Nov 12 09:52 web2pyapp.crt
-rw------- 1 root root 3272 Nov 12 09:52 web2pyapp.key

We are ready to start our python application server now.

# python /opt/web2pyapp/ -a 'STRONG-PASSWORD-HERE' -k /opt/web2pyapp_keys/web2pyapp.key -c /opt/web2pyapp_keys/web2pyapp.crt -i -p 8000

web2py Web Framework
Created by Massimo Di Pierro, Copyright 2007-2016
Version 2.14.6-stable+timestamp.2016.
Database drivers available: sqlite3, imaplib, pymysql, pg8000

please visit:
use "kill -SIGTERM 1284" to shutdown the web2py server

IMPORTANT: Make sure that you put your own strong password after the -a flag.
Open up a web browser and put https://VPS-IP-ADDRESS:8000/ in the navbar, where VPS-IP-ADDRESS is your VPS IP Address.
Accept the certificate warning and the Web2Py welcoming page should appear. To login to the administration back-end, click on mysites and enter your password, the one that you used while starting the webserver.

To stop the webserver use the CTRL+C key combination.

Avoiding the open terminal to keep the Web2Py server alive

Since the Web2Py service requires an open terminal to be active, one option that you can use if you wish to exit the terminal and continue working, is by using the ampersand at the end of the command after which you can exit the SSH session.

# python /opt/web2pyapp/ -a 'Password01' -k /opt/web2pyapp_keys/web2pyapp.key -c /opt/web2pyapp_keys/web2pyapp.crt -i -p 8000 &
[1] 1468

To stop the server use the process ID that is provided when you start the server:

# kill -9 1468

Keep in mind that with this way you may miss any important errors or warnings that may show up on the server while you are developing.

Of course, you don’t have to do any of this if you use one of our Python VPS Hosting services, in which case you can simply ask our expert Linux admins to install Web2Py for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

Install Fail2ban on an Ubuntu 14.04 VPS
How to Install Ruby 2.0 and RubyGems 2.1.11 on Ubuntu 13.10 from source
How to install The Bug Genie Issue Tracker on a CentOS 7 VPS
There are currently no comments.

Free Migration to RoseHosting. Award Winning Linux VPS Hosting with Fully Managed Support. Coupon RHBLOG50 for 50% offOrder Now