Category: Linux

How to run Kong servers with SystemD

Kong is one of my favourite projects, I do like it and keep pushing my current company and most of who I know to use it. So today I’ll talk about installing version 0.10.x and how to run it automatically via SystemD on Ubuntu 16.04.

Let’s talk about installing Kong, basically, we have two steps:

First, installing Kong (this taken from the docs):

This will install Kong correctly on your server successfully.

Continue reading

Filed under: Business, Code, Linux, Nginx

Renew let’s encrypt SSL via systemd

I’ll assume that you are using Ubuntu 16.04 and nginx on your server, as I’ll talk about installing Certbot and then how to setup the renew process.

To install Certbot (the simple way) you need to update your system and run the following commands:

After installing Certbot you will need to run the following command which will edit your nginx configuration files and do the magic

And to renew your certificate you should run the following command ( which is the command that we will automate )

Now that we have everything up and running we will need to configure Systemd to automate the renew process, the following is copied over from Sheogorath’s Blog post but modified a bit to work with Certbot instead of letsencrypt binary.

Continue reading

Filed under: Linux, Nginx

What you should use to write a CLI app

I was going to write a post about this, but then I found out that I don’t have a big plan for what am going to write, so instead, I prefer that you go and read this article: Re-Introducing Symfony Console – CLI PHP for the Uninitiated! its not exactly what I wanted to write, but why to re-write things when someone already did that.

Intro:

As a web developer, we are always fascinated with what we can do for the web, we have the best technologies ( not including old IE version ), we have some limitation, but now we can also use web technologies to develop Desktop apps. So talking about CLI apps may not be the best topic here, but sometimes its way better to use CLI to develop an application than using the normal route with nginx/apache, why you may need to do that? the reasons are unlimited, the main one is your judgement.

First of all developing CLI application with PHP does not differ that much from developing Web app, you will use the same code, but your user will interact with the app via Terminal not Visual UI, this can be helpful when you are doing something like processing big files,  CSV files, or maybe doing some maintenance. You will need to care about the structure of your app, and how you code, at the end you don’t want to spend a lot of time trying to debug it and even losing control and make it way complicated than it should. so lets start to show you how I do it, then you may use the same or even better technique to develop your own.

Required Components:

There are a lot of libraries which we can utilize to develop the code, as with web you are not limited to specific framework or library, you can create your CLI with nodejs or even better with PHP ;) , for me I depend on PHP so I’ll list all the libraries that I use here:

  1. Symfony Console : http://symfony.com/doc/current/components/console.html
  2. Symfony Process : http://symfony.com/doc/current/components/process.html

Symfony Console is the main component here, which will help us to build a Command Line Application (also known as CLI).

Filed under: Code, Linux, PHP

Why I choose CLI over web interface

Yesterday I was working on a piece of code which needs to communicate with beanstalkd server, so I spent about an hour or so trying to figure out which framework to use, Lumen, Slim or even Laravel.

The code was not that much complicated, just getting some data and passing it to the queue server and processing it later. Nothing that much complicated, I even though to do it with plain PHP and not use any framework at all.

Long story short, I ended up creating a PHP CLI application, I mean literally I found it the best solution, so why did I choose to go with CLI instead of any regular web application and make it a web app or even a RESTFUL app.

I went with CLI for few reasons :

  1. There is no interaction from outside, so no one will communicate with it or even call it from outside the server
  2. It has only one purpose, getting the data and push them to the queue server to be processed later.
  3. needed it to be light, and simple.
  4. didnt need all this mambo jambo of setting up nginx, PHP & SSL .. etc

And the nice thing is that I was able to do it in less time than if I ever wanted to use a framework.

 

so my advice to you, if you are going to work with microservices try to check if you can do the job via CLI, if yes dont do it via web.

 

 

Alert! As usual, English is not my first language so if you found any linguistic error just let me know to fix. thanks in advanced.
Filed under: Business, Code, Linux, PHP

How to test and auto deploy your laravel code from Gitlab

Few days ago, I was playing with the new Laravel 5.4 and Gitlab CI, and got to the point where I wanted the CI to test my code once I push it.

Using google lead me to this post on Laracasts, and it was the starting point for me, there you can get important files .gitlab-ci.yml and .gitlab-ci.sh  , basically the first one will define the stages for the testing and the second one will build the environment for your test.

So lets look at a short version of .gitlab-ci.yml

Continue reading

Filed under: Business, Code, docker, Laravel, Linux, MySQL, PHP