Linux Command Line Tips for Increasing Productivity

Linux Command Line Tips For Increasing Productivity

When it comes to Linux, most of the time you would be working on the command line. With the advent of configuration management tools like Chef, Ansible etc, developers can now work on Linux system automation efficiently without worrying much about the system internals. However, working with the command line is required at any state of the process. Let it be debugging, editing a configuration or testing an application for the first time. Linux command line tips will increase your productivity. You can avoid lots of repeated tasks using these tips and shortcuts.

Linux Command Line Tips

In this article, we have listed out the command hacks that you could use in a Linux terminal for increasing your productivity.

Note: In all the examples explained below, “+” means just the combination. It does not mean you have to use the “+” button in keyboard.

Search Previously Executed Command

You can search for a previously executed command using the reverse search functionality.

Use “Ctrl + R” button and type the keyword to search. It will return the matching command executed before.

Delete the last Word and Line

When you are typing,

1. If you want to delete the last word, use “Ctrl + W
2. If you want to delete the whole line, use “Ctrl + U
3. If you want to enter next line, use “Ctrl + C

Also read: Linux networking and troubleshooting commands

Find and kill and process

Let’s say you want to find a process id and kill it. You can do this using the following command.

ps -aef | grep <service name>  | grep -v grep | awk '{print $2}' | xargs kill -9

List out all process and Listening ports

Use the following command to list all the listing ports.

netstat -tlnp

Process related

1. Use pgrep to get the process id of a service.

pgrep <service name>

And you can use xargs to kill all the related processes.

pgrep <service name>  | xargs kill -9

2. User nohup and & to send a process to the background and run forever.

nohup <some process script> &

Output as file Input

You can use the output of a command as a file to be the input of another command using “<” symbol.

For example, if you want to compare the /etc/hosts of a remote host with your current host, you can do the following.

diff /etc/hosts <(ssh [email protected]<IP> -i ~/.ssh/key-file cat /etc/hosts)

Suppress the standard output

If you want to suppress the standard output, you can redirect the stdout to /dev/null

For example,

ls -l > /dev/null

File Permissions in Octal form

To view the file permissions in octal form, you can use the following syntax.

stat -c '%A %a %n' <file name>

disk/CPU/network status

To know disk/CPU/network status you could use the following command line utilities.

iostat
netstat
top
htop
dstat
vmstat

Other useful Tips

1. Use Ctrl + Z to suspend a process

2. Use grep for filtering outputs

3. Use !! to execute the last command

4. Use dmesg command to identify hardware or driver problems

5. Use the mtr command to troubleshoot network issues.

6. To empty a file use >  followed by the filename. For example >example.txt 

For example,

mtr 8.8.8.8

6. Use pstree command to view the process tree of your system.

Useful Links

1. Linux process management tutorial for beginners.

2. Linux commands every developer should know.

Linux Command Line Tips For Increasing Productivity

How to Migrate WordPress Site to Digital Ocean Cloud Server

migrate wordpress to digital ocean

Devopscube was initially hosted on Bluehost. Due to increased traffic, the website performance in terms of load time from Bluehost was not up to the mark.  So we moved our website to Digital Ocean cloud hosting which has a drastic difference in site performance and site load time.

If you cannot manage your server, Bluehost or Hostgator would be a better option for hosting your blog in a cost effective manner. In Digital ocean, you need to take care of WordPress setup, security, server patch updates and more. If you a are looking for a good VPS solution, Digital Ocean will be a better option.

Note: If you sign up for Digital Ocean Using this link, you will get a free $10 credit.

Migrate WordPress Site to Digital Ocean

In this article, we have shared a small guide for to migrate WordPress site to Digital Ocen droplet.

Backing Up WordPress files From Current Hosting Provider

You need to backup and get the following data .

1. MySQL file. This you can get it from the PHPMyAdmin page of your existing hosting.
2. Complete wp-content content folder from current hosting.
3. If you added custom rules in the .htaccess file, backup and download the same.

Setting Up Digital Ocean Server

1. Launch the droplet using one click WordPress ubuntu 14.04 image.

2. Log into the server using ssh. Note down the details in the welcome message.

3. Update the server

sudo apt-get update -y

5. In the welcome page, you can see all the default Mysql and PhP details (Default mysql root password, php.ini location etc). You can also view it using the following command.

cat /etc/motd.tail

Chane the default MySQL root password using the following command.

mysql_secure_installation

Setup PHPMyadmin

PHPMyadmin makes it easy to import the database and manage new users.

1. Install PHPMyadmin

sudo apt-get install phpmyadmin

2. Enable php mcrypt.

sudo php5enmod mcrypt

3. Open /etc/php5/apache2/php.ini file and increase the file_upload_limit and post_max_size parameter to 50MB or more depending on your SQL file size.

3. Restart apache server.

sudo service apache2 restart

Create database, user, and import the database

Create a new database and a database user using PHPMyadmin page. Make user you give all the privileges to the new user to the database you create.

You can also create database and user using MySQL CLI with the commands given below. Change the database name, user name and password accordingly.

mysql -u root -p
CREATE DATABASE devopscube_db;
CREATE USER [email protected] IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON devopscube_db.* TO [email protected] IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit

After this, head over to PHPMyAdmin page and log in with your DB credentials.

1. Now select the created database and click the import option.

2. Upload the SQL backup file you downloaded from your current hosting provider and click import. This will import all your WordPress data.

Upload wp-content folder

1. Upload the wp-content backup folder to Digital ocean droplet using SCP or a tool like FileZilla.

2. Replace the default wp-content droplet folder with your wp-content folder in /var/www/html folder.

3. Change the wp-content folder owner to www-data

sudo chown -R www-data:www-data /var/www/html/wp-content

3. Open wp-config.php file and change the database, database user, and password. Also, check the table prefix parameter. If your existing table prefix it is other than wp_, change it in the wp-config.php file.

Map the IP to Domain Name

1. Copy the droplet public IP from Digital ocean panel.

2. Open the DNS zone editor of your domain name from your domain name provider and update the A record to digital ocean IP.

It will take few minutes to hours for the DNS update. Once the DNS update happens, Digital Ocean droplet will start serving your website.

migrate wordpress to digital ocean

Title: How To Setup and Configure Latest Magento 2.x On Linux EC2

installing and configuring latest magento 2 on linux

This guide explains the steps to install and configure latest Magento 2.x on a Linux ec2 cloud server or a VPS. We will be doing the following.

  1. Setting up LAMP Stack (Mysql version 5.6 or later)
  2. Setting up Database and user (CLI and PHPMyAdmin)
  3. Setting up Magento 2.0 using composer.

I am using an Ubuntu 14.04 LTS server from Amazon ec2. This tutorial will work on any cloud or VPS having a Ubuntu server.

Setup LAMP Stack

1. Update the Server

sudo apt-get update -y

2. Install apache

sudo apt-get install apache2

3. Install MySQL server and the PHP module for MySQL. During installation, MySQL would prompt for the password for the root user. Set a strong password.

sudo apt-get install mysql-server-5.6 php5-mysql

4. Create MySQL database directory using the following command.

sudo mysql_install_db

5. Run the MySQL secure installation command.

sudo mysql_secure_installation

The above command would prompt for the root password. Enter the root password and proceed with the options given in the output below.

Enter current password for root (enter for none):

Change the root password? [Y/n] n
 ... skipping.

Remove anonymous users? [Y/n] y
 ... Success!

Disallow root login remotely? [Y/n] y
 ... Success!

Remove test database and access to it? [Y/n] y

Reload privilege tables now? [Y/n] y
 ... Success!

6. Install PHP.

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

7. Open /etc/apache2/mods-enabled/dir.conf file using vi or nano editor.

 sudo vi /etc/apache2/mods-enabled/dir.conf

The file would look like the following.

    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm

Move index.php to first so that the file would look like the following.

    DirectoryIndex index.php index.html index.cgi index.pl i index.xhtml index.htm

8. Restart apache server.

sudo service apache2 restart

9. To know all the PHP details, create a file named info.php

sudo vi /var/www/html/info.php

Copy the following contents on the info.php file.

<?php
phpinfo();
?>

Now, if you browse to http://<Server-IP>/php.info, you will be able to see all the PHP configuration details.

Install and Configure PhpMyAdmin

PhpMyAdmin is a great utility for managing databases through GUI. Follow the steps carefully for setting up PhpMyAdmin.

1. Install PhpMyAdmin

sudo apt-get install phpmyadmin -y

When it prompts for web server, press space bar and select apache2 and press enter. For Configure database for PHPMyAdmin, press enter. Password of the database’s administrative user, enter the root password for MySQL that you created during MySQL installation. Enter the same password for confirmation.

2. Enable PHP mcrypt module.

sudo php5enmod mcrypt

3. Restart the web server.

sudo service apache2 restart

Now you can access the PhpMyAdmin Web UI by visiting the ec2 public IP address followed by PHPMyAdmin as shown below.

http://<server-IP>phpmyadmin

You can use the MySQL root credentials to log in to PHPMyAdmin account.

Create Magento User and Database

You can create MySQL user and Database using the command line as well through PhpMyAdmin. Using PHPMyAdmin is self-explanatory. If you want to use the command line for creating the user and database, you can follow the steps given below.

1. Sign into MySQL client using the root user and password.

mysql -u root -p

2. Create database Magento.

CREATE DATABASE magento;

3. Create a magento_admin with a strong password. Replace “password” with your strong password.

CREATE USER [email protected] IDENTIFIED BY 'password';

4. Grant all privileges to magento_admin for Magento database. Replace password accordingly.

GRANT ALL PRIVILEGES ON magento.* TO [email protected] IDENTIFIED BY 'password';

5. Flush all the privileges and exit the MySQL CLI.

FLUSH PRIVILEGES;
exit

Setting up Magento

In this section, we will configure Magento using LAMP stack. Follow the steps carefully.

1. Create a file called magento.conf in the apache sites available folder.

sudo vi /etc/apache2/sites-available/magento.conf

Copy the following content on the file.

<VirtualHost *:80>
 DocumentRoot /var/www/html
 <Directory /var/www/html/>
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 </Directory>
</VirtualHost>

2. Enable our new conf and disable the default conf using the following commands.

sudo a2ensite magento.conf
sudo a2dissite 000-default.conf

3. Reload the apache service.

sudo service apache2 reload

4. Open php.ini file to increase the memory_limit parameter to 512M (default 128M).

sudo vi /etc/php5/apache2/php.ini

Find memory_limit parameter and set it to 512M and save the file.

memory_limit = 512M

5. Install required PHP modules for Magento.

sudo apt-get -y install libcurl3 php5-curl php5-gd php5-mcrypt php5-intl php5-xsl

6. Enable rewrite, mcrypt module and restart the apache server.

sudo a2enmod rewrite
sudo php5enmod mcrypt
sudo service apache2 restart

Setup Magento 2.X

1. Install Composer.

curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

2. Create a Magento marketplace account and get public and private access keys from your account. Refer this link for getting the public and private keys

3. Create an auth.json file

sudo vi /root/.composer/auth.json

Copy the following content on to the file with your public and private key.

{
"http-basic": {
      "repo.magento.com": {
         "username": "edd45269f04a6ca51cbbbed2fedab26b",
         "password": "ef88687a5cf5d109c5540ff401b0b903"
      }
   }
}

4. Get the latest Magento binaries using git.

If you don’t have git installed, install it using the following command.

sudo apt-get install git -y

Clone the magento2 community version code to Magento directory.

git clone -b 2.0 https://github.com/magento/magento2.git magento

5. Copy all files to /var/www/html directory using rysync.

sudo rsync -avP magento/. /var/www/html/

6. CD into /var/www/html folder and install all the required Magento modules using composer.

cd /var/www/html
composer install

7. Change the owner of /var/www/html to www-data.

sudo chown -R www-data:www-data /var/www/html/

8. Visit the public IP of your server. You will see the Magento setup page as shown below.

magento initial setup

 

9. Click agree and setup. Click next for database settings.

magento 2 initial setup

 

10. Enter the database username , password and database name you have created under MySQL configuration as shown below. Click next after entering the details.

magento database configuration

 

11. Next page, you can see the store and admin page address. You can customize the admin age path. If you have a domain name, you can map the domain name to the IP address.

magento 2 admin url confirations

 

From this point, you can click next and fill in the details. In the last page, click “Install” option. Once installed, you will get all the details of your Magento site as shown below.

 

magento final installtion

installing and configuring latest magento 2 on linux