Skip to content

Instantly share code, notes, and snippets.

View mortenege's full-sized avatar

Ege mortenege

View GitHub Profile
@mortenege
mortenege / django_channels_with_vagrant_apache_supervisor.md
Created March 4, 2018 06:56
Django Channels with Vagrant, Apache and Supervisor

Django Channels with Vagrant, Apache and Supervisor

This post describes how to set up a Django Channels environment in Vagrant using Apache as a reverse proxy. We are picking up from an environment we already configured, see this previous post. This guide will describe multiple steps of the process including:

  • How to install and configure Channels
  • Creating a simple Echo app that utilises websockets
  • Configuring Apache to route our websockets
  • Running Channels in a production-like environment

Step 1

@mortenege
mortenege / django_channels_aws_eb_alb.md
Created March 4, 2018 06:48
Django Channels on AWS Elastic Beanstalk using an ALB

Django Channels on AWS Elastic Beanstalk using an ALB

This post will describe how to set up a Django Channels solution using AWS Elastic Beanstalk [EB]. This guide is written in response to there being very little information on the combination of Channels and AWS. Mainly many solutions end with problems regarding websockets, which is a fundamental part of Channels. See here and here. This guide will consist of multiple step-by-step parts including

  • How to set up a local Django Channels solution
  • How to set up an Application Load Balancer [ALB] to serve websockets
  • How to configure EB to deploy Cha
@mortenege
mortenege / simple_django_channels_logging_setup_for_aws.md
Created March 4, 2018 06:40
Simple Django/Channels logging setup for AWS

Simple Django/Channels logging setup for AWS

In this port we will be exploring possible logging options when having deployed our Django Channels app to AWS Elastic Beanstalk (see previous posts). An excellent guide to Logging with Django can as always be found in their docs. Here we will explore a simple logging setup that has a catch-all for both Django and Channels loggers. A quick reminder of the setup we have on our AWS Elastic Beanstalk server. HTTP requests are being server by Django as WSGI through Apache wsgi module. At the same time we are serving WebSocket connections using Daphne on a local port 5000 and several workers using [Su

@mortenege
mortenege / ssl_with_lets_encrypt_vesta_and_wp.md
Created March 4, 2018 06:36
SSL with Let's Encrypt, Vesta and Wordpress

SSL with Let's Encrypt, Vesta and Wordpress

It's time to join the new era of safe internetting. This post descibes how an SSL certificate is acquired, installed and enabled for a server running VestaCP and Wordpress using the free Certificate Authority (CA) Let's Encrypt. The internet and software is ever changing and following one tutorial never suffices to a working solution. This post is my experience following this tutorial using this script. Also this forum post has helped. Prerequisites: This post assumes that you have a webserver with root access and own a domain name. Also that vesatcp is set up to host at least one site on your domain. There is plenty of information about vestacp online and it will therefore not be included here.

Step 1

Lo

@mortenege
mortenege / https_and_www_redirect_using_htaccess_in_apache.md
Created March 4, 2018 06:27
HTTPS and www Redirect using .htaccess in Apache

This post describes how to enforce a secure https connection using the .htaccess-file in Apache. At the same time we would like to redirect all www-requests to a non-www secure request. This post is a concatenation of the following forum posts here and here. Edit .htaccess with the following content.

RewriteEngine On 
RewriteBase / 
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^www\.(.*)$ [NC] 
@mortenege
mortenege / TroubleshootingDjangoChannelschannel_layer.md
Created March 4, 2018 06:24
Troubleshooting Django Channels channel_layer

Troubleshooting Django Channels channel_layer

This post will focus on troubleshooting and debugging the channel layer of any Django Channels application. For this post a local Redis backend is used.

Initial Requirements

It is assumed for the purpose of this example that a working Django Channels application is running, and that a proxy service is running that is able to upgrade the HTTP connection to a WebSocket connection. A Redis server is also required.

The Example Application

@mortenege
mortenege / SupervisedRedisToControlDaphne.md
Created March 4, 2018 06:17
Running a Supervised Redis to control Daphne

Running a Supervised Redis to control Daphne

In a previous post we discovered that if Redis crashes and is restarted Daphne will not work properly for WebSocket connections. We discovered that it is a bug in Daphne and that using Supervisord to solve this problem might be a solution. We are going to use EventListeners in Supervisord to run a customized python script to restart Daphne if Redis crashes. First we add Redis to our supervisord configuration. Note: Remember that Redis should NOT be run in daemonized mode when running in Supervisord.

[program:Redis_Server]
command=redis-server /etc/redis/redis.conf
[...]
@mortenege
mortenege / LaravelWPLogin.md
Last active February 28, 2018 08:39
Use a Wordpress User table and login logic within Laravel

Use WP user table and password control in Laravel

This is useful for anybody who is running Laravel Framework, but for some reason keep their User logic in Wordpress.

Note: This assumes any other Wordpress to Laravel migrations have already been taken care of (like adding remember_token to user table and setting up a User-model that extneds Illuminate\Contracts\Auth\Authenticatable)

requires either MikeMcLin\WpPassword or Hautelook\Phpass

PS. This can probably also be accomplished by swapping out the app-hasher for the entire project!