4 Simple Steps To Install WordPress Via SSH

WordPress SSH is a powerful tool that lets you handle everything from one terminal. If you’re already comfortable with using WordPress SSH, installing WordPress can be really fast and efficient.

In this article, we’ll provide a simple guide to help you navigate the process. Whether you’re new to SSH or looking to streamline your WordPress installations, this guide will make it all clear and straightforward.

TL;DR: If you’re familiar with SSH, installing WordPress will take you a few minutes. We’ll give you the commands: how to download the WordPress files, create a database, configure wp-config, and complete the installation successfully. Within minutes, you’ll be managing your WordPress site.

What you need to install WordPress via SSH?

Before you dive into installing WordPress using SSH, it’s important to have a few things ready. Here’s what you’ll need:

  1. SSH access to your server: This usually means having an SSH client installed, like PuTTY for Windows, or Terminal for macOS and Linux. 
  2. Web server: You’ll need a functioning web server. This tutorial uses Apache but you’ll find tutorials for other web servers. 
  3. Stable internet connection: A reliable network connection is essential. Disruptions can cause delays, corrupt the installation, or require you to start over.

Note: This tutorial is for Ubuntu. Other operating systems may use a variation of these commands. 

Step 1: Create the installation directory and download WordPress

To get started with your WordPress installation using SSH, you’ll first need to set up the directory where WordPress will reside and download the necessary files. Follow these commands step by step:

  1. Create the directory: Run the following command to create the installation directory:
sudo mkdir -p /srv/www

This sets up a directory for WordPress, preparing it to receive content.

  1. Set directory ownership: Next, you’ll need to change the ownership of the directory:
sudo chown www-data: /srv/www

Assigning ownership to www-data ensures that the web server can access and modify the files as needed. This is especially important for updates because it will throw up a 404 error if there are insufficient permissions. 

  1. Download and extract WordPress: Use the curl command to download the latest WordPress package and extract it directly into your prepared directory:
curl https://wordpress.org/latest.tar.gz | sudo -u www-data tar zx -C /srv/www

This command fetches the WordPress package and places it in your directory, all in one go.

Step 2: Configure the database

With the WordPress files in place, the next critical step is setting up a MySQL database to store your website’s data. Here’s how to configure your database via SSH:

  1. Access MySQL: Start by logging into MySQL as the root user:
sudo mysql -u root

This command gives you access to the MySQL monitor, where you can issue commands to manage your databases.

  1. Create the database: Create a new database for your WordPress installation:
CREATE DATABASE wp_;

This creates a database named “wp_”, where all your site data will be stored. This is the prefix used by default. It helps make sure that all your plugins and themes work correctly. 

  1. Create a database user: Next, create a new user and set a strong password:
CREATE USER wp_@domain IDENTIFIED BY '<your-password>';

Replace <your-password> with a secure password. This user will have access to your WordPress database.

  1. Grant permissions: Assign the necessary permissions to your new user:
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON wordpress.* TO wp_@domain;

This step is crucial as it allows the WordPress user to perform essential database operations.

  1. Apply changes: Ensure all your changes take effect:
FLUSH PRIVILEGES;
  1. Exit MySQL: Once you’ve configured everything, exit MySQL:
quit

Exiting MySQL returns you to the command line, ready for the next steps.

  1. Start MySQL Service: Make sure your MySQL service is running to support the WordPress connection:
sudo service mysql start

You can then set up an account with tools like Adminer or Webmin. Add your site and you’ll be able to manage your database from there. 

Step 3: Connect your site to your database

Linking your WordPress setup to the database is essential for your site to function properly. WordPress uses the wp-config.php file for this connection. If you don’t do this correctly, you will notice a database connection error. Here’s how you can configure the wp-config.php file using SSH:

  1. Copy the sample configuration file: Start by creating a new wp-config.php from the sample file provided:
sudo -u www-data cp /srv/www/wordpress/wp-config-sample.php /srv/www/wordpress/wp-config.php

Every new WordPress installation has a configuration file template. The one used to connect your site to its database is created on installation, so that’s what you are doing in this step. 

  1. Set database credentials: You need to update the configuration file with your database details. Use the following commands, replacing <your-password> with your database password:
sudo -u www-data sed -i 's/username_here/wordpress/' /srv/www/wordpress/wp-config.php
sudo -u www-data sed -i 's/password_here/<your-password>/' /srv/www/wordpress/wp-config.php

Ensure you input the password correctly to prevent connection issues.

  1. Open configuration file in nano: Access the configuration file for further edits:
sudo -u www-data nano /srv/www/wordpress/wp-config.php

This command opens the file in the Nano text editor.

  1. Replace security keys: Locate the following lines in the file:
define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

Delete each of these lines using Ctrl + K.

  1. Insert new security keys: Visit WordPress secret key API. Copy the generated keys and paste them into your wp-config.php to replace the deleted lines.

This step secures your site by generating unique phrases that protect against security threats.

  1. Save and close the file: Exit Nano, saving your changes by pressing Ctrl + X, then confirm with Y, and finish by hitting Enter.

Step 4: Configure WordPress

With everything in place, it’s time to finalize your WordPress setup through the web interface:

  1. Access the WordPress setup page: Open your web browser and navigate to:

http://url.com

This will take you to the WordPress installation page, where you can start configuring your site.

Pro tip: The URL is a non-SSL URL. This means it doesn’t have enough data encryption. We recommend that you instal an SSL certificate immediately. 

  1. Set up your site: You’ll be prompted to enter important details such as:
  2. Site title: Choose a name that best represents your website.
  3. Username: Create a unique username for logging into WordPress. Ensure it doesn’t match your MySQL username or your server’s login username for security reasons.
  4. Password: Set a strong password distinct from any other passwords you use.
  5. Email address: Provide a valid email address for WordPress notifications and password recovery.
  6. Privacy settings: You can decide whether you want search engines to index your site. Check or uncheck the option according to your preference.
  7. Complete the installation: Once you’ve entered all required information, proceed to complete the installation.
  8. Log in: You can log into your WordPress admin panel immediately after the setup is complete.

Troubleshooting common issues

Even with careful preparation, you may encounter some challenges during the WordPress SSH installation. Here are tips to overcome common issues:

  • MySQL errors: If you’re having trouble with MySQL, double-check your syntax and ensure your database credentials match what you specified in wp-config.php. If errors persist, confirm that the MySQL service is running with sudo service mysql start.
  • Incomplete downloads: If WordPress files aren’t fully downloaded, verify your internet connection and try downloading again. Ensure the URL you’re using with curl is correct and typo-free.
  • Server resource limitations: Sometimes, your server might not have enough resources (e.g., memory) to handle installation tasks. Edit your wp-config.php file to increase PHP’s memory limit:
define('WP_MEMORY_LIMIT', '256M');
  • Command-line syntax errors: Carefully review commands for typos or misplaced characters. Shell commands must be precise; even small errors can cause failures.
  • Version compatibility: Ensure the versions of PHP, MySQL, and WordPress are compatible. Check the official WordPress requirements and update any outdated components accordingly.
  • Configuration errors: If the site isn’t displaying correctly, revisit your wp-config.php settings to check for errors. This includes confirming correct database credentials and valid security keys.

Should you install WordPress via SSH?

To determine if you should use SSH to install WordPress, consider your familiarity with SSH.

If you don’t have much experience with SSH, using a good web hosting provider with managed WordPress installations might be easier. These platforms offer quick and guided setups that can create a WordPress site in just a few clicks, without needing to use command-line operations.

On the other hand, if you’re comfortable with SSH, installing WordPress this way is a great choice. This method provides complete control over the installation process and configurations. It’s especially beneficial for developers who want to customize settings and avoid relying on third-party interfaces. Additionally, managed WordPress installations by hosts come with their own tweaks and optimisations.

Ultimately, the best approach depends on your technical skills and the level of control you desire over your site. If convenience is your priority, a managed host is suitable; if you value control, SSH is the way to go.

Final thoughts

Installing WordPress is just the beginning of owning and managing WordPress admin. Using SSH for this task is ideal if you have the expertise. It’s a swift process, requiring only four steps, and it provides an exceptional level of control over your setup. For those comfortable with SSH, it’s an efficient way to tailor your installation to perfectly fit your needs.

FAQs

How to install WordPress through SSH?

To install WordPress through SSH, you’ll first need access to your server via SSH. Begin by creating an installation directory and downloading WordPress files. Configure a MySQL database and then connect it to your WordPress setup by editing the wp-config.php file. Finally, complete the installation through your browser. This method provides fine control over your setup if you’re comfortable using command-line tools.

How to SSH to a WordPress site?

To SSH to a WordPress site, you need an SSH client like PuTTY (for Windows) or Terminal (for macOS/Linux). Use your server’s IP address, username, and password to establish a connection. The command generally looks like this: ssh username@your-server-ip. Make sure your server has SSH access enabled and that you have the necessary credentials.

How to install WordPress in Linux terminal?

To install WordPress using the Linux terminal, open a terminal window and use SSH to access your server. Follow the same process as mentioned for installing WordPress via SSH: download the WordPress package to your server using command-line tools, set up the database, configure the wp-config.php file, and finalize the installation in your web browser. Linux terminal commands streamline this process, making it efficient for those familiar with command-line interfaces.

How to install WordPress via SFTP?

To install WordPress via SFTP, you need an SFTP client like FileZilla. First, download the latest WordPress package to your local computer. Then, connect to your server using SFTP credentials. Transfer the WordPress files to your server’s appropriate web directory. After the transfer, configure the MySQL database, and update the wp-config.php file with your database credentials. Complete the installation by visiting your site in a web browser to finish the setup process. SFTP offers a secure way to transfer files without using the command line.

Tags:

You may also like


Fix: WordPress 403 Forbidden
Fix: WordPress 403 Forbidden

Stuck with a “403 Forbidden” error while trying to access your WordPress site? It’s a little scary and quite cumbersome but you can troubleshoot WordPress errors like this.  It’s a…

Fix: WordPress 413 Request Entity Too Large
Fix: WordPress 413 Request Entity Too Large

Fixing errors in WordPress site is like hitting a digital roadblock. It can be frustrating and disruptive. But, you’re also left wondering why this is happening to you.  The “413…

How do you update and backup your website?

Creating Backup and Updating website can be time consuming and error-prone. BlogVault will save you hours everyday while providing you complete peace of mind.

Updating Everything Manually?

But it’s too time consuming, complicated and stops you from achieving your full potential. You don’t want to put your business at risk with inefficient management.

Backup Your WordPress Site

Install the plugin on your website, let it sync and you’re done. Get automated, scheduled backups for your critical site data, and make sure your website never experiences downtime again.