Useful Linux commands for beginners

If you are switching from Windows to Linux based operating system, then it might be difficult in early days to get hang of it. Here are some commands that will be useful.

  1. If you want to find out size of current directory, just type

2. Check your disk usage

3. See all files and directory size in current path

4. Truncate log files

5. List content of a directory using ls command

6. If you want to know about a command, you can take of man command, for example if you want to go into details of ls command, just type

It will give you an output something similar to this

 

I will be updating this with more useful commands as and when I found.

Thanks

Transfer ownership of a Digital Ocean Droplet

I run a web development agency and most of the time it happens that we create servers for client in our own Digital Ocean account during the development phase.  When project gets over we usually transfer the ownership of the droplet to client. I have seen Digital Ocean customers
struggling with the transfer of ownership of droplet.

So here is I am giving a simple step by step guide to transfer a droplet from one Digital Ocean account to another.

Step 1: Take a snapshot of droplet

We need to first take a snapshot of the droplet that you want to transfer. You can either take a live snapshot which doesn’t require shutting down the droplet or to avoid any data loss just power off the droplet before taking snapshot. You can power off the droplet from the control panel or by logging into server through ssh.

Enter the name of snapshot and click on “Take Snapshot” button.

DO Snapshot

DO Snapshot

Step 2: Enter recipient owner digital account email address

Once the snapshot is ready, click on “Change Owner” option. It will prompt to enter recipient email address. Enter the address of the account to which you want to transfer the droplet.

Step 3: Accept snapshot transfer

Now log into the control panel of the recipient account. Go to Images and then Snapshots. You will see the snapshot that you had transferred to this account. Click on Accept to complete the transfer process.

Step 4: Create a new droplet from snapshot

Since we have the snapshot with us now, we need to create a droplet from this snapshot. To Click on “Create Droplet” option from menu and select the appropriate plan for your droplet, and your droplet is ready!

Install COMODO Postive SSL certificate on Ubuntu

Comodo offers a wide range of SSL certificates to suit a diverse range of business requirements and budgets.

Follow below steps to install comodo positive ssl certificate on your ubuntu server.

Step 1 –  Before applying for a certificate we need to submit Certificate Signing Request (CSR)  to Certificate Authority (CA). Run below command on your server

* replace example_com with your domain name if you want to

It will ask following details

  • Organization Name
  • Organizational Unit
  • Country Code
  • State / Province
  • Locality
  • Common Name – This is the domain name for which you want to purchase SSL certificate

After providing above mentioned details this command will create two files

  • example_com.key – Your private key which you need to configure Apache or Nginx
  • example_com.csr – CSR

Step 2 – Apply for the certificate and provide content of CSR file

Step 3 – After submitting CSR, CA will send you an email on email selected by you. You should get your SSL certificate after verifying your domain.

Your certificate zip file will contain

example_com.crt  – Your ssl certificate
AddTrustExternalCARoot.crt – Root CA certificate
COMODORSAAddTrustCA.crt  – Intermediate CA certificate
COMODORSADomainValidationSecureServerCA.crt  – Intermediate CA certificate

Step 4 – Create a bundle of all crt files

Step 5 – Configuring Apache web server to serve website over HTTPS


Step 6 (Optional) – Configure Nginx to serve website over HTTPS

Install or update nodejs usin NVM in Ubuntu

Node JS is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event driven, non-blocking I/O model that makes it lightweight and efficient
 Using nvmNVM, which stands for “Node.js version manager” we can install multiple versions of nodejs on Ubuntu.

To install or update nvm, you can use the install script using cURL: ( You can find the installation instructions on projects github page https://github.com/creationix/nvm/blob/master/README.md)


or using Wget:


Run the script by running 


To get the list of available Node.js versions

React Native Issues

Recently I started learning React Native to build native mobile applications using React JS. I faced lots of issues while making my first application run on my Ubuntu desktop. Here I am recording issues I faced and the solutions that worked for me, so that beginners like me don’t have to reinvent the wheel.

A problem occurred configuring project ‘:app’.
> SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
  1. Go to your React native Project -> Android
  2. Create a file local.properties
  3. Open the file
  4. paste your Android SDK path like below
    • in Windows sdk.dir = C:/Users/USERNAME/AppData/Local/Android/sdk
    • in macOS sdk.dir = /Users/USERNAME/Library/Android/sdk
    • in linux sdk.dir = /home/USERNAME/Android/Sdk

Replace USERNAME with your user name

Now, Run react-native run-android in your terminal
ENOENT: no such file or directory, open ‘android/app/src/main/assets/index.android.bundle’
Manually create this directory
mkdir android/app/src/main/assets
Unable to load script from assets index.android.bundle
  1. (in project directory) mkdir android/app/src/main/assets
  2. react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  3. react-native run-android

ou can automate the above steps by placing them in scripts part of package.json like this:

Ref: https://stackoverflow.com/questions/44446523/unable-to-load-script-from-assets-index-android-bundle-on-windows

 

Then you can just execute npm run android-linux from your command line every time.

I will keep updating this as and when I encounter new issues with solutions that worked for me.

Convert GMT to Local timezone in PHP

Following code snippet converts a date time in GMT to Local timezone.

 

mysql table is marked as crashed and last (automatic?) repair failed

If you are getting this error

mysql table is marked as crashed and last (automatic?) repair failed

Go to your data folder and try running

You should stop MySQL process first. If that doesn’t work, you can try with

I had to navigate to /var/lib/mysql/<database> and run myisamchk -r -v -f ./<table name>.

PS – This was answered at following thread, this post is for just personal reference in future.

Reference – http://stackoverflow.com/questions/8843776/mysql-table-is-marked-as-crashed-and-last-automatic-repair-failed

Requires Doctrine DBAL Laravel migration

If you are running a migration to change the data type of a column in a table. You might come across this error message in terminal.

This error message is telling you to install doctrine/dbal to make this work. You can learn more about this package here https://github.com/doctrine/dbal

To install this package through composer, run following command in terminal.

Now you can run your migration by running

This should work now.

npm install – Please try running this command again as root/Administrator

If you are getting this error while running npm install, then you are not having write permission on .npm directory.

To get the ownership of this directory run following command

Also we need to give write permission to node_modules directory

ref – http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo