Table of Contents
Web2py is a free and open source Python framework for developing web applications. You can develop fast, scalable and secure web-based applications rapidly using web2py. Web2py allows you to easily program dynamic web content using the Python programming language. You can perform many tasks, such as development, testing, debugging, and database administration via a web interface. Web2py supports various operating systems like Windows, Mac, and Linux. It readily integrates with Apache, Nginx, Lighttpd and other web servers. Web2py is designed to help secure your server from various kinds of attacks like Cross Site Scripting, Malicious File Execution, and Injection Flaws.
In this tutorial we will explain how to install the Web2py framework on a CentOS 7 server.
- A server running CentOS 7.
- A non-root user with
To get started we will install some required packages and update our system by running the following commands:
sudo yum clean all sudo yum update -y sudo yum install git -y
Once your system is updated, you can proceed to the next step.
Create a directory for the
web2py installation and clone the
web2py repository to it.
sudo mkdir /opt/web2py cd /opt/web2py/ sudo git clone --recursive https://github.com/web2py/web2py.git /opt/web2py
Next you will need to use
openssl to generate a SSL key and certificate which will be used to secure access to the Web2py web interface.
Create a directory to store the key and certificate:
sudo mkdir /opt/web2py_cert
Create a RSA key and certificate pair with the following commands:
cd /opt/web2py_cert/ sudo openssl req -x509 -new -newkey rsa:4096 -days 365 -nodes -keyout web2py.key -out web2py.crt
Answer all the questions:
Generating a 4096 bit RSA private key .........................................................++ ...........................................................................................++ writing new private key to 'web2py.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]:IN State or Province Name (full name) :GUJ Locality Name (eg, city) [Default City]:JND Organization Name (eg, company) [Default Company Ltd]: Your Company Name Organizational Unit Name (eg, section) :IT Common Name (eg, your name or your server's hostname) :web2py Email Address :email@example.com
You should now have a
web2py.crt file in your
Set some restrictive permissions for the SSL key and certificate:
sudo chmod -R 600 /opt/web2py_cert/*
Access the Web2py Web Admin Interface
You are now ready to start python application server.
sudo python /opt/web2py/web2py.py -a '[ADMIN_PASSWORD]' -k /opt/web2py_cert/web2py.key -c /opt/web2py_cert/web2py.crt -i 0.0.0.0 -p 8000 &
Note: You should substitute a strong password after the
-a flag in place of [ADMIN_PASSWORD].
Your Python application server is now running on port
8000. Before accessing web interface, you will need to allow port
8000 through the firewall. (firewalld)
You can do this with the following commands:
sudo firewall-cmd --permanent --zone=public --add-port=8000/tcp sudo firewall-cmd --reload
Open a web browser and point it to the URL
https://your-server-ip:8000, you should see the following "welcome" page:
Click on the blue
ADMIN button and sign in with the password you just specified when starting the server.
You should now have a basic knowledge of installing and running the Web2py web framework. You are welcome to leave feedback in the comments section below if you have any questions related to web2py.
Thank you for sharing the information.