This tutorial will guide you step by step on how to setup your server so you can install new plugins and upgrade existing plugins using an SSH2 layer in PHP and WordPress.
What is WordPress?
WordPress started in 2003 with a single bit of code to enhance the typography of everyday writing and with fewer users than you can count on your fingers and toes. Since then it has grown to be the largest self-hosted blogging tool in the world, used on hundreds of thousands of sites and seen by tens of millions of people every day.
What is SSH?
SSH (Secure Shell) is a protocol allowing a secure channel to be established between a web server and a client’s local machine. Many web hosting companies now offer SSH for greater security.
There are a few things that need to be in place before you can actually use this tutorial.
The first thing to do is make sure you have SSH2 installed via pecl. If it’s not installed or you’re not sure, run this command: pecl install ssh2
note: If your case is where the installed version of SSh2 is beta, run this command instead: pecl install channel://pecl.php.net/ssh2-0.11.0
If you don’t feel comfortable running these commands yourself and you know of a server administrator that can help, or you’re paying for managed services, ask them to install this for you.
After SSH2 is installed, follow these instructions to ensure that the SSH2 extension is enabled in PHP. Again, if you are using managed services, simply ask them to do this for you.
- cd /etc/php5/conf.d; echo “extension=ssh2.so” > ssh2.ini
- /etc/init.d/apache2 restart
- Red Hat, CentOS, Fedora
- cd /etc/php.d; echo “extension=ssh2.so” > ssh2.ini
- /etc/init.d/httpd restart
Step 1: Generating the server-side RSA keys
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory ‘/home/user1/.ssh’.
Enter passphrase (empty for no passphrase): (just hit enter, no need for a password)
Enter same passphrase again: (same thing, hit enter again)
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
The xx:xx:xx etc. will be replaced with your actual fingerprint.
Step 2: Creating an ‘authorized_keys’ file
cd .ssh cp id_rsa.pub authorized_keys
Step 3: Setting the proper file permissions
cd ~/ chmod 755 .ssh chmod 644 .ssh/*
Step 4: Choosing the ‘SSH’ option
In this tutorial, I opted not to use a password, so you do not need to enter a password.
Step 5: Click “Proceed”
The last step is to click the proceed button and it will install a new plugin or upgrade an existing plugin via the integrated SSH layer in WordPress. You should see results something like this…
== Optional ==
If you want to automate the process a bit more, there are a few more things you can do to make it even easier.
If you open up your wp-config.php and add these lines, it will make the process smoother.
define('FTP_PUBKEY','/home/user1/.ssh/id_rsa.pub'); define('FTP_PRIKEY','/home/user1/.ssh/id_rsa'); define('FTP_USER','user1'); define('FTP_PASS',''); define('FTP_HOST','server1.example.com:22');
Now, when you click “upgrade” or “install” on a new plugin, it will bypass the first screen you saw above asking for the details. It will automatically go into the process and start the install/upgrade.