Installing a Webserver on AWS EC2

I’ve recently lantean.co to AWS EC2. Amazon offers a free EC2 instance for a year…. so i decided to give it a shot.

The main reason i had to migrate to a self managed hosting is simple. Shared Hostings don’t allow you to fine tune several settings, such as the PHP Memory, and you might event not be able to login using ssh. What did i need to do?. It’s simple… let’s see…

 

Setting up the Environment

  1. Signup at Amazon Web Services. You’ll need a credit card.
  2. Create a new EC2 instance. Select ‘Micro’ as the type.
  3. Select the Amazon AMI. (I don’t trust 3rd party images!).
  4. Follow the wizard, and generate the SSH private / public keys.
  5. Setup the firewall, so only IP’s in your C class can connect through SSH, and everyone can hit the port 80.
  6. Connect to your box![cc lang=”bash”]ssh -i certificate.pem ec2-user@[elastic-ip][/cc]
  7. Setup a password for your root user[cc lang=”bash”]su passwd[/cc]
  8. Install Apache[cc lang=”bash”]yum install httpd
    service httpd start
    chkconfig httpd on[/cc]
  9. Install PHP[cc lang=”bash”]yum instlal php php-mysql[/cc]
  10. Install mySQL[cc lang=”bash”]yum install mysql-server
    service mysqld start
    chkconfig mysqld on[/cc]
  11. Secure mySQL[cc lang=”bash”]mysql_secure_installation[/cc]
  12. Install APC[cc lang=”bash”]yum install php-pecl-alc[/cc]

 

Setting up Apache

Assuming we’re not gonna host just a single website, but a couple of them… we’re gonna need to setup Virtual Hosts. With VirtualHosts you can serve as many domains as you need, using a single apache installation. Steps!

  1. Log into your instance and type… (replace domain.com with your own domain):
    [cc lang=”bash”]
    su
    mkdir -p /var/www/domain.com/public_html
    mkdir /etc/httpd/conf.d/domain.com.conf
    nano /etc/httpd/conf.d/domain.com.conf/httpd.conf
    Add the following lines:


    ServerAdmin your-mail@domain.com
    DocumentRoot /var/www/domain.com/public_html
    ServerName www.domain.com
    ServerAlias *.domain.com
    ErrorLog /var/www/domain.com/error.log
    CustomLog /var/www/domain.com/requests.log combined

    [/cc]

  2. Enable htaccess in your virtual hosts:

    [cc lang=”bash”]nano /etc/httpd/conf/httpd.conf
    AllowOverride All[/cc]

  3. Enable logrotate:
    [cc lang=”bash”]
    nano /etc/logrotate.conf
    Add the following lines:

    /var/log/httpd/*log
    /var/www/*/*log
    {
    size 5M
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
    /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
    }
    [/cc]

 

Setting up mySQL

At last!. Let’s see how to create a mySQL database, add a new user, and how to import your mySQL dump, using nothing but bash.

  1. Create a new database and a new user
    [cc lang=”bash”]
    mysql -u root -p << You will be asked for your mySQL root-password! create database wordpress; create user 'wordpress'@'localhost' identified by 'password'; grant all privileges on wordpress.* to wordpress@localhost; flush privileges; [/cc]
  2. Import a database dump
    [cc lang=”bash”]
    mysql -p -u wordpress wordpress < database_dump.sql [/cc]

 
I hope you found this short guide helpful!

SSH SFTP Updater : “Private key incorrect for user”

If you’re using WordPress SSH SFTP Updater plugin, and you got the error “Private Key is Incorrect for use”… even when the keys are correct, check the following:

[cc lang=”bash”]nano /etc/ssh/sshd_config[/cc]

If there is a “ForceCommand internal-sftp” directive, somewhere, in sshd’s config, try disabling it. That was what was causing me issues:

I had an sftp-only user, and the WP plugin doesn’t support that!.

Dropping a MongoDB Database

I’m writing this down, riiight here, because i just got bored of searching this in google everytime i need to run an experiment.
If you need to drop a mongo database, just fire the mongo shell and type:

[cc lang=”javascript”]
use mydb;
db.dropDatabase();
[/cc]

That’s it!

Warp Drive is Possible!

Warp Drive

Not long ago i’ve read Michio Kaku’s book, Science of the Impossible. If you have enough spare time to pick up a new book, i’d like to recommend it.

Michio suggests, in his book, that building a Warp Drive might become a reality in the next 100 years. But what are the grounds on that saying?.

Alcubierre Warp Drive

Proposed by physicist Miguel Alcubierre, the Alcubierre’s Drive is a solution to Einstein’s Relativistic equations. For it to work, we need matter with negative mass… which, as of today, hasn’t been discovered yet.

The idea behind the Alcubierre Drive is pretty clever. An object cannot achieve light speed on its own, because it’s mass would grow to infinity. So… as a brilliant alternative, Miguel proposed that we should move the space around us, instead.

How is that?. Well… imagine you place a toy-car on a sheet of paper. And instead of moving the car… you move the sheet of paper on which it’s standing. The toy would stand still, but the “space” around it would have moved.

If you’d like to go on reading about this, i suggest you click on the Alcubierre’s wikipedia entry!.

Dark Matter

The universe is expanding. Almost every human being with a rudimentary education knows that. But physicists have been struggling for the last hundred years with a serious problem.

We know that everything is moving away…. yes, because of the big bang. But thing is… the universe is not only expanding. It’s expanding at an accelerated rate. And that, my friends, is one of the greatest mysteries of science.

One of the most widely accepted theory that can explain this is… there is dark matter all around us. Why dark?. Because we cannot see it directly. And this dark matter, theoretically, matches THE Alcubierre’s Drive requirement: Dark Matter, if it even exists, needs to have negative mass.

Why negative mass?. Well… objects with positive mass attract other objects. That’s known as Gravity. If you wanna repel other objects… you need to twist that around: you need negative mass.

In Speculation Phase

We have the theoretical background that makes Faster Than Light… a theoretical possibility. That’s a HUGE difference with the science of the previous century. At this point, at least, we can dream of building an Enterprise ship.

Hopefully… our grandchildren will be able to experience our dreams. That is… reaching the stars!.

By the way… NASA has its own ‘Status of Warp Drive‘ webpage.

%d bloggers like this: