Jump to content

User:Santhosh.thottingal/Development Server

From mediawiki.org

This page explains how to set up a development server, probably in a VPS. I personally use a hetzner VPS for my mediawiki development.

Advantages

[edit]
  • Stable dev server, unaffected by OS upgrades, laptop changes, local experiments and resulting port and version conflicts
  • Exposing your local dev server with public address help you to share your work quickly

Disadvantages

  • Initial setup time
  • Network delays depending on your internet connection.

Setup

[edit]

SSH, tmux, zsh

[edit]

Cloning repos, create and push commits etc require your ssh keys in the development server. However, don't copy the ssh keys to your development server. Instead forward your ssh agent to development server. This can be done as follows:

In your ssh configuration, ~/.ssh/config, setup the host as follows:

Host yourvpshostname
  HostName xx.xx.xx.xx
  User root
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/id_ecdsa_whatever
  PasswordAuthentication no
  ForwardAgent yes

Then you can connect to your remote server as

 $ ssh yourvpshostname

I use zsh with https://github.com/ohmyzsh/ohmyzsh. I use agnoster theme, and following plugins: git git-prompt ssh-agent docker docker-compose pass timer

I use tmux terminal multiplexer so that I have a persisted terminal session in development server between ssh sessions(or disconnections).

tmux has one limitation though, its ssh agent gets invalidated every time new ssh happens. To fix that have an alias in your .zshrc like this and call when needed:

alias fixssh='eval $(tmux showenv -s SSH_AUTH_SOCK)'


Wiki Family installation

[edit]

I use mwcli based Wiki family. Follow the instructions from User:Santhosh.thottingal/WikiFamily. Since mwcli uses port 8080 and that is common port used by many applications, I changed that to 8765. This can be done at the time of mwcli installation. It will ask for the port and give your port that is very unlikely to be used by other applications.

Rest of the installaiton of MW cli is same as what I explained in User:Santhosh.thottingal/WikiFamily.

Once the installation is complete, the mediawiki, cxserver, and such services are locally available. Next step is to expose that to public, more importantly to your local laptop.

Nginx proxy

[edit]

To expose the mw docker services, I use nginx with the following configuration:

upstream mwdd {
    server 127.0.0.1:8765 weight=50 fail_timeout=30s;
}

server {
    listen 80;
    listen [::]:80;
    server_name ~^(?<subdomain>.+)\.dev\.thottingal\.in$;

    access_log  /var/log/nginx/dev.thottingal.access.log;
    error_log /var/log/nginx/dev.thottingal.error.log;

    location / {
        proxy_pass http://mwdd;
        proxy_set_header Host $subdomain.mwdd.localhost;  # Forward the hostname
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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 {
  server_name ~^(?<subdomain>.+)\.dev\.thottingal\.in$;
   
  listen [::]:443 ssl ipv6only=on;
  listen 443 ssl;
  ssl_certificate /root/certs/dev.thottingal.in+3.pem;
  ssl_certificate_key /root/certs/dev.thottingal.in+3-key.pem;

  access_log  /var/log/nginx/dev.thottingal.access.log;
  error_log /var/log/nginx/dev.thottingal.error.log;
  location / {
    proxy_pass http://mwdd;
    proxy_set_header Host $subdomain.mwdd.localhost;  # Forward the hostname
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    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;
  }
}

Note that I have added an A record in my DNS provider(namecheap in my case) *.dev.thottingal.in so that I can have any subdomains under that.

So the http://en.mediawiki.mwdd.localhost:8765 will be mapped to http://en.mediawiki.dev.thottingal.in and so on.

For https, since setting up wildcard DNS is not easy, I am using a self signed certificate using mkcert.

One more setting is require to let mediawiki know that the domain is not default one from mwdd. For that in the LocalSettings.php, add

$wgServer = "https://$dockerDb.mediawiki.dev.thottingal.in:443";

VS Code

[edit]

VS Code has built in remote development support. Follow instructions from https://code.visualstudio.com/docs/remote/vscode-server

You can open projects and work as if those folders/projects are local.