Tuesday, March 29, 2011

Multiple domains and subdomains in Apache2

If you want to host multiple websites and have one server running Apache2, it's pretty simple to setup virtual hosts so that each domain and subdomain will show different content. You'll need to point your domains and subdomains to the IP address of your server first, as DNS takes some time to update. Once that is done it's just a matter of configuring Apache.

You'll want to find your sites folder, it should be /etc/apache2/sites-available  Here you can either edit the default file or create your own. The advantage to creating your own is being able to enable/disable parts of your configuration rather than the whole thing. Either way, below is what you need for each domain/subdomain you wish to configure:

<VirtualHost *>
        DocumentRoot "/var/www/subdomain/"
        ServerName subdomain.cezary.com

        <Directory /var/www/subdomain/>
                Options Indexes FollowSymLinks MultiViews +Includes
                AllowOverride None
                Order allow,deny
                allow from all

What does all that do? I'm glad you asked.

DocumentRoot  is the local path to your content
ServerName  has to match the domain or subdomain of your site
<Directory ...>  contains options and settings for your site. The ones listed here are pretty standard. Modify these to your liking.

You'll want to make a new <VirtualHost *> entry for each domain and subdomain you host. If you put this configuration in the default file then you are almost done. If you made your own file then there is one more step. You need to enable your custom configuration file. You can do this with the following command (as root):

a2ensite xxFILExx

Where xxFILExx is the name of your own config file. And that's it! Now you just need to tell Apache to reload the new settings.

/etc/init.d/apache2 reload


Friday, March 25, 2011

Generating QR codes

To generate a QR code on your page simply insert the following:

<img src="http://chart.apis.google.com/chart?cht=qr&chs=100x100&chl=xxxURLxxx" width="100" height="100" />

Replace xxxURLxxx with the link you want. You can also change the size, but 100 by 100 is usually large enough to accommodate most URLs.

If you want to dynamically generate the QR code, you can replace xxxURLxxx with PHP like so:

<img src="http://chart.apis.google.com/chart?cht=qr&chs=100x100&chl=<?php echo $varURL; ?>" width="100" height="100" />

Wednesday, March 9, 2011

How to install cURL

If you are making your first shopping cart, crawler or simply need cURL to make existing code work, here's how to get it.

First things first, check to see if cURL is already running. Create the following PHP page:
Visit that page and search for "curl". If nothing is found, you don't have cURL. A proper installation should have a reference under "Additional .ini files parsed" as well as a section called "curl" with all the details.

There are several ways to install/enable cURL, depending on your setup. Here are the two most common:

LAMP (as root or using sudo)
apt-get install curl libcurl3 libcurl3-dev php5-curl php5-mcrypt
XAMPP (edit xampp\apache\bin\php.ini and uncomment or add this line)
In either case you'll need to restart Apache to load cURL after the installation.

To verify the installation, go to the PHP page you created and search for "curl".

Friday, March 4, 2011

Manage Your Code Deployment: Subversion To Web Server In One Click

Here's the simplest way to push a folder out of your repository onto your web server for testing.

$result = array();
$command  = 'svn export ';
$command .= 'https://your_server/svn/project /path/to/www ';
$command .= '--username USER --password PASS --force ';
$command .= '--non-interactive --trust-server-cert';
exec($command, $result);

- Host name HAS to match certificate (where I have "your_server")
- check .htaccess files, mod rewrite, ensure permissions are 755 and www-data is owner
- Version # can be forced with -r switch (svn -r 5 export ...)