Create A Python App In Azure App Service On Linux

Azure app service on Linux

 
Azure app service is a fully managed compute platform that is optimized for hosting websites and web applications.
 
Prerequisites 
  •  Azure Subscription
  • Python 3.7
  •  Git
  • Azure Command LIne Interface
Step 1
 
Download the sample code
 
In a terminal window, to run the following command to clone the sample application to your local computer  
  1. git clone https://github.com/Azure-Samples/python-docs-hello-world  
Then, go the folder
  1. cd python-docs-hello-world  
Step 2
 
Run the sample code
 
In a terminal window, run the following code
  1. py -3 -m venv env  
  2. env\scripts\activate  
  3. pip install -r requirements.txt  
  4. SET FLASK_APP=application.py  
  5. flask run  
Step 3
 
Open a web browser, and go to the sample app at http://localhost:5000/
 
The webpage will display the following page
 
Run a sample Python app locally
 
Step 4
 
Sign in to Azure
 
Using Command LIne Interface
 
The Azure CLI provides you with many convenient commands that you use from a local terminal to provision and manage Azure resources from the command line. You can use commands to complete the same tasks that you would through the Azure portal in a browser.
 
Run the code 
  1. az login  
Step 5
 
Deploy the Sample Code
 
In the CLI terminal
  1. az webapp up --sku F1 -n demo-app -l centralus  
You get following output:
  1. The behavior of this command has been altered by the following extension: webapp  
  2. Creating Resource group 'appsvc_rg_Linux_centralus' ...  
  3. Resource group creation complete  
  4. Creating App service plan 'appsvc_asp_Linux_centralus' ...  
  5. App service plan creation complete  
  6. Creating app 'demo-app' ....  
  7. Webapp creation complete  
  8. Creating zip with contents of dir /home/username/quickstart/python-docs-hello-world ...  
  9. Preparing to deploy contents to app.  
  10. All done.  
  11. {  
  12.   "app_url""https:/demo-app.azurewebsites.net",  
  13.   "location""Central US",  
  14.   "name""demo-app",  
  15.   "os""Linux",  
  16.   "resourcegroup""appsvc_rg_Linux_centralus ",  
  17.   "serverfarm""appsvc_asp_Linux_centralus",  
  18.   "sku""BASIC",  
  19.   "src_path""/home/username/quickstart/python-docs-hello-world ",  
  20.   "version_detected""-",  
  21.   "version_to_create""python|3.7"  
  22. }  
Step 6
 
Browse the app
 
Browse  the URL http://demo-app.azurewebsites.net.
 
You get the following output.
 
Run a sample Python app in Azure
 
The web application is successfully deployed.
 
Step 7
 
Manage the Azure App
 
In your Azure portal ->Search
 
Navigate to App Services in the Azure portal
 
Then, Click your app name. You'll see your azure app processing details.
 
Conclusion
 
In this article, we learned how to deploy a Python app in Azure app service on Linux OS. I hope you understood how deploy an Azure app on Linux OS. Thank you for your reading. Any doubts in this article, please ask me. 


Similar Articles