System Requirements
- A server with the latest Arch Linux release (refer to the official setup guide).
- A functional web server — either Apache or Nginx installed and configured.
- Root-level access (sudo):
Commands that require root privileges are marked with a
#. The best practice is to usesudowith each root-level command as a non-root user. - An installed and familiar text editor such as
vi,vim,nano,emacs, or any equivalent tool.
Matching infrastructure at centron
Scripts and services eventually need an environment that keeps running: ccloud³ VMs from €3.12 per month, billed by the hour. Rent a cloud server →
Python 3.7 Installation on Web Server
Using Apache
It is not feasible to run both Python 2.x and 3.x Apache modules simultaneously on Arch Linux. However, this is generally not an issue.
To activate Python 3.x support:
# pacman -S mod_wsgiNext, modify the Apache configuration file at /etc/httpd/conf/httpd.conf. Scroll to the end of the LoadModule entries and append:
LoadModule wsgi_module modules/mod_wsgi.soUsing Nginx
To enable Python 3.x with Nginx, execute:
# pacman -S uwsgi-plugin-pythonValidating Python Setup
In your desired directory, create a test.py file containing this script:
#-*- coding: utf-8 -*-
def wsgi_app(environment, start_response):
import sys
output = sys.version.encode('utf8')
status = '200 OK'
headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, headers)
yield output
application = wsgi_appApache Configuration
To integrate the test application with Apache, append the following to /etc/httpd/conf/httpd.conf or insert it inside the appropriate <VirtualHost> block if using multiple hosts:
WSGIScriptAlias /wsgi_app /srv/http/test.pyRestart Apache for changes to apply:
# systemctl restart httpdNow, open a web browser and navigate to http://YOUR-SERVER-WEB-ADDRESS-OR-IP/wsgi_app. A test page displaying your Python and GCC versions should appear.
Finally, clean up by removing the test.py file and deleting the related WSGIScriptAlias directive from the Apache configuration.
Then restart Apache again:
# systemctl restart httpdConfigure Python 3.7 with uWSGI and Nginx on Arch Linux
Create the uWSGI Configuration
Begin by creating a new file at /etc/uwsgi/wsgi_app.ini and populate it with the configuration below:
[uwsgi]
socket = /run/uwsgi/wsgi_app.sock
uid = http
gid = http
plugins = python
chdir = /usr/share/nginx/html/
wsgi-file=test.py
callable = applicationTo begin serving wsgi_app with uWSGI, execute:
# systemctl start uwsgi@wsgi_appUpdate Nginx Configuration
Edit /etc/nginx/nginx.conf. In every server block where testing is desired, add the following configuration. If you are using separate virtual host files, apply the change to each one individually:
location ~ \wsgi_app {
root /usr/share/nginx/html/;
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/wsgi_app.sock;
}Restart Nginx to apply the changes:
# systemctl restart nginxOpen your browser and go to http://YOUR-SERVER-WEB-ADDRESS-OR-IP/wsgi_app. You should see a test page displaying the current Python and GCC versions.
Cleanup
After confirming it works, remove the test.py file and the location block for wsgi_app from /etc/nginx/nginx.conf.
Restart Nginx once again:
# systemctl restart nginxThen, stop the uWSGI service for wsgi_app:
# systemctl stop uwsgi@wsgi_appLastly, delete both the /etc/uwsgi/wsgi_app.ini and test.py files to complete the cleanup.
Conclusion
By following these steps, you’ve successfully configured Python 3.7 with uWSGI and Nginx on an Arch Linux server. This setup enables robust WSGI application serving while maintaining flexibility and performance. Don’t forget to clean up temporary test files and configurations to keep your server tidy and secure.
Testen Sie Ihr Setup auf ccloud³
Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.