Thursday, August 29, 2013

bitbucket setup

While I do have a GitHub account, I've decided to give BitBucket a try. The biggest selling point for me is that they have unlimited private repos. I still think GitHub is better for the general open source community, since more developers are on that site so it's one less account they have to create when they are contributing to a particular project. But for tinkering on small, personal projects, it seems like BitBucket is more along the lines of what I'm looking for.

After creating a BitBucket account, I went ahead and setup SSH so that I could use a SSH connection (and avoid the username/password hassle of using HTTPS) to push to my BitBucket repo. BitBucket provides pretty thorough instructions on how to do that here: https://confluence.atlassian.com/display/BITBUCKET/Use+the+SSH+protocol+with+Bitbucket

Getting BitBucket up and running was relatively straightforward. I created an empty repo on the BitBucket site. Then, on the client side, I decided to go with EGit since I was using Eclipse to do my dev work. My version of Eclipse came with EGit installed, so there's no need to install additional software. Looking at this tutorial, I skipped to Section 5 to start configuring Git in Eclipse. Note that, instead of using '/home/username/' I used '/Users/username/' since I was doing this on a Mac. What I like about the EGit interface is the Git Staging Perspective that they have. It makes it super easy to see what hasn't been staged, what's been staged and waiting to be committed, and what's already been committed.

To push the changes to a cloud Git server, just run these commands:
cd /path/to/my/repo
git remote add origin ssh://git@bitbucket.org/username/helloworld.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags

setting up git

Continuing my installation streak, I wanted to setup Git. I find this particularly useful when mucking around with a new coding language. As I'm making my way through what works and what doesn't, it's a tremendous help to know that in case I accidentally get too creative in my coding experiments, I always have something to easily fall back to. Now there are already lots of good discussions (e.g., see here and here) about Git vs other versioning control systems (VCS) (I personally used to use Subversion before switching to Git). As a Mac user, Git was already installed, though it was an older version (v. 1.7.12). Since I use Macports to do nearly all of my installs, I use these commands to update everything:
sudo port selfupdate         # updates macports
sudo port outdated           # lists which ports have a newer version
sudo port upgrade outdated   # upgrades the ports to the newer versions
Macports is usually smart about building/installing any dependencies first, but sometimes you run into errors. Also, there are a few ports that take a long time to build, so be patient! During my install, I encountered an error building arpack:
 --->  Computing dependencies for arpack 
--->  Configuring arpack 
Error: org.macports.configure for port arpack returned: configure failure: 
command execution failed 
Please see the log file for port arpack for details: 
/opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_math_arpack/arpack/main.log
To solve this, I first ran this:
 sudo port clean arpack 
 sudo port install arpack +openmpi -gcc45 -gcc47 
...and then continued running sudo port upgrade outdated

Note that others (http://mac-os-forge.2317878.n4.nabble.com/MacPorts-39476-arpack-s-openmpi-variant-conflicts-with-gcc45-td220687.html) have cited that they still encountered errors when building arpack. If that's the case, then try: sudo port install arpack -accelerate +atlas instead.
To check that the version was updated, run:
 git --version

installing apache, tomcat, and mysql on ec2

I'm a bit late jumping on the ec2 boat, but finally got around to checking out what ec2 is like and decided I'd try my hand at JSP while I'm at it. So with that in mind, I decided to go with a linux distro for my ec2 instance. For the most part, I followed these instructions to set up tomcat and mysql: http://coenraets.org/blog/2011/11/set-up-an-amazon-ec2-instance-with-tomcat-and-mysql-5-minutes-tutorial/ With that, I was up and running, I used MySQL Workbench (connecting over SSH) to setup a toy database that I could muck around with. Then I started hacking away on Eclipse EE, trying to do some simple JSP/Servlet stuff.
Inevitably, there were some additional tweaks I ended up needing to do after the 5-min tutorial setup, so I'll outline what I did here:
  1. Open up MySQL port. To ensure that my code could access the database (and not just MySQL Workbench), I had to open up the mysql port (3306). To do this, go to the EC2 Dashboard; under Network and Security, click on Security Groups. Select the appropriate security group for your instance and, under 'Inbound', create a new rule for the mysql port. After click 'Add Rule', it should appear in the list of TCP Ports.
  2. Automatically startup services. To automatically have tomcat and mysqld start up whenever the ec2 instance restarts, run these commands:
    sudo chkconfig --level 35 tomcat6 on
    sudo chkconfig --level 35 mysqld on
    Note: the different levels correspond to runlevels. To check that we have these services running with the right flags, we can run: chkconfig --list
  3. Secure MySQL. To make MySql slightly more secure, add a password for root (by default, there's no password), remove the test database, and remove anonymous access to the database.
    # create a new password for root
    sudo mysqladmin -u root password 'new-password' 
    # login with the new password
    sudo mysql -u root -p                           
    # remove test database
    mysql> DROP DATABASE test;
    # remove anonymous access to database
    mysql> DELETE FROM mysql.user WHERE user='' ;    
    mysql> FLUSH PRIVILEGES;
    
  4. Get phpMyAdmin working. Sometimes it's just easier to do DB stuff through a browser instead of a dedicated app like MySQL Workbench. To get phpMyAdmin up and running, I need to install Apache and php first. Having both Apache and Tomcat installed isn't problematic, since I have Apache handle the 80 port and Tomcat handle the 8080 port (which is the default for Tomcat anyways).

    To install Apache:
    sudo yum install php
    sudo yum install httpd
    
    To have the Apache service automatically run on startup:
    sudo chkconfig --level 35 httpd on
    Then I just went to https://gist.github.com/aronwoost/1105007 and followed the instructions in these sections: 'Setup phpMyAdmin', 'Make mod_write work', and 'Start apache'.

    First, to allow access from external IP's:
    sudo chmod 600 /etc/httpd/conf.d/phpmyadmin.conf
    sudo nano /etc/httpd/conf.d/phpmyadmin.conf
    #  Web application to manage MySQL
    #  #
    #  Order Deny,Allow
    #  Deny from all
      Allow from 127.0.0.1
    #
    Alias /phpmyadmin /usr/share/phpmyadmin
    Alias /phpMyAdmin /usr/share/phpmyadmin
    Alias /mysqladmin /usr/share/phpmyadmin
    
    Then, we add the blowfish_secret so that cookie authentication will work
    sudo chmod 600 /usr/share/phpmyadmin/config.inc.php
    sudo nano /usr/share/phpmyadmin/config.inc.php
    ...
    $cfg['blowfish_secret'] = 'put-a-magic-string-here'; 
    /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
    ...
    sudo chmod 644 /usr/share/phpmyadmin/config.inc.php
    
    Now we modify the httpd configuration to allow mod_rewrite to work:
    cd /etc/httpd/conf
    sudo nano httpd.conf
    
    A few lines below that, look for AllowOverride None and replace with AllowOverride All. And now start up Apache:
    sudo service httpd restart
    Now phpmyadmin is up and running at: 
    http://Your_EC2_IP_Address/phpmyadmin
    or
    http://ec2-*.*.compute.amazonaws.com/phpmyadmin