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.
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.
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. 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.
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.
Setting up LAMP Stack (Mysql version 5.6 or later)
Setting up Database and user (CLI and PHPMyAdmin)
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!
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.
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.
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.
9. Click agree and setup. Click next for database settings.
10. Enter the database username , password and database name you have created under MySQL configuration as shown below. Click next after entering the details.
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.
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.