Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Wednesday, September 27, 2017

Ubuntu Keep Process Running After SSH is Terminated

Hello,

Recently I was learning NodeJS and for that I faced an issue with node server. I installed node server via SSH and started server. But as soon as I closed terminal Node server stopped working. But I needed server up and running even if terminal is closed. So after struggle of sometime I found out solution. Here is what we have to do.

Basically when you type command on SSH and start server it runs on the foreground and wait for process to be finished. So as soon as you close terminal foreground process is also terminated and hence your server is stopped.

So in this case you have to run server as background process and if you are using ubuntu you can use nohup  and & to start running process in background hence it will not be terminated once the terminal is closed.

So here is the command you have to follow.

$ nohup "COMMAND" &

Here COMMAND is your command to start the server and since you have mentioned nohup and & it will run the process in background and will not be terminated when SSH is closed.

Wednesday, May 31, 2017

Amazon EC2 Create Swap Space

Hello,

Recently in one of my project we have laravel application deployed on amazon ec2 instance. When running composer update command, we were facing issue of swap space as it was not defined. So in this blog I will explain how you can create swap space in your amazon ec2 instance. Please note these steps are specifically for ubuntu instance. If you are running other version of liunx, please check commands first and then use it.

1) Create swap file

sudo fallocate -l 1G /swapfile

2) Verify it

ls -lh /swapfile

It should show following output.

-rw-r--r-- 1 root root 1.0G Apr 25 11:14 /swapfile

3) Enable it and make it accessible by only root user.

sudo chmod 600 /swapfile

sudo mkswap /swapfile

sudo swapon /swapfile

That's it now you have swap space configured in your instance. 

Wednesday, May 24, 2017

How to exit the Vim editor?

Every time I use vi editor on terminal in OSX or Linux, I face issue on exiting Vim editor on terminal. So in this blog I am going to explain complete procedure on exiting vim editor on terminal in OSX or Linux.

What is Vim editor?

Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple OS X.

How to Use Vim on Terminal?

Go to terminal and type following command

vi "NameOfFile"

and it will open Vim editor like this.



This is blank file. To start editing file press "I" key and then you can start editing file.

Now the tricky part is exiting vim editor on terminal. Here are exact procedure.

Hit the Esc key, vim goes into command mode.

Type Shift key + : and you will see : at bottom of the file.

Now you have to type command to tell editor what you want to do with the file. Here are some options you have.

q to quit
q! to quit without saving
wq to write and quit
wq! to write and quit even if file has only read permission
x to write and quit
qa to quit all
Now press "Return key" and it will exit vim editor.

Sunday, January 8, 2017

.htaccess Doesn't Work in Amazon AWS EC2 Instance with Ubuntu

Recently I was configuring Laravel application in Amazon AWS EC2 instance which was having Ubuntu and Apache installed. The problem was htacess file was not working so Laravel routes were not working. Instead of parsing laravel routes it always shows error URL not found.

The problem is by default in apache installed on ubuntu doesn't have .htaccess enabled so first you have to manually enable it in config file and restart apache.

Here are the steps.

1) Login to your EC2 instance with SSH.

ssh -i "Yourkey.pem" ubuntu@yourpublicip

2) Enable Mode Rewrite, this is just incase if it's not enabled.

sudo a2enmod rewrite

3) Go to following directory.

cd /etc/apache2/sites-available

If you use LS command here you will see following file.

000-default.conf

That's the file with default apache configuration which are applied to your sites in /var/www/html folder.

4) Open this file for editing.

sudo nano 000-default.conf

5) Add following lines after DocumentRoot /var/www/html line.

<Directory />
     Options FollowSymLinks
     AllowOverride All
</Directory>
<Directory /var/www/html>
     Options Indexes FollowSymLinks MultiViews
     AllowOverride All
     Order allow,deny
     allow from all
</Directory>

6) Save the file and restart the apache.

sudo service apache2 restart

that's it and now your .htaccess file will work and your laravel application will start working.