MENU
Language

How to run python on a lollipop server

We will explain in detail the steps to run a Python script on Lollipop’s server.

0. Preparation

Follow the steps below to
– SSH connection to Lollipop’s server
・Check Python version
– Install pip

Run the

1. Check the Python execution environment

Check your Python version

SSH to Lollipop’s server and check the installed version of Python.

python3 --version

Example output:

Python 3.7.17

Preparing a directory for CGIcgi-bincreating a directory

Lollipops require CGI scripts to be placed within a specific directory (e.g., ). cgi-bin
First,web create a directory insidecgi-bin the /<public folder> directory.

is the value specified in the public (upload) folder > your own domain settings.

mkdir -p ~/web/<公開フォルダ>/cgi-bin
  • -pThe option is automatically created if the parent directory(web) does not exist.

Set the appropriate permissions in the directory of the CGI script.

chmod 755 ~/web/<公開フォルダ>/cgi-bin

confirmation

Verify that the directory was created correctly

ls -ld ~/web/<公開フォルダ>/cgi-bin

Example output:

drwxr-xr-x 2 XXXX.XXXX LolipopUser 10 1月 1 12:00 /home/users/0/XXXX.XXXX/web/<公開フォルダ>/cgi-bin

Place the file and check it in action Once you have created the directory in the above steps,cgi-bin upload a Python script to check it in action.

2. Prepare a Python script

Create a Python script.

Script example:

Save the following scriptexample.py as:

#!/usr/bin/env python3
print("Content-Type: text/html\n")
print("<html><body>")
print("<h1>Hello, Python on Lolipop!</h1>")
print("</body></html>")

Point:

  • Stated at#!/usr/bin/env python3 the beginning of the script (specify the Python path).
  • Be sure to output “Content-Type (CGI script requirement).

3. Upload your script

Upload the script to the server’scgi-bin directory.

Way:

  1. Use FileZilla and more
    • Connect using Lollipop’s FTP/SFTP information.
    • in the directory ofcgi-binexample.py the server.
  2. Permission Settings
    • CGI scripts require execution permissions.
chmod 755 example.py

4. Run in your browser

Access the uploaded script to see it in action.

Example URL:

https://あなたのドメイン/cgi-bin/example.py

Normal operation results:

  • 「Hello, Python on Lolipop!」 If it is displayed, it is a success.

5. Periodic execution with Cron job (optional)

Lollipops allow you to utilize Cron to run Python scripts on a regular basis.

Way:

  1. Log in to the Lollipop management screen.
  2. Select “Server Management Settings” → “Cron Settings”.
  3. Create a new job.
Let's share this post !

Author of this article

AIアーティスト | エンジニア | ライター | 最新のAI技術やトレンド、注目のモデル解説、そして実践に役立つ豊富なリソースまで、幅広い内容を記事にしています。フォローしてねヾ(^^)ノ

Comments

To comment

目次