Setup a Ubuntu VPS | Setup a Server | Make ready a server for python deployment | deploy python using apache and wsgi |

K. Behera
5 min readFeb 8, 2021

Let’s make ready server for deployment in python. so in this topic we are going to setup a server and make ready for python deployment.

So there is a lot of method is available to deploy a python those things also we will discuss in this section but basically i am going to discuss deploy using apache and wsgi.

Before that if you dont know about vps and you want to know it then Click here to check my previous blog where i have discussed about types of servers.

Ok so the methods to make your application live or make visible to public there is multiple methods is there available like

1. you can run your application and make your laptop live/make your laptop as your own server,

2. use any other device like raspberry pi or arduino any kind of micro controller and run your application there and make port forwarding in your router and make your application live. and if you want to know more then comment in the comment box and let me know.

3. Rent a server and deploy your application and make your application live.

And now comes into picture that how we will deploy the application.

for deployment we have multiple webservers and lot of modules packages which will help us to deploy application in server.

ok so let me make it simple.

Here i will mention some of the terms and explain and after that i believe you can get it fully.

Note: — so these all are for python and to deploy in ubuntu vps

1. Apache: — it is a free opensource cross platform webserver software which will help your server connect to webserver.

2. NGINX: — it is also a opensource software for web serving , reverse proxying, caching, load balancing etc etc… so nginx has lot of functionalities that we can take and work on it.

3. WSGI : — it is a configuration that describes how a webserver communicates with web application. basically this has very vital role on deployment that it decides how our we application will connect with web server.

4. UWSGI: — it is the same like WSGI it is a software that aims at developing a full stack for building hosting services.

5. Gunicorn: — Green Unicorn it is a python wsgi http server server for unix it also has lot of functionalities that it hekps your application to work smoothly and run faster . as its name suggest it will make your connections faster and better and also it will balance your load according to that.

So before going to start with deployment process lets have a look into what is apache and wsgi .

What is apache :- Basically apache is a opensource foundation where we can find various kind of products from apache but here i am going to tell about apache web server which is also a essential part to deploy a server.

as we have discussed apache is a webserver and it has a very good brand. so from my case it is trusted.

and i have choosen here this one because this is so easy to configure.

In this topic i will run apache, mysql and php in your ubuntu server.

list of commands are here please look into it.

1. sudo apt update : — this command will update your existing packages and also make ready for you furthur installation.

2. sudo apt-get install apache2 : -Here we are trying to install apache here and to run apache in server.

3. sudo apache2ctl configtest : — using this command we can check whether our apache working properly or not it should return “syntax ok”

4. sudo systemctl restart apache2 : now we can restart apache in our server.

5. sudo ufw app list :-in this command we can check our firewall list in our server that are activated and running.

6. sudo ufw app info “Apache Full”

7. sudo ufw allow in “Apache Full” : — in this command we are allowing the firewall to the apache full access. that now we your apache can run in our server.

now we can check whether apache is running our server or not using your servers public ip address.

just open any browser and enter your public ip address in your URL bar. and check you should be getting apache page running in your server if not then check with above command or check with firewall otherwise trouble shoot it.

8. To install MySql we will have only one command : — sudo apt-get install mysql-server

and done..👍

Next move on to install php in server

9. sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql : — after giving this command now php will be running in your server now just need to some configurations.

10. sudo nano /etc/apache2/mods-enabled/dir.conf : — here just replace php in the field of html and write html in the field of php because we wanted to now run our php in our server.

then give command to restart the server.

11. sudo systemctl restart apache2.

for testing php is running on the server give the below command.

12. sudo nano /var/www/html/info.php : — here just paste below code.

<? php

phpinfo()

?>

save it and close it .. to save this one click on “ctrl+x” and then “y” and press “enter ⤶”

and boom 👊… your php page is ready.

now check with your ip address in your browser it should display your php page. if not then restart apache using above command

and finally lets make your server ready for your python application deployment.

13. install mod-wsgi for python3

sudo apt-get install libapache2-mod-wsgi-py3 :- using this command you will install the mod wsgi and apache if you have not install previously it will install it.

14. sudo a2enmod wsgi :- to enable wsgi in server this is the command using this one we can enable wsgi in our server.

15. sudo apt-get install python3-pip : — using this command now we are able to install python3 and also the pip for installing any package in our server or application for furthur deployment.

So these 15 commands will make your server ready for deployment.

so in the next article we will look into how to deploy python application in server using python frameworks.

so if you have not read ,my previous blogs please check the links below.

1. python frameworks in this link you can find details about the python frameworks

2. Details about server visit this link to check detail about servers types of server and vps server.

So Thank you 🙏

waiting for your comments any feedback please give below..😍

Originally published at https://khirod-blog.blogspot.com on February 8, 2021.

--

--