Using SFTP to Move Files to or from a Remote Server

I have a couple of AWS instances running for class and regularly need to move files back and forth to the server from my local machine. I was initially using scp for this task, but navigating the file system on the remote machine was onerous and unwieldy. Enter SFTP….

SSH File Transfer Protocol is a secure way to move files between two machines using the SSH protocol to authenticate.

I already had a private key file set up to access my instance via SSH, and the connection command is very similar:

sftp -i name_of_your_keyfile.pem user@your_hostname

The -i parameter indicates that you are using a key file. Replace the generic placeholders with your information.

Once you are connected your prompt will change to sftp>.

Many of the available commands will be familiar, if you are used to navigating a Linux file system via a terminal:

CommandDescription
lsList contents of remote working directory
llsList the contents of the local working directory
pwd Displays the name of the local working directory
cd Changes the remote working directory
lcdChanges the local working directory
getCopies a file from the remote directory to the local directory
putCopies a file form the local directory to the remote directory
deletedeletes a file from the remote working directory

To get a complete list of commands you can type help or ?

Correcting High Volume Issue in Ubuntu

I use Ubuntu on a Lenovo ThinkPad as my primary development machine. I was experiencing an issue with volume control where the volume was consistently loud and lowering it would mute the sound. After poking at it a few times without success I finally was able to get it working as expected.

First you will need to edit a PulseAudio config file. Open a terminal and enter the following:

gedit /usr/share/pulseaudio/alsa-mixer/paths/analog-output.conf.common

Any text editor will work, I used gedit in the example because it is easy to use and installed by default.

You’ll be prompted for your user password to open the file as root.

Once it is open, you want to search the file for Element PCM. The text you are looking for looks like this:

[Element PCM]
switch = mute
volume = merge
override-map.1 = all 
override-map.2 = all-left,all-right

You need to modify the text so the volume setting is changed from “merge” to “ignore” and add a volume-limit value and set it to a specific number. You can play with the number setting to see what gives you the best results. I found that a setting of 0.0075 gave me more than enough maximum volume while still allowing me to lower the volume appropriately. Your updated text should look like this:

[Element PCM]
switch = mute
volume = ignore
volume-limit = 0.0075
override-map.1 = all 
override-map.2 = all-left,all-right

Once that has been updated, save the file and enter the following in a terminal to reset PulseAudio and apply the changes:

pulseaudio -k 

Test the new settings to see if your volume control is where you would like it to be. If it is not, you can go back and adjust the volume-limit setting up or down to suit your preferences. Just remember to reset PulseAudio each time to apply the changes you made.


Creating a Child Theme in WordPress

When you are working with theme customization in WordPress, it is a good idea to create a child theme of the theme you want to start with. A child theme will look and feel like its parent theme, but will allow changes that you make to be retained when the parent theme is updated.

The first step to creating a child theme is to navigate to your themes directory located at /wp-content/themes. Once there, create a new directory for your child theme. You can call it whatever you want, but it is common to name it after the parent theme and append -child to the directory name.

Once your directory is created, you need to create a stylesheet in the directory and name it style.css. This stylesheet should contain the header comment below at the top of the file:

/*
 Theme Name:   Twenty Nineteen Child
 Theme URI:    http://example.com/twenty-nineteen-child/
 Description:  Twenty Nineteen Child Theme
 Author:       Your Name
 Author URI:   http://example.com
 Template:     twentynineteen
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Tags: one-column, flexible-header, accessibility-ready, custom 
 colors, custom-menu,   custom-logo, editor-style, featured-images,         
 footer-widgets, rtl-language-support, sticky-post, threaded- 
 comments, translation-ready
 Text Domain:  twentynineteenchild
*/

It’s important that the Template matches the directory name of your parent theme. Other things to watch out for are to make sure that you use the correct theme tags. Allowable theme tags are specified by WordPress.

The style.css theme is the only file that is required for the child theme, but you will need to add a functions.php file in order to enqueue styles correctly. The contents of that file should look something like this:

<?php
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
function my_theme_enqueue_styles() {
 
    $parent_style = 'parent-style'; // This is 'twentyfifteen-style' for the Twenty Fifteen theme.
 
    wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'child-style',
        get_stylesheet_directory_uri() . '/style.css',
        array( $parent_style ),
        wp_get_theme()->get('Version')
    );
}

Once those files are in place you can activate your child theme in your sites Administration Screen.

Using a Child Theme

Once your child theme is in place, you can copy over any template files you want to modify and make the changes within your child theme directory where they won’t be affected by updates to the parent. Additionally you can add CSS and PHP functions to the style.css file and functions.php within your child theme.


Installing WordPress with WP-CLI

I’ve been wanting to get a blog set up for a while now to start documenting my progress as I learn about Web development. Mission accomplished? Here’s how I did it.

My first step was choosing a domain name. Always tricky. I settled on adventuresinwebdev.com and registered it. I don’t use my hosting provider as a registrar so I had to point the new domain to my providers DNS servers.

Once all that was taken care of, I logged into my web server via SSH and got to work installing WordPress. My provide provides a handy GUI tool for WordPress installations, but I generally prefer to use the CLI when I can. My hosting provider has WP-CLI set up on my server so the installation process is super easy.

I navigated to the folder where I wanted to install WordPress and entered the following command to download the WordPress core files:

wp core download

Then I logged in to the cPanel for my server and set up a new MySQL database for the WordPress installation.

Once the database was configured, I moved on to setting up the WordPress config file. Once again, WP-CLI makes this simple with the following command:

wp config create --url=domainNameGoesHere --dbhost=localhost
--dbname=databaseNameGoeshere --dbuser=databaseUserName
--dbpass=userPassword

If you are following along, you’ll want to insert your database information in the relevant fields.

The last step is to execute the WordPress installation.

wp core install --url=yourDomainName --title="Your site title" 
--admin_name=yourAdminUserName --admin_password=yourAdminPassword  
--admin_email=yourAdminEmailAddress 

Again, you’ll need to insert your information in the appropriate fields.

That’s it! WordPress has been installed. Congrats!