If i practice enough…

It is a well known fact… if you wanna master a craft, you need to spend at least 10k hours practicing. Guitars aint no different… with practice comes mastery. With time… you don’t need to look where your fingers are. You just know it. You feel the position of your fingers in the fretboard.

It’s rock and roll, in its purest essence…

Guitars

Star Trek : Into Darkness

If you were looking for a new wallpaper, you’ve come to the right place. As you may know, several scenes of the new Star Trek “Into Darkness” movie were shot in the NIF… (National Ignition Facility).

The movie itself plays a twist over the original Star Trek Series, since… in the previous movie, we’ve seen an alteration in the flow of events, which led to a way different outcome.

If you haven’t gone to the cinema yet, i suggest you check it out. Seriously speaking!

 

Star Trek Into Darkness

GIT Modules

Equivalent to SVN Externals, GIT offers a nice feature called “Modules”. Long short story, you get to link an external project, inside your own project.
What do you make out of this?. Well, suppose you’re using a 3rd party library. You can update everything with just a command line pull. No need to download and merge, by hand.

Sounds nice, right?. It’s done this way:

cd MyApp
git submodule add git://github.com/some-framework/some-framework.git Frameworks/SomeFramework

Afterwards, we need to recursively update the submodules. Which will, in turn, clone the ‘some-framework’ repository:

git submodule update --init --recursive

Fixing High I/O usage on Amazon EBS

This humble wordpress blog is running on an AWS micro instance. We’ve got somewhere around 1k visitors each month, which is pretty awesome. But… to my surprise, the whole system is using over 14 million I/O operations.

I suspected there was something wrong with this… so i proceeded to do a small research.
By means of the application ‘iotop’, i managed to spot the I/O hog: apache!.

Specifically, i ran iotop with the following parameters:

sudo iotop -a -P

I ran a quick search on google, and found this post.  (Thank you George, for sharing your solution!).

Long short story, Apache’s APC plugin was using a memory mapped file, and it was writing… almost all the time.
The solution?. Edit your /etc/php.d/apc.ini file, and make sure that the mmap_file_mask parameter is se to use Shared Memory, as follows:

apc.mmap_file_mask=/apc.shm.XXXXXX

That should fix it!

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!
    ssh -i certificate.pem ec2-user@[elastic-ip]
  7. Setup a password for your root user
    su passwd
  8. Install Apache
    yum install httpd
    service httpd start
    chkconfig httpd on
  9. Install PHP
    yum instlal php php-mysql
  10. Install mySQL
    yum install mysql-server
    service mysqld start
    chkconfig mysqld on
  11. Secure mySQL
    mysql_secure_installation
  12. Install APC
    yum install php-pecl-alc

 

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):
    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:

          <VirtualHost *:80>
              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
          </VirtualHost>
  2. Enable htaccess in your virtual hosts:
    nano /etc/httpd/conf/httpd.conf
    AllowOverride All
  3. Enable logrotate:
    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
       }

 

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
    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;
  2. Import a database dump
    mysql -p -u wordpress wordpress < database_dump.sql

 
I hope you found this short guide helpful!