Connect Google Cloud SQL from Local Machine using Unix Socket

Published at February 22nd, 2017 in Cloud Computing, Cloud Server

Firstly,
You need to install Google Cloud SDK and check if you have gcloud command available in terminal. After installing gcloud you need to configure gcloud sdk by running gcloud init command.

Secondly,
I am assuming, you have configured your Google Cloud SQL instance for your project. If yes, then continue, otherwise you need to read “Google Cloud SQL Quickstarter Guide“.

Now Download cloud_sql_proxy.linux.amd64 package in your local machine with

"sudo wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64"

this command.

Thirdly,
Rename by mv cloud_sql_proxy.linux.amd64 cloud_sql_proxy
and give execution permission by chmod +x cloud_sql_proxy

Fourth,
Create application default credentials using “gcloud auth application-default login” command

Fifth,
Create a directory sudo mkdir -p /cloudsql for Google Cloud SQL proxy unix socket and make that directory writable sudo chmod 777 /cloudsql

Sixth,
start sql socket proxy by ./cloud_sql_proxy -dir=/cloudsql &

At last,
Now you can have working mysql DSN “mysql:unix_socket=/cloudsql/INSTANCE_CONNECTION_NAME” which you can use in your application and your application will work with Google Cloud SQL instance directly from local machine.

Please ask me anything about this post in comment below. I will be glad to assist you happily.

 

Get ThemeForest theme information and stats with simple PHP script

Published at October 14th, 2016 in PHP, programming

Now a days, lots of professionals are selling their creative works on ThemeForest. I just created the following simple (very simple) PHP script that works with HTML DOM and XPATH will do a very interesting job to show the ThemeForest theme information and statistics.

Just run this script on your PHP environment and you will get the following information of any specific ThemeForest theme.


Array
(
 [sellCount] => 2
 [price] => $16
 [created] => 2016-10-13
 [lastUpdated] => 2016-10-13
 [highResolution] => No
 [compatibleBrowsers] => IE10,IE11,Firefox,Safari,Opera,Chrome,Edge
 [filesIncluded] => HTMLFiles,CSSFiles,JSFiles
 [columns] => 1
 [documentation] => Unrated
 [layout] => Responsive
 [totalComment] => 8
)

WHMCS PHP API – Integrate billing system with your application

Published at August 29th, 2016 in PHP

WHMCS is a popular billing system specially for domain+hosting business. It provides mostly billing solutions. You can download WHMCS from download page. As a billing system, if you have several tools, utilities and services that require connection between your application and WHMCS then you badly need API to accomplish that interconnection.

WHMCS has a very basic API documentation (it’s enough though) without any specific programming library. You can use the following wrapper class to interact with your WHMCS system from your PHP application. This is very simple and doesn’t require further explanation in depth. See the following script. If you have any better idea or suggestions, don’t forget to write me in the comment area.

Stop and Remove all docker containers and images

Published at July 11th, 2016 in Cloud Computing

Some important commands for Docker containers and images. It’s useful for delete all docker containers and images altogether at once.


# Stop all docker containers
docker stop $(docker ps -a -q)

#Remove all docker containers
docker rm $(docker ps -a -q)

# Delete all images
docker rmi $(docker images -q)

Create NodeJS – ExpressJS static file server in a minute

Published at July 4th, 2016 in AngularJS, ExpressJS, NodeJS

It’s pretty straight-forward tutorial for anybody to understand. Suppose, you want to run your AngularJS static application in your local PC with pretty URLs and other features. You may need to create a stand-alone static file server.

So here you can do that with NodeJS and Express.

– Just create a package.json file in your application root. and write the following json configuration there.


{
  "scripts": {
    "server": "node static-server.js"
  },
  "dependencies": {
    "express": "^4.14.0",
    "node-static": "^0.7.7",
    "path": "^0.12.7"
  }
}

And after that create a JS file name ‘static-server.js’ with the following code where ExpressJS will serve you static files.


var express = require('express');
var app = express();

app.use(express.static(__dirname + '/public'));

app.get('*', function(request, response, next) {
    //__dirname + '/public' is your main file location of a
    response.sendfile(__dirname + '/public');

    //if you want to run AngularJS app with html5Mode(true) 
    //then you have to run server via index.html
    //response.sendfile(__dirname + '/public' + '/index.html');  
    //Write your own angularJS index file location
});

app.listen(8081, function(){
    console.log('Starting server at http://localhost:8081')
});

Now you are all set. Now install all nodejs dependency libraries by npm install command and then run ‘npm run server’ command to start your static server. After successfully started (can see in console) you can visit your static web server from http://localhost:8081 (you can change port as your wish). I think this will help you and your team.

Pages »