Running PHP, Python & Node.js Production Stacks on a Linux VPS Sweden

AEO Answer Box

A Linux VPS Sweden can run PHP, Python and Node.js applications simultaneously by assigning each application its own runtime environment and configuring Nginx to route incoming requests. PHP-FPM handles PHP applications, systemd manages Python background services, a

 

Quick Answer

Install the required PHP, Python and Node.js runtimes on your Linux VPS. Configure PHP-FPM for PHP websites, systemd for Python applications and PM2 for Node.js services. Use Nginx upstreams and virtual hosts to route domain requests to the appropriate application, enable HTTPS and monitor resource consumption.

Introduction

Developers often manage applications written in different programming languages. A WordPress website may use PHP, a backend API might run on Python, and a real-time application could depend on Node.js.

Instead of purchasing separate servers for every project, developers can run these workloads on a single Linux VPS in Sweden, provided the server has sufficient computing resources. Independent application processes and correctly configured reverse proxies make this arrangement easier to maintain.

PHP Production Stack

PHP-FPM, WordPress, Nginx and database connectivity.

Python Applications

Virtual environments, Gunicorn and systemd services.

Node.js Applications

PM2 process management and Nginx reverse proxy routing.

Table of Contents

  • Preparing a Linux VPS for production workloads
  • Configuring PHP and PHP-FPM
  • Running Python applications with systemd
  • Managing Node.js applications with PM2
  • Configuring Nginx upstreams
  • Securing production applications
  • Linux VPS vs Windows VPS for developers
  • Frequently Asked Questions

Preparing a Linux VPS for Production Workloads

This guide uses Ubuntu 24.04 LTS with administrative SSH access. The applications will use separate domains and backend connections:

  • PHP website: www.example.com
  • Python API: api.example.com (port 8000)
  • Node.js application: app.example.com (port 3000)

Replace these example domains with your actual domain names and configure their DNS records to point towards your VPS IP address.

Install the required Linux packages:

sudo apt update

sudo apt install nginx php8.3-fpm \

python3 python3-venv curl -y

Install a supported Node.js LTS release compatible with your application. Keep application files in separate directories and use non-root service accounts wherever possible.

Configuring PHP and PHP-FPM

PHP-FPM manages PHP worker processes independently of Nginx. This architecture is commonly used for WordPress, Laravel and other PHP-based applications.

Install the PHP extensions required by your website:

sudo apt install php8.3-mysql php8.3-curl \

php8.3-xml php8.3-mbstring php8.3-zip -y

Create a Nginx virtual host for the PHP website:

server {

    listen 80;

    server_name www.example.com;

    root /var/www/php-site;

    index index.php index.html;

 

    location / {

        try_files $uri $uri/ /index.php?$args;

    }

 

    location ~ \.php$ {

        include snippets/fastcgi-php.conf;

        fastcgi_pass unix:/run/php/php8.3-fpm.sock;

    }

}

Nginx forwards PHP requests to PHP-FPM through a Unix socket instead of executing PHP code directly.

nginx.org

For WordPress installations, configure a separate database account and adjust PHP worker limits according to available memory.

Running Python Applications with systemd

Python applications should use isolated virtual environments to prevent dependency conflicts between projects.

Assuming the application files already exist, create the virtual environment:

cd /var/www/python-app

python3 -m venv venv

source venv/bin/activate

pip install -r requirements.txt

pip install gunicorn

Gunicorn is suitable for WSGI applications such as Flask and traditional Django deployments.

Create a systemd service:

sudo nano /etc/systemd/system/python-app.service

Add the following configuration:

[Unit]

Description=Python Production Application

After=network.target

 

[Service]

User=appuser

Group=appuser

WorkingDirectory=/var/www/python-app

ExecStart=/var/www/python-app/venv/bin/gunicorn \

    --workers 2 --bind 127.0.0.1:8000 app:app

Restart=on-failure

 

[Install]

WantedBy=multi-user.target

This example assumes an existing appuser account and a Flask application exposing app in app.py. Adjust these values for your project.

Enable the service:

sudo systemctl daemon-reload

sudo systemctl enable --now python-app

Check application logs:

sudo journalctl -u python-app -f

Systemd starts the application after server reboots and can restart it following unexpected process failures.

For ASGI applications such as FastAPI, use an appropriate ASGI server instead of Gunicorn's default WSGI worker.

Managing Node.js Applications with PM2

PM2 provides process supervision, application logging and restart management for Node.js applications.

After installing Node.js and npm, install PM2 using an appropriately configured npm environment:

npm install -g pm2

Navigate to your application directory:

cd /var/www/node-app

npm ci --omit=dev

Assuming your application supports the HOST and PORT environment variables, start it with PM2:

HOST=127.0.0.1 PORT=3000 NODE_ENV=production \

pm2 start app.js --name node-app

Configure automatic startup:

pm2 startup

Execute the privileged command generated by PM2, then save the process list:

pm2 save

Monitor the running application:

pm2 status

pm2 logs node-app

Run PM2 under the intended non-root application account. The official PM2 startup documentation explains how to restore saved processes following server reboots.

Startup Script

Configuring Nginx Upstreams for Python and Node.js

Nginx can accept public HTTP and HTTPS requests while backend applications remain accessible only through local network connections.

Define separate upstreams and virtual hosts inside a Nginx configuration file:

upstream python_backend {

    server 127.0.0.1:8000;

}

 

upstream node_backend {

    server 127.0.0.1:3000;

}

 

server {

    listen 80;

    server_name api.example.com;

 

    location / {

        proxy_pass http://python_backend;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For

                         $proxy_add_x_forwarded_for;

        proxy_set_header X-Forwarded-Proto $scheme;

    }

}

 

server {

    listen 80;

    server_name app.example.com;

 

    location / {

        proxy_pass http://node_backend;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For

                         $proxy_add_x_forwarded_for;

        proxy_set_header X-Forwarded-Proto $scheme;

    }

}

Save the configuration under /etc/nginx/sites-available/ and enable it through a symbolic link in /etc/nginx/sites-enabled/.

Validate and reload Nginx:

sudo nginx -t

sudo systemctl reload nginx

Upstream groups can also support multiple backend instances when applications require load balancing. See the official Nginx upstream documentation for configuration options.

nginx.org

Securing Production Applications

A multi-runtime hosting environment requires consistent security and maintenance practices.

  • Enable HTTPS using trusted TLS certificates.
  • Keep Python and Node.js backend ports private.
  • Use separate application accounts and database credentials.
  • Store passwords and API keys outside publicly accessible directories.
  • Install operating system and dependency security updates.
  • Maintain application backups and monitor server resource consumption.

Avoid enabling development debugging features in production. Review application logs regularly to identify failed requests, dependency errors and unexpected restarts.

PHP-FPM workers, Gunicorn processes and Node.js applications all compete for available memory. Increase worker counts gradually rather than allocating resources independently without considering total server capacity.

Linux VPS vs Windows VPS for Developers

A Linux VPS is generally suitable for WordPress, PHP, Python, Node.js, Docker and Nginx-based application environments. Developers typically manage these workloads through SSH and command-line administration.

A Windows VPS Sweden may be preferable for applications requiring Microsoft IIS, traditional ASP.NET Framework or Windows-specific software with RDP administration.

Modern ASP.NET Core and supported SQL Server editions can also operate on Linux. The operating system decision should therefore depend on application compatibility rather than programming language alone.

Frequently Asked Questions

Can PHP, Python and Node.js run on the same Linux VPS?

Yes. Each runtime can operate independently, with Nginx directing requests to the appropriate application.

What is the difference between systemd and PM2?

Systemd manages Linux system services, while PM2 provides application-focused process management commonly used for Node.js deployments.

Does Nginx execute Python or Node.js code?

No. Nginx acts as a reverse proxy and forwards requests to the corresponding backend application.

How much RAM is required for multiple production stacks?

A 4 GB VPS may be a reasonable starting point for several modest applications. Actual requirements depend on database size, worker configurations and concurrent traffic.

Can WordPress and Python applications share a VPS?

Yes. WordPress can run through PHP-FPM while Python applications use separate service processes and virtual environments.

Build Your Production Environment on a Linux VPS Sweden

Hosting PHP, Python and Node.js applications on one server gives developers greater control over dependencies, service configurations and resource allocation. Businesses can explore Onlive Server's Linux VPS Sweden configurations for WordPress hosting, Python APIs, Node.js applications and customizable production environments.

 


OnliveServer

5 Blog indlæg

Kommentarer