Before I start, ThanksAJ.com is back up!!
So due to some change in life circumstances, my ability to host my own website myself has been compromised. Therefore, I set out in search of a hosting platform. I asked @Danielle-Ralston about Rackspace, but that was too pricey. I looked at Azure, but even that was more than I could spend right now. However, AWS has quite a few things you can do completely free. For example, 1 CPU, 1 core, and 1GB for a Linux VM is totally free!! (as far as I can tell)
Anyways, so here's what I did to move my webserver over...
I setup my network back up with my router and server just to get files off. I keep my sites in their own folders in /var/www/. I copied the directories to the SAMBA share directories and then from there off to my laptop. Next, you need to run the following command...
mysqldump -u [username] -p [database_name] > [dumpfilename.sql]
Do that for every database you have, assuming you're using Wordpress. I copied the exported databases for each of my three sites to my laptop as well.
Next, I created a new VM, or instance as Amazon calls it, of Ubuntu Server.
Next I choose my instance provisioning, and I'm in the free tier category...
Configure instance details...I left this all default...
Next is storage...I made my server 10GB...
Next you name/tag the machine...
Now is the security settings/firewall rules...I added HTTP port 80 to the list to allow the webserver to work...
That's pretty much it! A full list of what you have access to is here:
Once the VM was up, Amazon uses keys to secure the SSH connections, and they give you a very comprehensive tutorial on how to use their key file, which is a .pem, with PuTTY, which involves converting it to a PuTTY readable-format using PuTTYgen.
Once I connected, I installed Pertino and connected it to my account. Then I shared the folder housing the files on my laptop and ran...
mount -t cifs -o username=*username*,password=*password* //50.203.224.5/Websites /media/websites
I made the folder websites in the /media folder so I'd have somewhere to mount it. After that, I did the following...(note: I was running in root mode, so I didn't have to type sudo before the commands)
cd /media/websites
cp -rv * /var/www
The -r makes the copy recursive, and my .sql files were in this folder as well. I moved those after they copied. Also, the -v makes it verbose so you can see the progress, which you will want. While that ran, I opened a second SSH session and ran the following...
apt-get update
apt-get install apache2 mysql-server libapache2-mod-auth-mysql php5-mysql php5 libapache2-mod-php5 php5-mcrypt
This installs Apache, MySQL and PHP so that you have a functional LAMP stack on your server!
Now, assuming you have the .sql files copied, which it might be better to copy these separately and first (which I did), we need to import them back into MySQL. However, first we have to configure MySQL. You would have been prompted to set a root MySQL password when you installed it, so you will need that now.
mysql -u root -p
> CREATE DATABASE thanksaj;
> CREATE DATABASE literaryworksbyaj;
> CREATE USER wordpressuser@localhost;
> SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
> GRANT ALL PRIVILEGES ON thanksaj.* TO wordpressuser@localhost IDENTIFIED BY 'password';
> GRANT ALL PRIVILEGES ON literaryworksbyaj.* TO wordpressuser@localhost IDENTIFIED BY 'password';
> FLUSH PRIVILEGES;
> exit
You will want to recreate the databases using the same names you used before, or you can name it something different, as long as you update your wp-config.php file afterwards. Now, navigate to the directory of your .sql files. To import the database into MySQL, use the following command:
mysql -u [username] -p [database_name] < [dumpfilename.sql]
So in my case, I did this...
cd /path/to/sql_files
mysql -u root -p thanksaj < thanksaj.sql
So all that was left for me to do was setup the Apache Virtual Hosts and make sure Mod_Rewrite would work. Go to your apache.conf file in /etc/apache2/apache2.conf. It should be line 164 that will have the part you need, which is this:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change the line in bold from ending in None to All. Now navigate to /etc/apache2/sites-available/ and make a .conf file for each website you're hosting. To do this, run...
cp 000-default.conf thanksaj.com.conf
vi thanksaj.com.conf
The default looks as follows (additions/changes from default in bold):
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster@localhost
ServerName thanksaj.com
ServerAlias www.thanksaj.com
DocumentRoot /var/www/thanksaj.com
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
Make on of these for each site. Afterwards, run...
a2ensite thanksaj.com
service apache2 restart
You can bring all the sites on at once and then just restart apache once. Now the virtual hosts are online!
Once I did this and had all my files copied over, my site was live once again! I know this is pretty long but I hope this helps someone else in the future!
Stay fruity Fruit Tarts!
Thanks,
A.J.
Reference Links: