Categories
Tips & Tricks

Copy the SSH Key from Macbook Pro

As an enthusiastic developer, there are times when I need to collaborate with other people on projects that hosted in a central repository such as GitHub, Bit Bucket, or Gitlab.

Without the need to always type in the password on push, I need to add my SSH Key to that repository the enable it to recognize my development machine. In my case, I use mac.

Generating the key

In case you’re on a brand new Macbook and which has not yet generated a key before. To generate, open the terminal and run the following command:

ssh-keygen -t rsa -b 4096

Hit enter to accept the default location. Then once it prompts you to enter a passphrase, enter it or leave it blank to never require a passphrase on committing to the remote repository.

The next step is to copy the key and use it at your repository’s account profile.

Copying the key

Open the terminal and run the following command:

pbcopy < ~/.ssh/id_rsa.pub
Categories
Tips & Tricks

Using rsync to Upload Large Files to the Remote Server

I once met a situation when I could not upload a large compressed css file to the remote server via any ftp softwares either FileZilla or Cyber Duck.

I could not figure out why even I’d tried to increase timeout setting, reduce the number of connection, etc. still it ends up the same.

Then I decided to transfer the file via SCP. But it was too slow as SCP always verifies its credentials at every connection established.

The other possible method is to use rsync upon this recommendation.

The syntax is simple:

rsync -avzh style.css vkhost@192.168.1.254:/home/vkhost

Where /home/vkhost is the destination directory to have my style.css file moved to. It was done in just a blink of an eye for the file over 175kb.

Using rsync to Upload Large Files to the Remote Server
Categories
Tips & Tricks

Fixed: Corrupt SQL file contains unicode characters

I happened to have my backup sql file which contains Unicode characters broken. This happened when I had just bought a new version of Mamp Pro to install in my Mac. It comes with the latest PHP and a lot of exiting features!

I then re-installed my database of one project that contains Unicode characters. Unfortunately, it shows strange characters like below:

It’s a double converted character. To fix it, simply:

  1. Convert back to latin1
  2. Convert to binary
  3. Convert to utf8

So, go to the SQL tab of the phpMyAdmin, and run the following command:

alter table table_name modify field_name VARCHAR(2000) character set latin1;
alter table table_name modify field_name blob;
alter table table_name modify field_name VARCHAR(2000) character set utf8;

Then the unicode character will be back.

Categories
Tips & Tricks

Using Bootstrap 4.3.1 and Error Occurs When Triggering compass watch

Playing around with Twitter Bootstrap 4.3.1 is fun!

Initially, when triggering the compass watch from my terminal the error occurs like below:

error sass/bootstrap/bootstrap.scss (Line 4 of sass/bootstrap/_root.scss: Invalid CSS after "...lor}: #{$value}": expected "{", was ";")

The fix is simple. First, reinstall sass and compass to the latest version:

gem uninstall sass
gem uninstall compass
gem install sass
gem install compass

Then go to the _root.scss file in your bootstrap folder, and change the following codes:

@each $color, $value in $colors {
--#{$color}: #{$value};
}
@each $color, $value in $theme-colors {
--#{$color}: #{$value};
}
@each $bp, $value in $grid-breakpoints {
--breakpoint-#{$bp}: #{$value};
}

To:

@each $color, $value in $colors {
#{--#{$color}}: #{$value};
}
@each $color, $value in $theme-colors {
#{--#{$color}}: #{$value};
}
@each $bp, $value in $grid-breakpoints {
#{--breakpoint-#{$bp}}: #{$value};
}

Run compass watch again and the error goes away. Cheers!

Categories
Tips & Tricks

Delete content of a file using Truncate

There are times when we need to remove content from a file from our server space. Especially, those unwanted log content which are produced on the fly by your codes on purpose.

To my experience, some logs that are already checked should be deleted to save server space.

Note that when the log file exceeds the maximum file size defined in the configuration, it created another new one and rename the previous one to be something like domain.com.error.log.1, domain.com.error.log.2, and so on.

To remove those backup logs, just excecute the command

rm domain.com.error.log.*

To delete the content of the domain.com.error.log file, run the following command:

truncate -s 0 domain.com.error.log
Categories
Vesta

Upgrade PHP to 7.2 on Vesta CP

This morning I’m working on upgrading my Vesta CP to use PHP 7.2 as from the newly released WordPress 5.1 suggestion.

1. Add PHP Repository to my Debian

In my case, my Ubuntu operating system does not have PHP Repository yet. I then install it by running the following command:

sudo apt-get install software-properties-common

Then go add the PHP repository by running the following command:

sudo add-apt-repository ppa:ondrej/php

After that I need to make sure this repository is available on my call. I then run the following command:

sudo apt-get update

2. Install PHP 7.2

Now everything needed is available on the server. Installing PHP 7.2 by running:

sudo apt-get install php7.2

3. Tell Apache to use PHP 7.2

The Apache server is still using the previous version of PHP unless I disable the previous one and enable the 7.2 version.

To disable the previous PHP version, in my case, PHP 5, run:

sudo a2dismod php5 

To enable the newest version of the installed PHP, run:

sudo a2enmod php7.2

To get the change affected, restart the apache server:

sudo service apache2 restart

4. Installing Extensions

There are extensions that might be needed to replace the deprecated ones or required by PHP 7.2. The following extensions are some that may fix your need:

sudo apt-get install php7.2-common libapache2-mod-php2.1 php2.1-cgi php7.2-cli php7.2-phpdbg php7.2-fpm libphp7.2-embed php7.2-dev php7.2-curl php7.2-gd php7.2-imap php7.2-interbase php7.2-intl php7.2-ldap php7.2-mcrypt php7.2-readline php7.2-odbc php7.2-pgsql php7.2-pspell php7.2-recode php7.2-tidy php7.2-xmlrpc php7.2-json php-all-dev php7.2-sybase php7.2-sqlite3 php7.2-mysql php7.2-opcache php7.2-bz2 libapache2-mod-php7.2 php7.2-mbstring php7.2-pdo php7.2-dom phpize7.2

To get these extensions up and running, restart the apache:

sudo service apache2 restart

5. Fixing Errors After Upgrading to 7.2

In my case, I got an error saying “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”

As per it says, the MySQL extension is missing. To fix, go install it:

sudo apt-get install php-mysql

Then restart Apache:

sudo service apache2 restart

I also met the CURL error too when hitting save a post on WordPress. To fix, simply install the CURL extension and restart apache

Install CURL extension:

sudo apt-get install php7.2-curl

Restart Apache:

sudo service apache2 restart

Install Image Magic

sudo apt-get install php-imagick

Restart Apache:

sudo service apache2 restart

6. Known unsupported WordPress plugins

There are a few PHP warning errors of some WordPress plugins after upgrading PHP to version 7.2.

In this time of writing, those plugins are:

  1. All Push Notifications
  2. Facebook Instant Articles
  3. JetPack

Read more tips on migrating from PHP 5 to PHP 7 part 1 and Part 2

Categories
Tips & Tricks

Setup Static IP on Ubuntu 18.04 Server

I was playing around with setting up my own Ubuntu server for an intranet system to use within the company.

Everything works out of the box, almost like Windows ;). The thing that I think would be very much useful in the future is to set a static IP so that even if the server is moved or changed within the network, everyone can still access to the it without changing the IP.

To do so, go to /etc/netplan and you’ll find a file called 50-cloud-init.yaml (the file name might be different in your server). Edit it to match the following setting:

#This file is generated from information provided by
#the datasource. Changes to it will not persist across an instance.
#To disable cloud-init's network configuration capabilities, write a file
#/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
#network: {config: disabled}

network:
renderer: networkd
ethernets:
eno1:
addresses: [xxx.xxx.xxx.xxx/nn]
dhcp4: no
gateway4: xxx.xxx.xxx.1
optional: true
nameservers:
addresses: [xxx.xxx.xxx.xxx]
eno2:
addresses: []
dhcp4: true
version: 2

Save and type the following command: suo netplan --debug apply

Categories
Tips & Tricks

Change VestaCP admin Password

There are times when you are not able to log back in to the VestaCP as of your admin account. However, you still can login using normal user accounts. To fix this, try the following solution:

  1. Log in to the server via SSH
  2. run the following command: $v-change-user-password USER NEWPASSWORD // where USER is admin and NEWPASSWORD is the password you want
  3. Login back to your VestaCP pannel using the username: admin and password: YOUR NEW PASSWORD

Categories
Tips & Tricks

WordPress: All Pages Redirect to 404

If the .htaccess configuration is correct it means we haven’t enabled the apache2 rewite mod.

To enable, simply run the command below:

sudo a2enmod rewrite

Then

systemctl restart apache2

It works!

Categories
Tips & Tricks

Fixed – Cross-Origin Resource Sharing Error with Origin on Amazon CloudFront

Amazon Cloud Front is one of the AWS features which is popular among other CDNs. Configuring Amazon Cloud Front into WordPress website is easier with a plugin called W3 Total Cache.

However, most of the time, there is an error happened during the negotiation between the website, origin, and the S3 bucket using this plugin.

No ‘Access-Control-Allow-Origin’ header error is blocked by Amazon Cloud Front

To fix this, simply follow the following instructions:

  1. Change “Forward Headers” from “None” to “Whitelist”
  2. Add “Origin” to the “Whitelist Headers”
  3. Make sure that “Use Origin Cache Headers” is checked
  4. Invalidate the cached fonts

Read https://knackforge.com/blog/font-awesome-woff2-failing-load-amazon-cloudfront

https://www.naschenweng.info/2014/09/23/wordpress-w3-total-cache-cloudfront-font-cors-issue/

http://blog.celingest.com/en/2014/10/02/tutorial-using-cors-with-cloudfront-and-s3/