Posts Tagged ‘Ubuntu’

Installing Ubuntu 9.04: A Designers/Development Environment

Sunday, April 26th, 2009

ubuntu-logo217This is the last type of post I want to write because it involves administration. I *HATE* system administration. It is as interesting to me as car or train maintenance, I just want the damn thing to work. Unfortunately due to some less then intelligent security practices my linux box at home that I used for a development environment had gotten hacked. With the release of Ubuntu 9.04 I decided it was time to dust off the admin skills and upate my environment and also fix some pesky annoyances in my workflow. So since I spent the better part of this weekend researching, copying and installing I figured I would document the process here.

My requirements:

  • Had to run Ruby on Rails
  • Had to support a web server with virtual hosts
  • Had to be able to run WordPress
  • Had to be accessible via Windows
  • Had to be remotely manageable

Now I have been using linux for a long time, so I didn’t evaluate other solutions. It is free, reliable and Ubuntu is relatively painless to administer. That being said, if you have never used linux before I wouldn’t recommend it for a production environment for a beginner, I would however suggest you get a linux box and familiarize yourself with it for down the road.

So with my requirements outlined, I identified that I needed a linux desktop running Apache, MySQL with PHP and Passenger (modrails for Ruby). There are other web servers and database servers (the latest version of passenger runs under nginx) but I wanted to use something that was super well documented and had tons of tools available for any need I might possibly have. Basically I stuck with your standard heavy hitters.

Ubuntu Installation

Ok, so the first thing I did was download Ubuntu 9.04 from www.ubuntu.com. It was an ISO image and I burned it to a dvd. I used the 64 bit version as my development server is 64 it, but I don’t think anything I did should be different with the 32 bit. One thing I do with all my development servers is I remove all the unnecessary hardware. This server is never an actual desktop for me so I took out the soundcard, an extra DVD writer and an extra USB card. I do this just because I am never going to use these features with this machine and the less hardware the less problems with installation/maintenance. I stuck my dvd and went through the default Ubuntu install… nothing special.

Updates

Once I got Ubuntu up and running the first thing I do is update it to include all the latest patches/updates. Bring up a terminal (Under Applications > Accessories) and type the following commands:

sudo apt-get update

and once that is complete:

sudo apt-get upgrade

Now my machine is all up to date.

IP Address

By default your machine should/will probably pick up an IP address from DHCP from your router or some other method. You will want to pick out a static IP address and setup your machine so you can use Apache and name based virtual domains. This is a little tricky to follow so let me break it down:

  1. I want a domain name for each of my client projects that is online all the time (I don’t want to share like 3 generic web servers and upload and download all the time).
  2. I want that domain accessible from any machine inside my network.
  3. I want to have an unlimited amount of domains.

Luckily I can have it all for the bargain price of 8 bucks a year from godaddy. I ran over to go daddy and bought the domain milabs.org (as in My Labs). Call it whatever you want, it doesn’t matter … noone will ever see it but you. NOTE: If you don’t happen to mind having your development server at 192.168.2.15, you can actually use my domain “milabs.org”, but I will get into that in a moment. I registered the domain and used MediaTemple to point a wildcard DNS entry for *.milabs.org to 192.168.2.15, which is the IP address I have chosen for my development machine. Now 192.168.2.* is my internal network so my browser inside my network resolves the domain just fine and points it to my development server, noone else in the world can get to it. Infact if you try to, it will just resolve internally to your own network (that is if you use 192.168.2.* as your network). This is why if we all used 192.168.2.* as our networks and all had our development machines at 192.168.2.15 we could all use the same domains… and hey if you buy a domain and happen to use some other variation like 192.168.1.2 for example, you can post your domain here and others can share that and save a couple of bucks.

SO anyway, I go under System > Preferences > Network Connections and I set my server to use a static IP address of 192.168.2.15

Remote Desktop

I use a primarily windows environment for my “front end”, plus my development server is actually not even plugged into a monitor 99% of the time, so I want to remotely be able to administrate it. I can do so using good old VNC. You can set it up on the server by going to System > Preferences > Remote Desktop and check “Allow other users to view your desktop” and UNCHECK “You must confirm each access to this machine”. Now using windows or mac or whatever environment you want you can a VNC client from many different sources… I would surf around google… there are tons of free ones and each one has some custom features that you may want. I just stick with RealVNC cause it is free and simple.

Once you have your VNC client installed, just fire it up, type in your IP address and you should be able to remotely administer your linux box.

File Sharing with Samba

Ok so now I want to get a share on my windows server that I can do my work on my windows apps (photoshop, illustrator, e) but write to my linux machine so the “work” can be “used” by apache or rails or whatever I am working on. Using Samba you can make linux shares accessible to windows (and vice versa, but I am not going to cover that here).

My configuration:

  • My ubuntu user name is lwallenstein
  • I want to share my home directory as all my work goes into a directory called workspace under my home.

To install samba, run the following command from your terminal:

sudo apt-get install samba smbfs

Once you have completed the installation, you now need to add a samba user and configure that user for access.

sudo gedit /etc/samba/smb.conf

and search for:

;  security = user

and replace (uncomment and add an additional line) it with:

security = user
username map = /etc/samba/smbusers

Save the file.

Next we need to add a samba user. I suggest to keep things simple, you use your ubuntu user name for your samba user name. My user name is lwallenstein, you will obviously want to replace this with your user:

sudo smbpasswd -a lwallenstein

We then need to add a user map to tell it “this samba user is the same as this ubuntu user”. This is why I use the same user name, it makes things simple.

sudo gedit /etc/samba/smbusers

Add your user account in the format <ubuntuusername> = “<samba username>”, so for example mine would look like:

lwallenstein = "lwallenstein"

Save the file.

Last thing we need to do is share our home directory on linux for the windows servers to be able to find:

sudo gedit/etc/samba/smb.conf

Find and uncomment below three lines


[homes]
comment = Home Directories
browseable = yes

and add the following line directly underneath browseable = yes:

 writable = yes

Save the file.

Thats it. All we need to do now is restart Samba and you should be able to see your shares under your Network on your windows machine:

sudo /etc/init.d/samba restart

Ruby On Rails

So I have many Ruby on Rails projects going on. I don’t want to run mongrel or thin for each one, but just like with my client web servers I want them to be “on” all the time. So this is super easy to do with Apache and Passenger, but before I get there, I have to install Ruby, Rubygems and Rails:


sudo apt-get install ruby irb rdoc ruby1.8-dev libopenssl-ruby imagemagick curl
wget http://rubyforge.org/frs/download.php/55066/rubygems-1.3.2.tgz
tar xzvf rubygems-1.3.2.tgz
cd rubygems-1.3.2
sudo ruby setup.rb
cd /usr/bin
sudo ln -s gem1.8 gem
sudo gem update --system
sudo gem install rails passenger mongrel capistrano

This simply installs Ruby, gets rubygems, installs rubygems, does a symlink for the command gem1.8 so it accessible by the command “gem” and then installs the rails, passenger, mongrel and capistrano gems.

Apache

Ok so now we have our machine, with its nice shares and RoR running. Of course the power in this setup is the ability to have customer web sites so that like if I have customers Apple, Bannanas and Orange I can get to their sites at http://apple.milabs.org, http://bannanas.milabs.org and http://orange.milabs.org. So next we need to install and configure apache (with PHP and Passenger/Modrails):


sudo apt-get install apache2 php5 libapache2-mod-php5 apache2-prefork-dev libapr1-dev
sudo passenger-install-apache2-module

Next we need to configure Apache to load the Passenger module (and use a development environment as Passenger uses a production environment by default):


sudo gedit /etc/apache2/mods-enabled/passenger.load

and add the following lines to the blank file:


LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.1/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.1
PassengerRuby /usr/bin/ruby1.8
RailsEnv development

Save the file.

Restart Apache so it will load Passenger:

sudo /etc/init.d/apache2 restart

You may get some errors about not reliably being able to determine the server’s fully qualified domain name, you can ignore them. They are just warnings and are benign.

Now we are done with Apache, but before I go into configuring client environments, lets get MySQL installed and out of way.

MySQL

MySQL is pretty simple to straight forward to setup. I setup MySQL in my development environment using the user root with a blank password:


sudo apt-get install mysql-server libmysql-ruby php5-mysql

Virtual Hosts/Client Configurations

Ok, this is what makes it all worth while. For each client we want a development environment so that we can use:

http://clientname.domainname.com

to access their files, whether it be a static web site, a ruby project, a wordpress installation… basically a web project.

Now we configured the server to a static IP address and registered a domain name and using a wildcard DNS entry we pointed the domain to the server. This mean *.domainname.com will resolve to our development server. * being anything. So using the wild card we never have to think about DNS again… it just resolves anything I type in to the server and NOW Apache will decide if there is data configured for that domain name and respond if there is.

For each of my clients I need to setup a virtual host configuration. This is fairly simple:


cd /etc/apache2/sites-enabled

For each of my clients I need to create a virtual host file using and tell Apache what domain name I want to use and where to point it. For my example I am going to make a virtual host for a company I work with called Kiobo. So I create the file:


sudo gedit kiobo

and in the file I am going to tell it to respond to kiobo.milabs.org and point it to my kiobo files in /home/lwallenstein/workspace/clients/kiobo/www

<VirtualHost *:80>
ServerName kiobo.milabs.org
DocumentRoot /home/lwallenstein/workspace/clients/kiobo/www/
</VirtualHost>

Save the file.

Restart Apache for the new virtual host to be loaded (ignore the warnings)

sudo /etc/init.d/apache2 restart

Now if I use my browser on my windows box and go to http://kiobo.milabs.org I now see my web site I created for Kiobo. I can edit the files using my E text editor on Windows and Apache will use PHP or Passenger/Modrails to do any development processing.

Thats It!

UPDATE: I got this in an email andI am sure it will be helpful to some of you, so I thought I woudl share:

Joseph Barnes of RAD Solutions, Inc. wrote:

I tried a little trick since I didn’t have a fixed IP address.  I registered a domain with HostMonster.com  then I changed the DNS servers to FreeDNS and pointed them back to the same servers/ip addresses as they were when HostMonster resolved them.  Then I added a subdomain DNS server using Dynamic DNS, install Bind 9 configuring it to resolve internally and externally separately using view.  To add additional virtual apache servers for each contract I used ispconfig 3 which allowed virtual apache, ftp and mail for each contract/client.  Unfortunately Comcast scans the ports so I had to get the log from my router and block the Comcast security but by then they had blocked my dns and mail ports which I had to switch to alternate unblocked ports.  It’s an alternative but was a pain to figure out why internal and my dmz things resolved but didn’t from internet.

About Lynn Wallenstein

I create things and make things better. Thats and interesting title huh? Well thats what I do. I head my own freelance/consulting firm, Powered By Geek. I am the main idea gal and I make things pretty. This blog is where I ramble about all things design, code, project or whatever both for PBG and for my collection of personal projects.

Contact Me
My Portfolio
Buy Me a Coffee