Adding Virtual Hosts to Ubuntu Apache

Now that I have Ubuntu installed and the Apache server working, I need to configure some Virtual Hosts. I have several names registered at dyndns.com that all point to the same IP. Right after you get Apache going, it defaults to serving from a default location, in this case /var/www. Any http requests coming into the box are all routed to that directory.

But Apache can support multiple virtual hosts. So if I route say example1.dnsalias.com and example2.dynalias.com to my IP via dyndns.com, I want them to be each served from their own directory. The default /var/www has system ownership and would need to be changed. So I’m going to create a directory for each site under my user directory. So I’ll create /home/bruce/sites/example1 and /home/bruce/sites/example2 to host the files for each site.

Now we need to make Apache use them. In the default configuration, Apache is already set up to support multiple virtual Hosts. In order to get the new sites working, we need to create a couple of configuration files in the /etc/apache2/sites-available directory, then enable them, and then restart Apache.

If you look in the sites-available, you’ll find a file called default. This represents the default Apache serving configuration. Copy this file twice to serve as a basis for the new configuration files. sudo cp default example1 and sudo cp default example2. You need to make two or three changes to each of these files, and add one line. There’s a line in the file tagged ServerAdmin. If you want, you can make the value a real e-mail address. There are also two lines labeled Document Root and another in a %lt;Directory> statement that have the path to the directory being served – in this case, it should be /var/www/. Change both of those to the directory that will contain the new site files – /home/bruce/sites/example1/ and again with example2.

Almost done. Now after the ServerAdmin line add a new line:
ServerName example1.dynalias.com and again with example2 file. Use whatever actual domain names you’ve registered with dyndns.com or other dynamic name server you’re using.

So now in addition to the /etc/apache2/sites-available/default file, you’ll have two more files – example1 and example2, which have been modified to point to the actual hosting directories, and with the appropriate domain names.

Now we have to tell Apache to serve the new domains. Ubuntu has a couple of convenience commands to enable and disable sites. So, to enable the new sites, enter sudo a2ensite example1 and again sudo a2ensite example2. These commands copy the configuration files you created into the /etc/apache2/sites-enabled directory. We’re almost there.

Finally, you have to restart Apache2 so that it reconfigures to serve the new sites. Simply enter sudo /etc/init.d/apache2 reload.

Be sure there’s an index.html file with some content in each of the
/home/username/sites/example1 and example2 directories. Now if you enter http://example1.dnsalias.com to a browser, you should see the contents of the appropriate file.

I hope I’ve made these steps pretty clear. It really isn’t that hard.

  1. Create directories to host the content of a new virtual site.
  2. Make a copy of the /etc/apache2/sites-available/defaults file with a site appropriate name.
  3. Change the two /var/www/ entries to the actual directory of the new site.
  4. Add the ServerName line with the real domain name you will be hosting.
  5. Use a2ensite to enable the new site, and finally reload Apache2 so it knows about the new site

[Update 4/19/2010] – Don’t know exactly, but these directions seem to not work if you have more than one virtual site plus the default site. I could only get one specific virtual site to work when the “default” site definition was also there. But, if I a2dissite default then all the other sites I specified and a2ensite enabled work. Don’t quite get it, but I guess that’s ok  because a default site isn’t all that useful unless it is your only site.

You can host as many sites as you want, but the free version of dyndns.com only allows up to five names. And if you don’t create a new site configuration file for a domain directed to your Apache server, it will go to the default at /var/www/.

If all this works, it should just take you five or ten minutes for each new site. But it is easy to make a tiny mistake, and things then don’t work. There are plenty of other sources of information about configuring an Apache Virtual Host. I’ve tried to summarize as simply as possible, but if things go wrong, try another set of directions.

Next, we will test the MySql installation, maybe do some configuration. Then we test PHP. Finally, we’ll try to get sendmail working, although that may be the hardest thing to do, and isn’t really essential unless the apps you’re building or testing need to originate e-mail.

[Update 6/16/2011] – I’ve just configured a real, live Centos Linux on a VPS. All this stuff about creating a virtual host seems to have gotten easier, at least on the Centos implementation. Don’t know if all this stuff is still needed on Ubuntu or not, but on Centos, all the servers are defined in the single file: /etc/httpd/conf/httpd.conf. Much easier.

Advertisements
Posted in LAMP | 13 Comments

Adding LAMP to Ubuntu Desktop

OK, next step, adding the “AMP” (Apache, MySql, PHP) to the “L” (Linux) in the desktop version of Ubuntu 8.10. I’m actually writing this as I do this, so what I say now might turn out to need tweaking. But, I’ve got my 8.10 desktop installed, updated, and have made a few personalization one normally makes. Now I found this page at the Ubuntu site that looks as if it has all the info. So we’ll follow along and see if what that page say really works.
So, step one: from a terminal, enter: sudo tasksel install lamp-server

Took about 3 minutes, had to enter MySql password in the process.

So, now I open Firefox, enter the local address (http://localhost/) and there it is! The install worked. Total time, less than 10 minutes. But we’re not done. Need to talk to the outside world now, and set up virtual hosts so we can get in multiple ways on multiple test web sites.

So since I had my previous version set up to host a domain (using dyndns.com, more on how to do that later), I tired entering that name – nope, doesn’t work. Need to fix something. Tried my machines current real IP address. Nope. Think I might have to fix the router tables. As part of the install of Ubuntu by Fusion, each VM gets its own MAC address, which is what the router uses to assign a local IP to connected machines. So I use “ifconfig” to get my current VM’s IP.

So now I’m in the router admin panel, and there is the ubuntu machine listed in the LAN computer table. Now I have to change some settings for the router’s virtual server tables. This will likely be a bit different on each router, but on my D-Link it is under the Advanced tab. I need three entries – HTTP, HTTPS, and SMTP. These need the correct Port numbers (HTTP: 80, HTTPS: 443, and SMTP:25) and the IP address of the Ubuntu VM box. AND THAT DID IT! I can now talk to the Apache server from any outside computer using a real URL.

[UPDATE: 4/19/2010] This works with an Apple Airport, too, but the getting to the settings is a bit different. Use the Airport Utility. Go to the “Advanced” tab, pick port mapping. Now use the “+” button to add the three above services – Personal Web Sharing, SMTP Mail, and Remote Login – SSH for https (I guess – couldn’t find another way to do that one). Then use the local IP of you Ubuntu box instead of the default provided by AirPort Utility, and your all set.

By the way, the actual location of the web site in the filesystem: /var/www

Total time, including writing this, 20 minutes. This seems MUCH faster than the last time I tried this, but I know more what I’m doing. Like all that business about the settings on the router – easy now, but I think it was hard the first time.

So, what’s next? We’ll set up a couple of extra Virtual Servers so it is possible to create and test multiple web sites. Then we need to make sure MySql is working properly. Finally, we will be sure PHP 5 has all the libraries and features installed and customize some of its settings to match those on my real host.

So, how did I get a real URL to talk to my Ubuntu virtual machine? You need to use a dynamic IP server that maps a URL to a physical IP address. I use dyndns.com. They have a totally free service which requires you to manually confirm things once a month. Or you can pay a little, and it doesn’t nag you.

Here’s how it works. You actually are using a real IP address to connect to the web from your house. This address is assigned by your ISP in some manner. The main thing is that the address is not normally permanent. It most probably will change from day to day. So if you want to talk to your server from the outside world, you have to be able to map a permanent URL to a real changing IP address. This is what dyndns.com does (and there are others, but I’ve had excellent look with dyndns.com).

It provides a bunch of main domain names like “dnsalias.com” and a bunch of others. You get to choose from those and create your own sub-domain on that – for example: mytestsite.dnsalias.com. You also need to keep dyndns.com updated with your real IP. Depending on your router, this isn’t that hard.

Most current routers already know about dyndns.com (and others, but dyndns.com seems to be the best supported by routers). You set them up to automatically report your current IP to dyndns.com. I won’t give all the details because they differ, but that’s the main idea – set up a dyndns.com domain (or several), set up your router to auto-update the IP, and you’re ready to have the world talk to your Ubuntu server.

If your router doesn’t have this, they have DynDNS update clients that run on Windows, Mac, and Linux. Dyndns.com says the software clients are better, but I’ve never had any difficulty with my router based version. (On the other hand, my comcast assigned IP doesn’t seem to ever change unless I have a power glitch or otherwise have to reset the router, and even then I sometimes get the same IP.)

So there we have it – while I’m addressing building a Mac Fusion Ubuntu Virtual Machine LAMP server, essentially everything I’ve covered would apply equally to a fresh install of Ubuntu on real hardware. But it is so nice to have everything right there on one physical machine. Part of why I really love my Mac.

Next time – tweaking Apache, adding Virtual Hosts.

Posted in LAMP | Leave a comment

Building A Fresh Mac/Ubuntu Development Platform

As I said in my previous post, I’m going to build a fresh development platform. Part of this was prompted by the fact that my old installation started having some issues, and that the latest VMWare Fusion for the Mac has added some support for Ubuntu 8.10.

So, here’s my starting point. Mac OS 10.5.6, VMWare Fusion 2.02, Ubuntu Desktop 8.10 (I need the desktop, so the server version is not the right choice), Komodo IDE 5.0.

My goal is to describe every step of the process in getting the new Ubuntu VM configured properly – this involves the initial installation, adding LAMP, getting it configured to be a virtual host to a few domains, getting e-mail to work properly to send out e-mail, installing the Linux version of Komodo IDE, and getting the debugger to work properly (This means accessing the Ubuntu hosted site from a browser running in the Mac OS X environment while using Komodo on the Ubuntu platform to edit and debug). My past experience has shown that getting the getting Apache set up properly with correct permissions, getting e-mail to work, and getting the debugger to work were the hardest issues.

So, step 1 – Initial configuration of Ubuntu 8.10.

I downloaded the 8.10 desktop ISO and started Fusion and created a new VM. It knew how to mount the ISO, and did an “easy install” – that is I only provided the virtual disk size, my user name and password, and after a while, the Ubuntu VM was up and running. Easier than earlier versions. Right after installing, you can install the updates. It is pretty much totally automatic.

After it is installed, you still have to install the VMware Tools package so that stuff works better with the VM (at least I did). That takes a little effort. You tell Fusion to install the Tools from the Virtual Machine menu. That mounts and opens a virtual CD on Ubuntu. You have to then copy the tar.gz file to a non-read-only place – like /tmp.

Then you extract the tar.gz file, and open a terminal. cd to /tmp/vmware-tools-distrib, and then “sudo ./vmware-install.pl”. Answer all the questions, the defaults are almost always right. And in 5 minutes, it is ready to reboot, and the system will properly resize the screen and other stuff.

Next it is time to install LAMP. Next post.

Posted in LAMP | Leave a comment

New projects – WordPress-based websites

Ok, looks like the AWS stuff won’t be happening anymore. Just didn’t have the energy to keep going on a new project of that scale. So now what?

Well, my son has a band, and it is very good. Good enough to make it to the big times if one can believe what almost anyone who hears them says. So, to help get his band going, I’m improving their current website, and building new ones.

By the way, the band is called IVORY DRIVE, and the main web site is IvoryDrive.com.

Guess what? After a bunch of research and design, I’ve decided that the very best way to build a website these days is with WordPress. Really! While it is blog oriented, you can really build that is completely page oriented with no blog at all if you want. A jillion add-ons are available, and it is pretty easy to find or create a site style template to get exactly the look you want.

My current mini-project, for example, is converting IvoryDrive.com which is currently a hand-built site with Dreamweaver to a WordPress based site. The band likes it style, and the main effort will be creating a custom WP theme that matches exactly the original. I think it will be entirely possible to do that. That’s how flexible WP is. And after that, it will be much easier to maintain the web site.

In order to do that, I’m going to make things a littler more complicated than I need to – partly just to keep up with things. In order to make it easier to develop the new theme, I’m going to rebuild my testing server from scratch.

My development environment is a Mac with VMWare Fusion and a bunch of VMs. I’ve had a testing server built before, but for reasons I can’t easily figure out, PHP has quit working, and it is an old version of Ubuntu. So rather than upgrade, I’m starting from scratch. And I’m going to document that in upcoming posts.

Just a quick note – after 30 years of software development, I’ve found what I think is the perfect development platform for any web based software: A Mac Pro, VMWare Fusion with VMs for every OS I need to support, Komodo IDE, and a Ubuntu Desktop/Server LAMP environment. I’ll talk about that later, but next is getting a fresh Ubuntu 8.10 Desktop/Server up and configured.

Posted in Web Development | 1 Comment

Summer’s over

Okay, I have to admit I pretty much took the summer off. But now I’m back to work.

So, there should be some more entries to follow fairly soon.

Posted in General comments | Leave a comment

My New Open Source Library for Amazon SimpleDB

My last post was about Amazon Web Services. I’ve spent the last week getting up to real speed with SimpleDB, their data base product.

Actually, AWS is really bleeding edge now. Some of their major components, including SimpleDB, are still in Beta. And now I’ve learned what a “limited Beta” is: it means they let a limited number of people sign up, and then cut off more users. I found out the hard way that Simple was a LIMITED beta. But, fortunately, with a bit of begging, I managed to get authorized to use the service.

Part of bleeding edge is a serious lack of general previous experience. When I started on my current web project, I decided to use what is called a LAMP development environment: Linux, Apache, mySQL, and PHP. Because this has a well-established user base, there’s lots of open source code and other tools available for development. You don’t have to start from scratch. (That doesn’t mean there’s not a lot of crap out there, but you seldom have to start from nothing.)

Not so with AWS, and especially SimpleDB. Amazon has provided pretty good documentation, but it is mostly about how SimpleDB really works, and its API. That’s all based on web transfer protocols. This really isn’t PHP. And Amazon has a bunch of basic libraries that implement the API protocols in several programming languages, including PHP. (That’s one plus for AWS – they use web protocols that can be implemented in practically any web development programming language.) But the interface libraries really take the AWS SimpleDB view of the world – they aren’t far from the AWS API, but are quite a ways from how one usually programs in PHP. Not that they don’t get the job done – it is just painful.

Thus my new library which I’m calling paws for PHP for AWS. Eventually I guess I’ll write versions for the main AWS services, but for now I’ve just released the SimpleDB version. It took me a week, and I think it’s pretty cool. All of the confusing AWS API view is completely hidden away – kind of like assembly language programming vs. a high-level language. Now all you have to do is concentrate on building your data base logic. The code for accessing it is now very easy.

I’ve been doing this sort of thing for over 30 years. I have a feel for what a library should look like for a programmer. I like things simple, and try to take the time to find the simple way of doing things. It is worth it in the end. With a well-designed, easy-to-use class, you can save hours and hours of programming later. Instead of figuring out how to use your tool, you can concentrate on the logic of your application.

So I’m building a proprietary web site – why release this library as open source? Partly because I’m pretty proud of my design, and since no one else has release an equivalent library, it stands a pretty good chance of helping a lot of people, and having a lot of people using it. And if it is a good as I think, it might even become a standard library used by SimpleDB PHP programmers. Before long, there could be other tools based on this library, and the learning curve becomes shorter for everyone. And in the end, I’ll get paid back for my effort far more than if I had kept it proprietary.

And that’s how you get past the bleeding edge.

Posted in Programming, Web Development | Tagged , , , | 3 Comments

Amazon Web Services

I’ve decided that Amazon Web Services is the only (currently) sane way do develop a web site today, especially if one expects/hopes that the site might generate high traffic.

If you haven’t heard about it, check it out at aws.amazon.com. Essentially, Amazon.com is leveraging their $2 Billion investment in infrastructure by making it available to the world. It’s called cloud computing. For very reasonable rates (it isn’t free, but darn near), you can get data storage, a database, and servers. The data storage and database scale automatically, and you can add servers on demand.

So what does this mean? It really evens the playing field. Using AWS (and apparently Google and Microsoft are working on similar platforms), you can build a web application that can easily expand to handle as much traffic as you like, all without you having to invest tens or hundreds of thousands of dollars on a data center. No hardware to buy, no maintenance staff for it, no physical location required — all that stuff required to build a web application that requires a huge upfront investment. It will take a very long time before it would have been cheaper to do it yourself – if ever – than to pay Amazon.

And you don’t have to use all the Amazon features at once – you could use the database and storage and run the app on your own servers, for example. For the applications I build, storage, data base, and servers are the main components. AWS also has some other services such as message queuing.

But what about using an ISP or other web-hosting service? Well, for smallish apps, that is probably OK. But as soon as you start getting thousands or more hits per hour, that solution will start to have problems. This is where the three-part solution might help. If you think there ever is a possibility of getting lots of traffic (or moderate traffic that views lots of data like videos or music), then you could start with your own server or a hosting company, but use Amazon’s storage and data base solutions.

If you are hoping to build a high-traffic site, no matter what platform you use, I’ve discovered there is one secret to designing your application’s architecture. As you get high loads, the solutions available end up spreading the computation and storage issues over many individual servers. Each page you serve to the user will likely come from a single server, but the next page served is likely to come from a completely different server. What that means is that your applications have to be essentially stateless. Whatever state you need from page to page must be kept in cookies on the client computer (hopefully in a secure manner). As long as you remember this basic principle, you application can likely be ported to a cloud environment.

But whatever the details, cloud computing as a service changes everything. Startups no longer need a big upfront investment in server hardware and software. If you can invest some sweat equity in your project, you can easily get going with a few thousand dollars (development machines, usage of AWS, etc.), and not tens or hundreds of thousands of dollars.

Posted in Programming, Web Development | Tagged , , , | Leave a comment

Building a new web site

OK – I’m going to restart my blog here from scratch. I’ve dumped all the old stuff, and will now blog about some of the things I’m learning as I build a new, modern web site. Part of this will be to share what I learn, and so I hope help others. Part will be so I can remember what I did.

I’ve been working on a new web site since late 2007, so far doing everything myself. It has gone a lot slower than I had hoped, but it’s been fun, and I’ve learned a lot. The new site is still proprietary, so I won’t talk much about that, but I will cover some things I’ve learned.

So, just to help me remember what I want to talk about, here’s some topics to come:

1. Basic model for a modern web site: dynamic, easy-to-use, lots of AJAX.

2. Development tools – MacPro + VMWare = Amazing development platform

3. Freeware – use it or not?

4. Amazon AWS – clouds are the future

5. Current state of grammar checking

The last is what is currently driving my work. If you are developing new web sites, and haven’t heard about cloud computing (which I somehow missed until very recently), this is the wave of the future, and at the moment, Amazon’s AWS is about the only game in town. AWS totally levels the playing field for startup web sites, and will really allow for near zero capital startup costs. The problem is that it has a pretty steep learning curve and is still so young that there aren’t as many tools available as you’d like. But the upside is incredible.

Posted in Web Development | Tagged , , | 2 Comments

Reboot!

You may have heard a couple of new terms: digital native, and digital immigrant. Anyone born after 1985 or so is probably a digital native – they’ve grown up with computers all around. The rest of us have had to learn about computers and all things digital – we grew up in a different time.

But I think there is a third category – digital pioneers – and I consider myself a digital pioneer. I’ve been in this business for 30 years now, and actually contributed to how personal computers are used today. I wrote the very first spelling checker for a personal computer, and created the first true grammar checker for computers.

I’ve done a lot of other things, and I’m now back in the startup business – working on a new web site. I thought it would be fun to create a blog about this new venture, as well as share other random thought I have from time to time about the digital age.

Posted in News | Tagged | Leave a comment