How to find out what application that using specific port

Just a case if you want to know some application or service who is running under specific port :

$ netstat -tulpn | grep :80

Sometimes you need to run with sudo to see all services :

$ sudo netstat -tulpn | grep :80

Output :

tcp        0      0    *               LISTEN      1393/nginx.conf

It turns out that 1393 is the pid of service

Configure php-fpm and nginx to run in low memory server

It was pain in the ass to have php-fpm and nginx together to serve php app, especially when you’re running on low-memory server, especially when you’re running cms like wordpress which basically heavy duty. I had a Centos server running with memory only 1024Mb (1Gb). My web kept crushed every single time. And the problem stil remains, memory leak. I don’t know what the root cause was. I still don’t know what that is but I think it’s something to do with php-fpm configuration or even nginx.

Just several days ago I had my blog up and running with wordpress in the same type of server, same OS (Centos) with the same memory (1Gb) and since I didn’t want to use apache, guess I had to get my nginx and php-fpm working together again. I thought my web would be running very smoothly since the blog was still unlikely to receive much traffic. But I was wrong, somehow the memory was leaked again. My server only running with 1024Mb, but I thought It didn’t matter. The only way to get this problem mitigated is to tune up both the php-fpm and nginx configurations which I never liked this. But I need this, so let’s get this done.

Continue reading “Configure php-fpm and nginx to run in low memory server”

Run Ruby on Rails App for the first time only with nginx

So I’m just lazy, I know there is better way to serve Ruby on Rails with unicorn or uWSGI, but I will try later.

This time I just want a have a quick look how’s the RoR running on the browser only with nginx, just a quick guide, no bullshit. so currently I have rails installed on my ubuntu machine 14.04 with mysql database configured and nginx. So make sure you have those things installed properly to follow this guide.

I usually create my local domain first to navigate it easier:

$ sudo echo -e "\tmyapp.local" >> /etc/hosts

Create the nginx config for your web app :

$ sudo vim /etc/nginx/conf.d/myapp.conf

very simple myapp.conf looks like:

server {
 listen 80;
 server_name www.myapp.local myapp.local;
 charset utf-8;
 access_log /var/log/nginx/myapp.access.log;
 error_log /var/log/nginx/myapp.error.log;
 location / {

Check nginx config and restart

$ sudo nginx -t
$ sudo service nginx restart

Run the rails (I told you, I’m just lazy) :

$ cd /myapp
$ rails server &

And now, Rails is running with port 3000 which nginx already addressed to myapp.local domain. Open up the browser and navigate to http://myapp.local

Setup Ruby On Rails on Ubuntu 14.04 Trusty Tahr

I’m sick of people who write tutorials which is not clear to install the Rails, too long, too much multiple choice, rambling. This is tutorial that actually works for me. Hope it would work for you too.

Install some dependencies first

$ sudo apt-get update
$ sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs

And we install the ruby, the current new version when this post is written is ruby 2.4.1, you might want to change with the newer version if available.

$ wget
$ tar xzvf ruby-2.4.1.tar.gz
$ cd ruby-2.4.1
$ ./configure
$ make
$ sudo make install

Check the ruby version

$ ruby -v

Install bundler and Rails with gem

$ sudo gem install bundler
$ sudo gem install rails

Check the Rails version

$ rails -v

Create new app

$ rails new my_new_app