Using scp to copy from a server and to a server

Copy files from the server to your pc

You need ssh access, view this post to do that:

Add ssh keys and ssh access to a linux server

The command to scp from server to your computer

1
sudo scp -i ~/.ssh/id_rsa user@server:A B

eg

1
sudo scp -i ~/.ssh/id_rsa user@server:/the/filepath/on/server/**/* /filepath/of/computer

/**/* refers to all files and subfolders

Copy files from your pc to the server

The normal way to scp, where you copy files from your computer to the server

1
scp -r A user@server:B

eg:

1
scp -r /path/on/your/computer/ user@server:/path/to/server/destination

-r means recursive (so all files and sub folders)

Wildcards

You can use wildcards to match with a file extension

1
eg *.php

That will copy all php files only.

Configuring github to work through a proxy

Edit the .gitconfig file on Windows to work with a proxy

Open your .gitconfig file. You can find this file in your C:/Users/[your user] folder.

Edit the .gitconfig file on Ubuntu/Linux to work with a proxy

Open your .gitconfig file. You can find this file in your home ~/ folder.

You can type in the command line:

sudo nano ~/.gitconfig

Edit the .gitconfig file

Insert the following lines:

[http]
proxy = http://username:password@proxyurl:port
[https]
proxy = http://username:password@proxyurl:port
sslVerify = false

Username would be your proxy username.

Password would be your proxy password.

Proxyurl would be the proxy url.

Port would be the proxy port.

View your git settings

You can check your git settings in the command line by running the following:

git config -l

 

Configuring a proxy on windows and linux

I have a daily battle with a proxy. Each day I think, “today this proxy will be tamed”. Only to have the proxy stop working and I have to start figuring it out from scratch.

Below is what I go through each time I experience problems with proxy connection.

Connecting to a proxy via command line:

Windows

Configure your windows environment to work through a proxy

Environment variables

One way is to update your environment variables.

Open a command console, and in it add these two settings:

set http_proxy=”http://proxyUsername:proxyPassword@proxyUrl:port”
set https_proxy=”’http://proxyUsername:proxyPassword@proxyUrl:port”

View environment variables

To view your system settings enter in your command console:

set

Using “set” is more like a “cache” setting, it will go away when you close the command console, or restart your computer. To set it permanently, either manually add it to your environment variables. Or use setx.

setx /M http_proxy “http://proxyUsername:proxyPassword@proxyUrl:port”
setx /M https_proxy “http://proxyUsername:proxyPassword@proxyUrl:port”

A note on the value ”http://proxyUsername:proxyPassword@proxyUrl:port”

This format can be:

  • ”http://proxyUsername:proxyPassword@proxyUrl:port”
  • ”http://proxyUrl:port”

Another note: ping will not work with a proxy. (Well for now I haven’t found a way for it to work yet.) From the research I have done to date, ping works at a different level to the proxy. So just a head’s up, if you use ping to test if your proxy settings now allow internet access, you will be going in circles.

What should work is if you use a tool like vagrant for example and you need to download a box.

If this doesn’t work, and you use a tool that needs internet acces through the command line and it still cannot connect to the internet. Make double-triple sure your proxy details are 100% correct. Make sure you are connected to the internet.

And try the below:

LAN Settings

Setting the proxy on the lan settings. I have found two ways of setting this, one way is through a web browser like Chrome. And the other is through the control panel.

Using chrome

Go to Settings.
Show advanced settings.
In the Network section click “Change proxy settings”.
In the window that opens up click on “LAN settings”.
Select “Use a proxy server for your LAN…”
Add the proxy address, add the proxy port.

Additional notes on using windows for proxy

  • Often something doesn’t work because you need to open a new console window for to take effect (eg changing environment variables).
  • Often something doesn’t work because you nee the entire system to be restarted (this is always my last go to, if all else fails, restart).

Proxy is still not working on windows

If you have done all of the above and you still do not have internet acces through the proxy, you need to check if your proxy itself is not blocking the access.

Setting up proxy details on Linux

This is still a work in progress, below is what I’ve figured out so far:
To set the system variables on linux:

export http_proxy=”http://proxyUsername:proxyPassword@proxyUrl:port”
export https_proxy=”http://proxyUsername:proxyPassword@proxyUrl:port”

Adding to your Environment variables for windows

Environment variables for windows

Adding environment variables is important to know. Environment variables are values that can be stored on your computer that can then be referenced by you computer.

Scenario: Adding python to a windows pc

Setting up python on a windows pc, you will need to make sure there is an environment variable set up to reference the command “python”. This will point to the python executable on your pc.

To view all your environment variables on windows you do the following:

  • Right click on your “My computer” icon
  • Select advanced system settings
  • Click on environment variables

The most common environment variables to edit are the values in the “Path”. This will allow you to point to an executable in a file path.

If for example you have php installed on your pc, but you cannot run php in the command line, you need to update or add the correct filepath to point to the php executable, which is often here: C:\xampp\php

Returning to python, I have python installed here: C:\Python27\Scripts. So I have made sure this file path is in my environment variable “Path”.

Remember to seperate multiple paths with a semi colon ‘;’.

Eg

C:\Python27\Scripts; C:\xampp\php;

This will remain the same for any program you want to run in your command line. If the file path is not in your environment variables you won’t be able to run the program from your command line.

Open a new command line window

You need to open a new command line instance in order to use the environment variable. You won’t be able use the path reference in the same command line window.

Use the command line tool to scaffold a wordpress site on windows

Pre-requirements

Make sure you have apache and phpmyadmin installed. You can download and install xampp here, which will provide you with both and more.

https://www.apachefriends.org/download.html

You will also need an internet connection.

This is easier if you use Linux, but if you prefer using Windows here is a quick guide.

Get wp-cli.phar

Follow the online instructions to get wp-cli.phar:

http://wp-cli.org/

If that doesn’t help try these alternative install methods:

https://github.com/wp-cli/wp-cli/wiki/Alternative-Install-Methods

Add the wp-cli.phar file to your system. I have a bin folder on Windows that I add any .phar files to.

C:\bin\wp-cli.phar

To run the wp-cli.phar on windows you will need to use the following command:

php [filepath]\wp-cli.phar

With [filepath]\ being the path to the location of your wp-cli.phar file.

Eg:

php C:\bin\wp-cli.phar

Check that the wp-cli.phar is working:

Run

php C:\bin\wp-cli.phar –info

Add a database

Go to your phpmyadmin, and add a blank database for your new wordpress to use. Typically your phpmyadmin will be here: http://localhost/phpmyadmin.

Just click on the “Databases” tab and create a new database called wp-test.

Add the mysql.exe filepath to your environment variables so that the command line can run mysql. You also need to have the php.exe filepath in your evironment variables;

Eg I added the below to my PATH variable in my evironment variables:

mysql

C:\xampp\mysql\bin;

php

C:\xampp\php;

Remember to separate each file path with a semicolon ;.

Read this post if you need to learn how to add to your environment variables.

Change to your wordpress directory

Go to the directory you want to add wordpress to. This will need to be on a server like apache. If you have xampp installed add wordpress in the htdocs folder.

Eg

cd C:\xampp\htdocs\wordpress\

This can be in any directory you like, just create the directory you want to install in and make sure you are in that directory in your command line.

Download wordpress using the command line

Step 1. Now that you have wp-cli.phar working download wordpress.

Run

php C:\bin\wp-cli.phar core download

The bonus of this approach is if you have already downloaded wordpress it will be cached on your system and the system will use that cached copy to install. You do not need to download it every time.

Setup the wp-config.php

Step 2. Every wordpress installation needs a wp-config.php file. Run the below to create the file.

Run

php C:\bin\wp-cli.phar core config –dbname=[db name] –dbuser=[db user] –dbpass=[db pass]

Eg

php C:\bin\wp-cli.phar core config –dbname=wp-test –dbuser=root

I have left out the –dbpass as I don’t have a password. By default in phpmyadmin the user name will be root and the password blank.

Getting an error?

If you get this error, you need to check that you have the mysql.exe location in your environment variables.

Error:
‘mysql’ is not recognized as an internal or external command, operable program or batch file.

You need to open a new command line instance in order to use the environment variable. You won’t be able use the mysql path reference in the same command line window.

Set wordpress up

Step 3. This is where you add in your admin user details and database details.

Run

php C:\bin\wp-cli.phar core install –title=’Test’ –admin_user=[your user name] –admin_password=[your password] –admin_email=[your email]  –url=[your wordpress url]

Eg

php C:\bin\wp-cli.phar core install –title=’Test’ –admin_user=admin –admin_password=securepassword –[email protected]  –url=http://localhost/wordpress/

Done.

You now have the ability to get wordpress up and running through the command line.

 

 

 

Command line for a newbie

Basics of command line explained. Functionality you should become familiar with.

What development can you do with the command line

The command line interface has become useful for scaffolding development projects in less time and with less effort.

With tools like git offering a simple but powerful version control interface it is becoming very important to add the command line to your toolbelt.

There are multiple online package libraries from which to download and install using the command line.

For php there is packagist.

For python there is pip.

For front end packages like angular or jquery and much more, there is npm.

The basics

So here’s a quick overview of the beginner stuff.

Change your location

When you open your command line tool, you will be in a particular folder on your computer. For windows you may be in C:\ and for ubuntu you may be in ~/

To change your location you can use command cd

cd [path]

Windows

Eg: cd C:/Projects/

Linux

Eg: cd ~/Projects

View files in current directory

As you move around the different folders on your computer you will want to see what other folders or files are within the folder you change to.

For Linux you will use the command ls:

ls

For Windows you will use the command dir:

dir

These will return a list of files and folders in the current folder.

You can combine this with a folder path in order to see a list of files and folders in a folder you are not currently in.

Linux:

ls [folder location]
Eg: ls /var/log

Windows:

dir /a [folder location]
Eg: dir /a C:/

Creating directories

Create a directory in the current location.

mkdir

If you want to create a directory in a different location you will need to use cd to go there.

Create a file

Ubuntu:

touch [filename]
eg touch index.html

Windows:

There are multiple ways to create a file in windows. You will just need to select the approach that works for you. Below are two of the various ways to create files on windows.

echo 2> [filename]

fc >> [filename]

Alternatively you can use notepad:

notepad [filename]

This will open up notpad which will then ask you if you would like to create a file named [filename]

Rename a file

ren

ren [current filename] [new filename]

Delete files

For Linux use rm

rem [filename]

For Windows use

DEL [filename]

Keep learning

This is only the tip of the iceberg. The command line is a very powerful interface and can save you a lot of time.