Run CGI written in python on Sakura's rental server

Introduction

I am using the standard plan on Sakura's rental server. Create a simple "Hello World" program written in Python I will explain how to operate as CGI.

Program written in Python

Hello.cgi


#!/usr/local/bin/python
print "Content-Type: text/html\n\n"
print "Hello World"

Points to keep in mind when creating files

File extension

It must be "cgi" instead of "py" (* 1).

Character code and line feed symbol

Set the character code to "UTF-8" It is good to set the line feed symbol to "LF". It seems that an error may occur with other combinations.

Command path to python

The command path to python described in the first line of "Hello.cgi" above. For the latest information, please check the item "Program Command Path" on the Sakura Support Page> "Rental Server Service Specifications"> "About CGI / PHP / SSI" → Sakura Support Page

Up to rental server

Up destination

The created file "Hello.cgi" can be uploaded anywhere under the document root (/ home / account name / www /), or it can be a newly created folder under the document root.

Permission settings

File permissions must be set to 755, 705, or 700 (* 2).

Also, if the file "Hello.cgi" is uploaded in the folder created under the document root, the folder permission for the folder containing the file "Hello.cgi" is 755, 705, or 700 (* 2). Must be set to.

Necessity of .htaccess

".Htaccess" is not required.

However, as you pointed out in the comment section, If this is left as it is, the extension "py" must be changed to "cgi", which is inefficient. So, create .htaccess with the following description Allows it to operate as cgi even with the extension "py" There is also a method called.

.htaccess


AddType application/x-httpd-cgi .py

Reference (Sakura's support page)

The latest information is Sakura support page> "Rental server service specifications"> "About CGI / PHP / SSI" page, there is an item "File and directory settings", so please check here → Sakura support page //help.sakura.ad.jp/206206041/)

Operation check

Specify the URL where "hello.cgi" is located in the browser Confirm that "Hello World" is displayed. URL specification example: If you place "hello.cgi" in the document root, It will be "https: // (domain name) /hello.cgi".

Afterword

When I tried CGI in Python for a moment, It would be nice to have a simple example! I thought, so I made this post. I hope it helps someone.

Recommended Posts

Run CGI written in python on Sakura's rental server
Run Python CGI on CORESERVER
Stray build of Python 3 on Sakura's rental server (Note)
CGI server (1) python edition in one line
Build CGI Server running on Python 3 on Docker
Run AzureKinect in Python on Christmas Eve.
Run Python in C ++ on Visual Studio 2017
Run python wsgi server on NGINX Unit
[Note] Python environment construction on rental server "CORESERVER"
Run Python YOLOv3 in C ++ on Visual Studio 2017
TensorFlow: Run data learned in Python on Android
DNS server in Python ....
Run Openpose on Python (Windows)
Run automatic jobs in python
Run shell commands in python
Run Python unittests in parallel
Run unix command on python
Gacha written in Python -BOX gacha-
Test.py is not reflected on the web server in Python3.
Squid Lisp written in Python: Hy
Run the output code on the local web server as "A, pretending to be B" in python
How to install OpenCV on Cloud9 and run it in Python
Install Python3 on Sakura server (FreeBSD)
Let's run "python -m antigravity" in python
Run shell command / python in R
Write an HTTP / 2 server in Python
Run a Linux server on GCP
Run Python on Schedule on AWS Lambda
Compatibility diagnosis program written in python
run uwsgi server in uwsgi-gevent mode
Run TensorFlow2 on a VPS server
Behavior of python3 by Sakura's server
Python CGI file created on Windows
Run unittests in Python (for beginners)
Run a simple algorithm in Python
Simple gacha logic written in Python
Periodically run Python on Heroku Scheduler
Create a shortcut to run a Python file in VScode on your terminal
Modules cannot be imported in Python on EC2 run from AWS Lambda
Deploy and use the prediction model created in Python on SQL Server
Rock-paper-scissors with Python Let's run on a Windows local server for beginners
A memorandum when Django is installed on Sakura's rental server (standard plan)
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Fourier series verification code written in Python
Stress Test with Locust written in Python
Run servo with Python on ESP32 (Windows)
Find files like find on linux in Python
Notes on nfc.ContactlessFrontend () for nfcpy in python
[Python] Run Flask on Google App Engine
Run the Python interpreter in a script
Run servomotor on Raspberry Pi 3 using python
One liner webServer (with CGI) in python
[Python] Run Headless Chrome on AWS Lambda
Run Python code on A2019 Community Edition
Install Python3 on mixhost server [Currently NG]
Make cron-like jobs run regularly in Python
Run Jupyter notebook on a remote server
Notes on using code formatter in Python
Put Docker in Windows Home and run a simple web server with Python
How to run GUI programs such as tkinter in Python environment on WSL2
Until you install Python with pythonbrew and run Flask on a WSGI server