Set Up Wordpress on an existing EC2 Server using a Virtual Host

Easily Host a New Website on an existing EC2 Server

Check out our main page How to set up EC2 and Wordpress From Scratch

Pre-Set Up

Point the New Subdomain URL in Namecheap to the Existing EC2 IP Address

  1. Log into AWS EC2 Management Console.
  2. Navigate to an existing EC2 Instance you want to host the new site on.
  3. Open up Namecheap and add a new CNAME Record
  4. From the AWS EC2 Management Console copy the Public IPv4 DNS
  5. Paste it into the new CNAME record and name the subdomain

Virtual Host Configuration

Learn how to set up the set up the Virtual Host for your new website

  1. SSH into the EC2 Server
  2. Navigate directory to cd /var/www/
  3. Create a new Directory for your new site
  4. Type: mkdir newsite
  5. Navigate directories by typing: cd /etc/apache2/sites-available/
  6. Copy a pre-exiting .conf file for the new .conf file
  7. Type: sudo cp existing-site.conf new-site.conf
  8. Edit your new .conf file: sudo nano new-site.conf
  9. Change every instance of the old URL to the new URL. Also change the document root to the new root folder
  10. Example: ServerAlias: newsite.sparkxcell.com
    DocumentRoot var/www/newsite

  11. Type: sudo a2ensite (enables the .conf file you just created. in the sudo command type the file name but dont include .conf)
  12. Type: sudo systemctl restart apache2
  13. Enable HTTPS by getting a certificate
  14. Type: sudo certbot --apache
  15. install wordpress if you need, by following the wordpress tutorial

Install Wordpress

Follow Digital Ocean on how to install Wordpress onto our Lamp stack.

  1. Follow the tutorial at Digital Ocean
  2. Skip all portions of MYSQL

    Note:
    define( 'DB_NAME', 'wordpress' ); the Schema Name
    define( 'DB_USER', 'wordpressuser' ); the user account you created
    define( 'DB_HOST', 'localhost' ); the RDS Endpoint

Database linking with AWS RDS

Instead of relying on an internal database, find out how to link it to our remote database service

  1. Download or open MySql Workbench
  2. In AWS click services > navigate to RDS located in Database.
  3. In Mysql Workbench
  4. At the top, Click Database
  5. Create New Connection
  6. Change HostName to RDS Endpoint found on AWS
  7. Put in the username
  8. You can click test connection or skip and go OK
  9. Connect to database
  10. Put in password
  11. On the right side, click schemas tab
  12. Right click and create new schema
  13. Type the name of the schema, then click apply
  14. A new window will open, click apply, then finish
  15. Next to the schema tab, click administration tab
  16. Click 'users and privleges'
  17. Create a new user
  18. Click schema privleges tab
  19. Click add entry > select schema(your project)
  20. Check all rights to that entry and click apply