tmux and screen shortcuts

Actiontmuxscreen
start a new session tmux OR
tmux new OR
tmux new-session 
screen 
re-attach a detached session tmux attach OR
tmux attach-session 
screen-r 
re-attach an attached session (detaching it from elsewhere) tmux attach -d OR
tmux attach-session -d 
screen -dr 
re-attach an attached session (keeping it attached elsewhere) tmux attach OR
tmux attach-session 
screen -x 
detach from currently attached session ^b d OR
^b :detach 
^a ^d OR
^a :detach 
rename-window to newname ^b , <newname> OR
^b :rename-window <newn> 
^a A <newname> 
list windows ^b w ^a w 
list windows in chooseable menu ^a ” 
go to window # ^b # ^a # 
go to last-active window ^b l ^a ^a 
go to next window ^b n ^a n 
go to previous window ^b p ^a p 
see keybindings ^b ? ^a ? 
list sessions ^b s OR
tmux ls OR
tmux list-sessions 
screen -ls 
toggle visual bell ^a ^g 
create another window ^b c ^a c 
exit current shell/window ^d ^d 
split window/pane horizontally ^b ” ^a S 
split window/pane vertically ^b % ^a | 
switch to other pane ^b o ^a <tab> 
kill the current pane ^b x OR (logout/^D) 
collapse the current pane/split (but leave processes running) ^a X 
cycle location of panes ^b ^o 
swap current pane with previous ^b { 
swap current pane with next ^b } 
show time ^b t 
show numeric values of panes ^b q 
toggle zoom-state of current pane (maximize/return current pane) ^b z 
break the current pane out of its window (to form new window) ^b ! 
re-arrange current panels within same window (different layouts) ^b [space] 
Kill the current window (and all panes within) ^b killw [target-window] 

Here’s the original info:

http://www.dayid.org/comp/tm.html

Using rsync to download from ssh

I run multiple servers i use for my various tasks. Lately i configured a raspberry  PI 2 with an attached 2TB hard drive that i use as a time machine backup for my MacBook and where i store programs and downloads, thus being able to access them from all over the world!

Thus, one of the things i need to do is download files from this server.

Sometimes you want to have the ability to resume your download, especially when the size of the download is big!

This is how you do it using rsync, through ssh:

rsync --partial --progress --rsh=ssh user@server_address:/remote/location/remote.file Local/path/local.file

You should be prompted for the password, if you configured sshd that way. Input it and your download will start or resume.

Fixing the Base URLs for Magento

If you move your Magento installation or change it’s hostname, the website will not be accessible.

This is how you bring it back up. This tutorial assumes you can log onto your server and have read/write access to your database.

1. Log into your MySQL database

Log into your MySQL database, replace $USER with your database user name and $DBASE with your database name. It will prompt you for your password:

mysql -u $USER -p $DBASE

If you do not remember your magento database name, try:

show databases;

and then:

use $magento_database;

Below are the SQL commands to change your base_url values. Replace unsecure http://www.example.com/ and secure https://www.example.com/ (if you have SSL/TLS enabled, else https should be http) with your appropriate domain url (trailing slash necessary) and if you’ve installed in a subfolder append it with a / after it.

2. SQL Commands

UPDATE core_config_data SET value = 'http://www.example.com/' WHERE path LIKE 'web/unsecure/base_url';
UPDATE core_config_data SET value = 'https://www.example.com/' WHERE path LIKE 'web/secure/base_url';

Check your base_url settings with the following:

3. Check correct results

SELECT path,value FROM core_config_data WHERE path LIKE 'web/unsecure/base%';
SELECT path,value FROM core_config_data WHERE path LIKE 'web/secure/base%';

Clear contents from var/cachevar/session directories after changing base_urls. Clearing cache and sessions is necessary because your config is cached and clearing it forces a reread of the configuration data from the core_config_data table and reestablishment of sessions with the proper information.

Install and Configure WordPress Under FreeBSD 11.0

Introduction

WordPress is a popular open source content management system (CMS) that can be used to easily set up a blog. It is a very flexible system, through its plugin and template support, that allows users to extend its functionality to meet their specific needs; WordPress can be customized to support anything from a basic blog to a fully-featured eCommerce site.

In this tutorial, we will show you how to set up WordPress with an Apache web server on FreeBSD 11.0

Prerequisites

Before you begin this guide, you must have a FAMP (FreeBSD, Apache, MySQL, and PHP) stack server setup.

This tutorial assumes that you want to serve WordPress from the root of your web site, e.g. http://example.com/, and that your Apache document root is empty (aside from the default index.html file).

This article assumes you have a working and configured installation of apache24, mysql57 and php70.

Step One — Install Additional PHP Modules

Although you already have PHP 5.7 installed, WordPress requires additional PHP modules in order to function properly. We will use pkg to install these required PHP modules.

At the command prompt of your server, use this command to install all of the required PHP 5.7 modules:

pkg install php70-mysqli \
 php70-xml \
 php70-hash \
 php70-gd \
 php70-curl \
 php70-tokenizer \
 php70-zlib \
 php70-zip

Each of these modules allows WordPress to use various functions in order to perform certain tasks. For example, php70-gd provides libraries for image handling, and php70-curl allows WordPress to download files from external servers for tasks such as plugin updates. Also note that if you followed the prerequisite FAMP tutorial, you should have already installed php70-mysqli, which allows WordPress to interact with a MySQL database.

Step Two — Prepare MySQL Database

WordPress uses a relational database, such as MySQL, to manage and store site and user information. In this step, we will prepare a MySQL database and user for WordPress to use.

Log into the MySQL administrative account, root, by issuing this command:

mysql -u root -p

You will be prompted for the password that you set for the MySQL root account when you first installed MySQL. After providing the password, you will enter the MySQL command prompt.

We will now create the MySQL database that WordPress will use to store its data. You can call this whatever you like, but we will call ours wordpress for our example. At the MySQL prompt, enter this SQL statement to create the database:

CREATE DATABASE wordpress;

Note that every MySQL statement must end in a semi-colon (;) before it will execute.

Next, we are going to create a MySQL user account that WordPress will use to interact with the database that we just created. For our example, we will call the new user wordpressuser with a password of password. You should definitely change the password to something more secure, and you can use a different user name if you wish. This SQL statement will create our example user:

CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

At this point, you have the MySQL database and user that WordPress will use. However, we must grant the user access to the database. To do this, we will use this SQL statement:

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;

Before this change in privileges will go into effect, we must flush the privileges with this SQL statement:

FLUSH PRIVILEGES;

Now exit the MySQL prompt:

exit

The MySQL database and user are now ready for use with a new WordPress installation. Let’s download WordPress now.

Step Three — Download WordPress

Now we must download the WordPress files from the project’s website.

The archive of the latest stable release of WordPress is always available from the same URL. Download it to your home directory with the following commands:

cd ~
fetch http://wordpress.org/latest.tar.gz

Now extract the archive with this command:

tar xvf latest.tar.gz

This extracts the contents of the archive to a directory called wordpress, in your home directory.

If you wish, you may delete the WordPress archive now:

rm latest.tar.gz

Step Four — Configure WordPress

Before making WordPress accessible via our web server, we must configure it so that it will able to connect to the database that we created earlier.

First, change to the wordpress directory:

cd ~/wordpress

To make the configuration simple, let’s base our WordPress configuration on the provided sample configuration, wp-config-sample.php. Copy the sample to wp-config.php, the default WordPress configuration file:

cp wp-config-sample.php wp-config.php

Now open the configuration file in an editor. We will use vi for this purpose, but feel free to use your editor of choice:

vim wp-config.php

The only modifications we need to make are to the MySQL settings. We must update the values of the following parameters:

  • DB_NAME
  • DB_USER
  • DB_PASSWORD

These correspond to the MySQL database and user that we prepared in an earlier step. Look for the following lines and update the highlighted parts with your database name, user, and password:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

Save and exit.

Step Five — Copy Files to Apache Document Root

Now that your WordPress application is configured to connect to your database, we must copy it to Apache’s DocumentRoot directory, where it can be served to your site’s visitors.

If you followed the prerequisite FAMP tutorial, Apache’s document root will be located at /usr/local/www/apache24/data—if your document root is located somewhere else, be sure to update the highlighted path in the commands in this section.

Let’s copy the WordPress files to Apache’s document root with the cp command:

mv ~/wordpress/ /usr/local/www/apache24/data/

Now change the ownership of the WordPress files to the www user and group, which is the name of the user that runs the Apache process, so Apache will have appropriate access:

sudo chown -R www:www /usr/local/www/apache24/data/*

Now that the WordPress files are being served by Apache, you are almost ready to start using WordPress.

Step Six — Run WordPress Installation Script

The next step is to run the WordPress installation script. The script will ask you a few questions about your WordPress site, then initialize the database.

In your web browser, navigate to your server’s domain name or public IP address and continue the setup from there!

That’s it, everything should be working fine now!

Configure apache24, php70 and mysql57 on FreeBSD 11.0

1. Install and configure Apache 2.4

Let’s install Apache 2.4 first. You may do so by running the following command:

pkg install apache24

On a brand-new system, you may get a message asking you to install the package management tool. If so, just enter “y” here because you will need this tool to complete the tutorial.

When asked to proceed with installing apache24 (and several other packages), enter “y” here as well.

Next, edit /etc/rc.conf with the editor of your choice and add the following line to start Apache on reboot:

apache24_enable="YES"

Now start Apache with the following command:

service apache24 start

Navigate to your IP address in your browser and you should see the default “It works!” Apache page indicating the installation was successful.

Apache 2.4 is now installed on your system. The next step is to install MySQL 5.7.

Tip: Your site files are located in /usr/local/www/apache24/data/ . This is where you’ll also find the default “It works!” Apache page.

2. Install and configure MySQL 5.7

The next step to install is MySQL 5.7. Do that now by running the following command:

pkg install mysql57-server

When asked to proceed with installing mysql56-server (and a few other packages, including mysql57-client), enter “y” here.

Edit /etc/rc.conf again and add the following line to start MySQL on reboot:

mysql_enable="YES"

Now you may start MySQL with:

service mysql-server start

At this point you will need to make some security modifications to your MySQL installation, particularly setting a root password and removing test and anonymous data. Do that with the following command:

mysql_secure_installation
  1. Press “Enter” at Enter current password for root (enter for none)
  2. Enter “y” at Set root password? [Y/n]
  3. Now enter a new secure password for the root MySQL user
  4. At Remove anonymous users? [Y/n], enter “y”
  5. Enter “y” at Disallow root login remotely? [Y/n]
  6. Remove the test database by entering “y” at Remove test database and access to it? [Y/n]
  7. g. Reload the privilege tables so your changes take effect by entering “y” at Reload privilege tables now? [Y/n]

Try accessing your MySQL databases now on the command line by using:

mysql -u root -p

That command should drop you into the MySQL shell. Congratulations, you’ve successfully installed MySQL 5.7 on FreeBSD 11.0! Now it’s time to install PHP 5.6.

3. Install and configure PHP 7.0

Again, we will use the pkg tool to install PHP 7.0. Do so with the following command:

pkg install mod_php70 php70-mysql php70-mysqli php70-extensions

Enter “y” when asked to proceed with installing the php70 packages.

Now edit /usr/local/etc/apache24/httpd.conf; the PHP file handler needs to be added and DirectoryIndex should contain index.php.

Locate the following block in httpd.conf:

<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

Change it to the following if you want Apache to serve index.php first (swap them if you want Apache to prefer index.html):

<IfModule dir_module>
DirectoryIndex index.php index.html
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>
</IfModule>

Now restart Apache so your changes to httpd.conf take effect:

service apache24 restart

Test that PHP is working correctly by creating a PHP file in /usr/local/www/apache24/data/. Create a file there called “index.php” and paste in the following code:

<?php
echo "Hello world!";
?>

Reload your IP address in your browser and you should see “Hello world!” instead of the default “It works!” Apache message from earlier in the tutorial.

You may need to restart Apache one last time if you still see “It works!” with:

service apache24 restart

That’s it! You now have a fully functioning FAMP server ready to host your website.

For certain websites like magento or wordpress you need to also enable mod_rewrite in apache24. To do this, uncomment the line

#LoadModule rewrite_module libexec/apache24/mod_rewrite.so

The next step is to also change this is http.conf.

vim /usr/local/etc/apache24/httpd.conf

find the section that contains the DocumentRoot:

DocumentRoot "/usr/local/www/apache24/data"
<Directory "/usr/local/www/apache24/data"

Change

AllowOverride None

to

AllowOverride All

Restart the apache web server!