Thursday, February 20, 2025

adding two wordpress sites to an existing server

We had a server which had Apache and Mysql already installed (as well as a couple of Wordpress sites already). Steps followed, in brief, to add two more Wordpress sites:
  1. mysql> create database wordpresswebsitestaging;

    CREATE USER "stagingwpuser"@"localhost" IDENTIFIED BY "ThePasswordH3r3";
    GRANT ALL PRIVILEGES ON wordpresswebsitestaging.* TO "stagingwpuser"@"localhost";
    FLUSH PRIVILEGES; 

    https://developer.wordpress.org/advanced-administration/before-install/creating-database/

  2. Creating the web root directories and a user who can sftp in to upload files etc if needed
    sudo adduser thewpwebsiteadmin
    sudo su thewpwebsiteadmin
    cd /home/thewpwebsiteadmin
    mkdir directory1
    mkdir directory2


    We need to give read permissions to the entire path for the webserver to be able to read these directories, so
    sudo chmod -R +rx /home/thewpwebsiteadmin


  3. Created DNS entries in cloudflare. In this case, CNAME records.

  4. Copied existing files in /etc/apache2/sites-available as templates for the new sites. Since we were using cloudflare origin certificates, there was no need to create new certificates with certbot etc. After editing the conf files as needed, with the /home/thewpwebsiteadmin/directory1 and directory2 as home directories, enabled the sites with
    sudo a2ensite newsite1 newsite1ssl newsite2 newsite2ssl
    sudo systemctl reload apache2


  5. Path to latest wordpress from https://developer.wordpress.org/advanced-administration/before-install/howto-install/
    wget https://wordpress.org/latest.tar.gz
    tar -xzvf latest.tar.gz
    cp -R wordpress/* directory1
    etc

  6.  Visit the new sites with a browser to supply the database configuration etc, the wp-config file gets generated, create a new file and paste the generated file to the wordpress root directories as
    nano wp-config.php

  7.  Create ssh key and add to authorized_keys - 
    ssh-keygen -t rsa -m PEM -f theadminuserkey.pem
    mkdir .ssh
    mv theadminuserkey.pem.pub .ssh/authorized_keys

    and set appropriate permissions for the .ssh directory and file - 
    chmod 700 .ssh
    cd .ssh
    chmod 600 authorized_keys

No comments:

Post a Comment