How to Set Up a WordPress Site on Your VPS

This guide will walk you through the process of installing WordPress on your VPS, allowing you to create and manage your own website easily.


Step 1: Update Your System

  • Log in to Your VPS:

    • Use SSH to connect to your VPS:
    bash
    ssh user@your_vps_ip
     
  • Update the Package Index:

    • Update your system’s package index to ensure you have the latest information on available packages:
    bash
    sudo apt update
  • Upgrade Installed Packages:

    • Upgrade any installed packages to their latest versions:
    bash
    sudo apt upgrade -y
     

Step 2: Install Required Software

  • Install Apache:

    • Use the following command to install the Apache web server:
    bash
    sudo apt install apache2 -y
     
  • Install MySQL:

    • Install the MySQL server package:
    bash
    sudo apt install mysql-server -y
     
  • Secure MySQL Installation:

    • Run the security script to set up security options for MySQL:
    bash
    sudo mysql_secure_installation
     
    • Follow the prompts to configure your MySQL installation, including setting a root password and removing anonymous users.
  • Install PHP:

    • Install PHP along with necessary modules for WordPress:
    bash
    sudo apt install php libapache2-mod-php php-mysql -y
  • Restart Apache:

    • Restart the Apache service to load the new PHP module:
    bash
    sudo systemctl restart apache2

Step 3: Create a MySQL Database for WordPress

  • Log in to MySQL:

    • Access the MySQL command line:
    bash
    sudo mysql -u root -p
  • Create a Database:

    • Run the following command to create a new database for WordPress:
    sql
    CREATE DATABASE wordpress;
  • Create a MySQL User:

    • Create a new user and grant permissions to the database:
    sql
    CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'your_password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost'; FLUSH PRIVILEGES; EXIT;

Step 4: Download and Configure WordPress

  • Change to the Web Directory:

    • Navigate to the web root directory:
    bash
    cd /var/www/html
     
  • Download WordPress:

    • Use wget to download the latest WordPress package:
    bash
    wget https://wordpress.org/latest.tar.gz
  • Extract the WordPress Files:

    • Extract the downloaded file:
    bash
    tar -xvzf latest.tar.gz
  • Move WordPress Files:

    • Move the extracted files to the web root:
    bash
    sudo mv wordpress/* ./
  • Remove the Downloaded Archive:

    • Clean up by removing the downloaded archive and the empty directory:
    bash
    rm -rf latest.tar.gz wordpress
  • Set Proper Permissions:

    • Adjust the permissions to allow the web server to access the files:
    bash
    sudo chown -R www-data:www-data /var/www/html
    sudo chmod -R 755 /var/www/html

Step 5: Configure WordPress

  • Create a Configuration File:

    • Copy the sample configuration file to create a new one:
    bash
    cp wp-config-sample.php wp-config.php
     
  • Edit the Configuration File:

    • Open the configuration file in a text editor:
    bashnano wp-config.php
     
  • Update Database Information:

    • Modify the following lines with your database details:
    php
    define('DB_NAME', 'wordpress');
    define('DB_USER', 'wordpressuser'); define('DB_PASSWORD', 'your_password'); define('DB_HOST', 'localhost');
  • Generate Secret Keys:

    • Visit the WordPress secret key generator to generate secure keys. Replace the corresponding lines in your wp-config.php file with the generated values.
  • Save Changes:

    • Save the file and exit the editor (in Nano, press CTRL + X, then Y, and Enter).

Step 6: Complete the Installation via Web Browser

  1. Access Your WordPress Site:

    • Open your web browser and navigate to http://your_vps_ip. You will see the WordPress installation setup.
  2. Choose Language:

    • Select your preferred language and click "Continue."
  3. Fill in Site Information:

    • Complete the site title, username, password, and email address, then click "Install WordPress."
  4. Login to WordPress:

    • After the installation, you can log in to your WordPress admin dashboard at http://your_vps_ip/wp-admin using the credentials you just set.

Congratulations! You have successfully set up a WordPress site on your VPS. You can now start customizing your site and adding content. If you have any questions or encounter issues, please consult the documentation or reach out for support.

Was this answer helpful? 0 Users Found This Useful (0 Votes)