Updating ghost-cli process name

Imagine you’ve created your new Ghost install but have set it up with the incorrect process name. The official documentation does not tell us how to update it, it just tells us that it can be set using the --pname flag during initial installation. Let’s look at how we can update the process name after we’ve installed our site.

Continue reading “Updating ghost-cli process name”

Disinfecting a Windows machine

So last weekend my sister came to me with a slow performing Windows 8.1 Acer laptop. She wanted me to format it and install a new copy of Windows 8.1.

I’ve been using Debian for the last 3 years. Previously I was dual booting between Windows and Debian in-order to play DOTA 2 with my friends, but since Valve released DOTA 2 on Linux, I’ve had little reason to open my Windows installation. As you’d expect I didn’t have a Windows 8.1 setup disc or ISO lying around. I debated whether to shift her to a clean KDE based Debian machine and she agreed as long as her desktop looked nice but I changed my mind when I saw the software she was using –

  1. Cyberlink PowerDirector Pro
  2. Cyberlink PhotoDirector
  3. Bunch of free games

I’m sure I’d be able to find alternatives for the above, but it’d be too much of a learning curve for her, plus setting up a KDE machine from scratch would take some time.

I decided to investigate the reason for slowness, and possibly fix the problem itself. Upon further discussion with her, I found out that the laptop was not only slow, but was infected with some sort of a malware. She was getting permission errors while opening certain folders, and a lot of the folders were hidden.

Continue reading “Disinfecting a Windows machine”

Renewing Let’s Encrypt certificate

Have the following command setup in my crontab to renew the certificate for this blog, and for the main website – thecurlybraces.com

30 3 1 */2 *  /opt/letsencrypt/certbot-auto renew --pre-hook "" --post-hook "service nginx restart"

This causes the command to run, at 03:30 on day-of-month 1 in every 2nd month.

Output

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/thecurlybraces.com.conf
-------------------------------------------------------------------------------
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for thecurlybraces.com
http-01 challenge for blog.thecurlybraces.com
Waiting for verification...
Cleaning up challenges

-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/thecurlybraces.com/fullchain.pem
-------------------------------------------------------------------------------

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/thecurlybraces.com/fullchain.pem (success)
Running post-hook command: service nginx restart

Incase you want to add more domains to an existing certificate, use the following command –

sudo /opt/letsencrypt/certbot-auto --expand -d blog.thecurlybraces.com -d thecurlybraces.com -d bitsnpieces.thecurlybraces.com --pre-hook "" --post-hook "service nginx restart"

This assumes that you have only a single certificate. If you’ve more, you’ll have to use --cert-name. Read more here.

Just putting this here for reference, and with the hope that it might be useful for someone else.

Setting up a blog using Ghost on Debian

My web hosting’s annual payment date was drawing close, and instead of renewing it, I decided I’d rent a server on Digital Ocean for 10$ a month. It turns out to be a lot more expensive but gives me the option to use the server for something other than just blogging and running PHP application.

After shifting to this new server, the first thing to do was to migrate my blog here. WordPress is an amazing platform, but over the years it has evolved to something a lot more than just a blogging tool. Besides the new kid on the block – Ghost, was creating a lot of buzz for its simplicity. I wanted to give it a try.

I setup my Digital Ocean server with Debian (Jessie 8.2). Node.js is required to run Ghost. Since I wanted to use this server for multiple applications, I decided I’d put nginx as a front facing proxy/compression server.

This blog item is a guide for setting up Ghost on a server running Debian. Let’s start,

Continue reading “Setting up a blog using Ghost on Debian”

My tools on Linux

Update 2016-01-16

Development of Crunchbang has now stopped. There are a few community spin-offs available, Bunsen Labs and Crunchbang++. I’m now using a netinst version of Debian at home with the i3 window manager, and Bunsen Labs on my office laptop. Both are working well. I’m still using the same set of software for my work, in addition to a few more, so this post is still valid.


I’ve been using Linux at home and work for over 5 months now. I’m using a Debian based distribution called Crunchbang. Over these past few months I’ve developed/programmed using multiple technologies and have gathered a collection of tools, that I use on a daily basis.

NameTypeLink
Eclipse with NodeEclipse – Check UpdateIDE for Node.jsLink
NetbeansIDE for PHPLink
DbeaverGUI client for Cassandra and othersLink
MySQL WorkbenchMySQL/MariaDB GUI clientLink
DiaFlowchart and DiagramsLink
SoapUITesting – API and Web ServicesLink
TildaDrop down terminalLink
MeldMergetoolLink
RemminaGTK RDP ClientLink
TomboyNote Taking AppLink
GMTPMTP ClientLink
GIMPImage manipulationLink
Continue reading “My tools on Linux”

Handling JSON request in PHP

I’ve been working with PHP and jQuery AJAX quite a bit lately. Along with sending form data to PHP page through AJAX, I’ve written restful web services in PHP that receive data in JSON format.

In general when you are sending data through jQuery AJAX to PHP, you don’t have to specify a contentType. Depending on your type ‘GET’ or ‘POST’, PHP will nicely wrap your content into either the $_POST or $_GET global arrays. When you don’t specify a contentType the default contentType is taken as application/x-www-form-urlencoded; charset=UTF-8’.

Following is the request headers from an AJAX call without contentType specified,

GET /ajax-php/api.php?firstname=Abijeet&lastname=Patro HTTP/1.1 
Host: localhost:8081 
Connection: keep-alive 
Cache-Control: no-cache Pragma: no-cache 
Accept: */* 
X-Requested-With: XMLHttpRequest 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer:http://localhost:8081/ajax-php/index.php
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8,fr;q=0.6

To further test this, I set up the following PHP code on my server,

<?php
$get=$_GET;
$post=$_POST;
$app_json=json_decode(file_get_contents('php://input');
$response=array();
$response['GET']=$get;
$response['POST']=$post;
$response['JSON']=$app_json;
echo json_encode($response);
die();

The response that for the above request case was,

{
  "GET": {
    "firstname": "Abijeet",
    "lastname": "Patro"
  },
  "POST": [],
  "JSON": null
}

If we put the jQuery AJAX type property as ‘POST’ we will have the following request header,

POST /ajax-php/api.php HTTP/1.1 
Host: localhost:8081 
Connection: keep-alive 
Content-Length: 32 
Cache-Control: no-cache 
Pragma: no-cache 
Origin: http://localhost:8081
X-Requested-With: XMLHttpRequest 
Content-Type: application/x-www-form-urlencoded; 
charset=UTF-8 
Accept: */* 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 
Referer: http://localhost:8081/ajax-php/index.php
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8,fr;q=0.6

Nothing much changes. The action is specified as POST and the data is no longer a part of the request header. The response from the server is following,

{
  "GET": [],
  "POST": {
    "firstname": "Abijeet",
    "lastname": "Patro"
  },
  "JSON": null
}

Obviously, PHP has no issues parsing content of type – application/x-www-form-urlencoded; charset=UTF-8. As soon as it sees that contentType, it checks the action and packs the data nicely into either $_GET or $_POST.

Let’s now talk about JSON data. In general, restful web services accept data of type JSON. When sending data via JSON the contentType for jQuery AJAX is application/json; charset=UTF-8

This is the request header,

POST /ajax-php/api.php HTTP/1.1 
Host: localhost:8081 
Connection: keep-alive 
Content-Length: 42 
Cache-Control: no-cache 
Pragma: no-cache 
Origin: http://localhost:8081
X-Requested-With: XMLHttpRequest 
Content-Type: application/json; charset=UTF-8
Accept: */* 
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36 
Referer: http://localhost:8081/ajax-php/index.php
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8,fr;q=0.6

When PHP receives this data and looks at the content type, it’s not quite sure how to process it, so it leaves it alone. In this case the action – ‘POST’ or ‘GET’ doesn’t matter. You’ll notice that $_POST or $_GET both, are empty arrays. Now, it’s up to you to read this data and parse it.

<?php
$app_json=json_decode(file_get_contents('php://input'));

The code above, reads the data from PHP’s input stream. Since we have passed a JSON string, we decode it, which converts it to a PHP array and stores it in $app_json. If the data you send is not in a correct JSON format, $app_json will have false.

When we echo our response, we get the following on the client side,

{
  "GET": [],
  "POST": [],
  "JSON": {
    "firstname": "Abijeet",
    "lastname": "Patro"
  }
}

I set up a small project to illustrate what has been written here. You can find it over on my GitHub page

Continue reading “Handling JSON request in PHP”