Here is the scenario: I used Bitnami to create a WordPress install on a free Amazon EC2 (Elastic Cloud Compute) micro instance (see this article if you want to know how to do that), and I wanted to point my URL at the resulting site. Furthermore, I wanted the ability to host more than one site on my EC2 instance, each with separate URLs. While there is a lot of good documentation about Amazon EC2, I didn’t find anything that told me how to do this. After a lot of research and messing around, I figured it out! Here’s how.
Assign a Static IP (Elastic IP)
The first thing you should do, if you haven’t already, is assign a static IP address to your EC2 instance. Confusingly, Amazon calls static IP addresses “elastic IP” addresses. You can do this either within the Bitnami control panel (go to Servers -> Assign IP) or in the Amazon EC2 control panel (go to Elastic IPs -> Allocate New Address). Assign the IP address to your instance, and write it down for later.
Keep in mind, this IP address will point to the “root” of your Bitnami site (http://yourname.bitnamiapp.com), which is a simple page with some links, one of which points to your WordPress site. That’s not what you want, but I’ll show you how to fix that.
Checking with my domain name provider, I found out that there is no way to directly point a domain name at a sub directory. You can only point it at an IP address, and then the nameserver can take you to a sub directory from there.
Point Your URL at that IP Address
So, the next step is to go ahead and point your URL at your EC2 IP address, even though that is not what we ultimately want. I Googled around and found these instructions to assign a domain name to Amazon EC2. Skip to step 8, because Bitnami basically took care of steps 1-7.
Basically, go to your domain host and specify NS73.DOMAINCONTROL.COM and NS74.DOMAINCONTROL.COM as your name servers, and change the A-record to point to your EC2 instance’s IP address.
After the domain name propagates, your IP address will point to: http://yourname.bitnamiapp.com. If you installed WordPress, your actual site is at http://yourname.bitnamiapp.com/wordpress, so we are not quite there yet.
At this point, you’ll need to be able to SFTP up to the server. Note that EC2 only works with SFTP, not FTP. You’ll need to download a key pair and load it into Filezilla or whatever program you’re using for SFTP. There are lots of sites that describe how to do this.
If You Are Hosting One Site
If you are only planning to host one WordPress site on your EC2 instance, you can do this solution, which basically makes your WordPress site “appear” at the root by doing an .htaccess trick:
- SFTP to /opt/bitnami/apps/wordpress/conf
- Uncomment the red lines in wordpress.conf as indicated by the comments by removing the hash at the beginning of lines 3 and 4:
1234# Uncomment the following lines to see your application in the root# of your URL. This is not compatible with more than one application.#RewriteEngine On#RewriteRule ^/$ /wordpress/ [PT]
Then, skip to step 6 below to finish configuring WordPress.
I’m not crazy about this solution, because it only allows me to host one site on my EC2 instance!
The Solution for Hosting More Than One Site
If you want to host multiple sites on your instance, here’s how to do it:
- SFTP to your Apache config folder: /opt/bitnami/apache2/conf
- Uncomment this line (remove the hash in front) in httpd.conf:
- Go to the “extra” folder: /opt/bitnami/apache2/conf/extra
- Make sure this line is uncommented in httpd-vhosts.conf:
- Add the following lines to your httpd-vhosts.conf file, substituting your domain name (without the “http://”) for “yourdomain”:
1234567<VirtualHost *:80>ServerAdmin email@example.comDocumentRoot "/opt/bitnami/apps/wordpress/htdocs"ServerName yourdomain.comErrorLog "logs/yourdomain.com-error_log"CustomLog "logs/yourdomain.com-access_log" common</VirtualHost>
- Restart httpd by typing this at the command line:
> sudo service httpd restart
- Modify your WordPress wp-config.php (or your database) with the new path in these two lines as follows:
12define('WP_SITEURL', 'http://yourdomain.com');define('WP_HOME', 'http://yourdomain.com');
- Go into WordPress and re-save your permalinks
Basically, you repeat steps 4 and 5 for each new domain name you want to map. Here are some sites that describe that part in more detail:
Do steps 6 and 7 for WordPress sites.
Did it work? Let me know how it went for you. I got it working with one site, and theoretically it should work with multiple sites, but I haven’t tried that yet.
The only side-effect of this was that I was no longer able to access the Bitnami “welcome” page at http://myname.bitnamiapp.com, but that was fine with me.
If you want to host multiple SSL sites, check out this article. – Brian