How to Configure Apache2 to Allow Drupal to Rewrite Paths

 by jakedimare- September 10, 2011

In this Rackspace Recipe we’ll configure a ‘sites-available’ file in Apache2 in order to allow Drupal (or WordPress) to rewrite paths. After installing a Drupal site on a Rackspace Cloud server for theĀ  first time, chances are you’ll notice it is not possible to enable the Clean URLs feature. This is most likely because Drupal doesn’t have permission to rewrite the path.

Fortunately, this is a very simple issue to correct. In order to gain access to the sites-available file for the site in question, it is necessary to log in via SSH or shell access on a Unix, Linux or a Mac. You can also access the shell by logging into the Rackspace cloud management console for your account. If you are trying to access SSH via a PC I recommend PuTTY.

All of the Rackspace Recipes on betaprogrammer.com reference the specific installation we’re currently using, which is Ubuntu server running apache2. Some differences may exist on other specific configurations.

Each site we publish on our Rackspace server uses a unique sites-available configuration file. These ‘files’ are located in a specific location by default: /etc/apache2/sites-available. Once logged into the server, type the following:

CD /etc/apache2/sites-available (enter)
sudo nano yoursitename (enter)

Once you’ve opened the specific site configuration file add the following:

<Directory /var/www/example>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-fsu
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

Of course, change the directory from ‘example’ to the actual directory for the specific site in question. Once this is complete use control-x to exit nano and be sure to save the file under the same name. Once out of the site it couldn’t hurt to restart apache with the following command:

sudo /etc/init.d/apache2 reload

In order to determine success, simply log into the Drupal site and check to see if it is now possible to enable clean URL’s. (/admin/settings/clean-urls)

If you don’t have a lot of experience working in sites-available configuration files it is a good idea to start by saving a backup of the file contents. This way, if anything goes wrong, you can quickly revert back to the way it was before you started.

This technique can also be used to make it possible for a WordPress site to create simple paths. However, the code for WordPress is slightly different:

<Directory /var/www/example>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>

Launching a fresh Drupal Installation on Linux with Drush

 by jakedimare- March 8, 2011

Care to venture a guess as to how easy it is to launch a fresh installation of the Drupal CMS? Would you guess 50, 25 or 12 steps? How about 8 steps? Believe it or not, that’s right. In this Rackspace Recipe we will review just how easy it is. This tutorial assumes you’re working on a Linux server with the LAMP stack and Drush previously installed. It also assumes you are logged into the shell with sudo permissions.

  1. Navigate to the root web folder by typing: ‘cd /var/www’
  2. Download the latest version of Drupal by typing: ‘drush dl drupal’
  3. Rename the Drupal folder by typing: ‘mv drupal-XXXX newsitename’
  4. Type ‘cd newsitename’ and open permissions for installation with ‘chmod -R 777 . ‘
  5. Create a database in mysql with the name of the site
  6. Update sites/default/settings.php with the correct connection string
  7. Run the install.php file
  8. Change permissions back to 755

Drush is an incredible tool which I could talk about for days, if I fully understood it. This is literally just the tip of the iceberg. To take this one step further…what if you wanted to add a bunch of modules to your new Drupal site? That’s pretty easy too. For instance…you could download an unlimited number of modules using Drush dl (download). Example:

drush dl cck views views_slideshow ctools views_bonus adminrole advanced_help panels admin_menu jquery_update pathauto print nodewords page_title globalredirect path_redirect taxonomy_manager node_import menu_block custom_breadcrumbs ckeditor filefield imageapi imagecache imagefield lightbox2 emfield messaging token webform google_analytics service_links date calendar devel backup_migrate jquery_ui nodequeue context context_reaction_theme views_arg_context cmf content_taxonomy menutrails image

The trick here is to be within the folder containing the site you want these modules to populate.

Installing LAMP on an Ubuntu Server

 by Jake DiMare- February 1, 2011

In this Rackspace Recipe we’re going to map out the process for installing LAMP (Linux Apache MySQL PHP) on an Ubuntu server. This will all be done from the command prompt or shell, as it is called in Linux and Unix. If you are attempting to connect to a Linux machine from Windows I suggest using PuTTY. On a Mac or Linux machine, simply open the shell utility and log in to the server with SSH using the credentials provided by Rackspace.

Once logged in:

  1. Type ‘sudo apt-get install apache2′ (yes, it will download and install the package)
  2. Type ‘y’ when prompted
  3. Test Apache by opening a web browser and entering the IP address of your machine.
  4. Type ‘sudo apt-get install php5 libapache2-mod-php5′
  5. Type ‘y’ when prompted
  6. Type ‘sudo /etc/init.d/apache2 restart’
  7. Create a file called using ‘sudo nano /var/www/testphp.php’ enter the following line: <?php phpinfo(); ?> and then click control x to close and save the file.
  8. Open a browser and navigate to http://yourserverip/testphp.php. If you see the PHP diagnostic page you’ve successfully installed PHP.
  9. Type ‘sudo apt-get install mysql-server’
  10. During the install you’ll be prompted to enter a password.
  11. Test mysql by typing ‘mysql -u yourusername -p’
  12. Enter your password when prompted. If you get a mysql prompt you’re done!

As you can see, without testing this process is complete in less than 12 steps and it is free. I began my career on working at a Windows shop and I was amazed at the speed and ease of using a command prompt once I learned a few simple concepts.

Floating in the Rackspace Cloud

 by Jake DiMare- February 1, 2011

I recently began migrating my own websites from a typical managed hosting service to the Rackspace Cloud in order to save money on hosting. I was surprised to discover unparalleled customer service, efficient administrative interface and a completely reliable, fast server. As a result I have decided I am going to use the cloud for my client’s needs whenever possible.

Before you start migrating all your sites, it is important to mention that a cloud server is no different from setting up a server in your own home or office (other than the location of the machine). You will need to administer every aspect of the machine, including security. Although Rackspace customer service is incredibly helpful, it is important to understand the fundamentals of server administration. I thought it would be fun to explain some of things I am learning along the way.

Everything I will share in this series I plan to tag as “Rackspace Recipes” will be based on my own experiences setting up and running LAMP on an Ubuntu Linux server. I’d like to point out they offer a variety of choices which might be better suited for your own specific needs.

Today we’ll take a real quick look at how easy it is to set up a new Ubuntu Linux server in the Rackspace cloud. It couldn’t possibly be any easier:

  1. Set up a new account with Rackspace Cloud
  2. Login
  3. Click Hosting
  4. Click Cloud Servers
  5. Click Add Server
  6. On the first tab you will see options for Linux servers. I use Ubuntu 9.1
  7. Give your server a name
  8. Select a server size. It’s OK not to be perfect here because you can adjust it on the fly later. I started with 256 but 512 is probably the minimum size for a server running multiple Drupal web sites.
  9. Click Create Server

That’s it! You now have a Linux server. In our next Rackspace Recipe we’ll explore installing the LAMP environment.

Uploading files using PHP and HTML

 by Jake DiMare- September 9, 2010

This week we’ll take a look at manipulating files and folders in PHP by creating an upload form component. Our example will apply PHP filesystem and directory functions and is 100% functional. Feel free to use it on your own project or modify as you see fit. The files are located here.
(more…)

Super Clean Base WordPress Template

 by Jake DiMare- September 2, 2010

Logically, most designers want to pack their template with lots of cool features in order to makes them more marketable. My idea is to give you something really basic and let you take it from there. (more…)

Basic use of recursion, arrays and loops

 by Jake DiMare- August 25, 2010

In this article we’ll explore using PHP to calculate whether a given number is prime and then calculate & display all the primes between 0 and that number. For those who slept through math (like me) a prime number is a natural number only divisible by 1 and itself. This problem is excellent for computers because the easiest solution is to check every number between 2 and the number in question. The resulting program is a great example to demonstrate how to use recursive loops and build an array. (more…)

Using Modulus to Build Dynamic Tables in PHP

 by Jake DiMare- August 19, 2010

Yesterday, after wrapping up the piece on calculating the Fibonacci sequence I wasn’t happy about the long vertical presentation. It was a missed opportunity to talk about a cool trick someone taught me years ago for generating tables with a variable number of columns using the modulus operator. (more…)

Calculating the Fibonacci number with PHP and HTML

 by Jake DiMare- August 18, 2010

In this article we’ll take a look at some very basic programming with math using PHP and HTML to calculate the Fibonacci number. The sequence of the Fibonacci number is calculated by starting with 1+2=3 and then continuing on by adding the sum to the preceding number after each pair. For example, 1+2=3, 2+3=5, 3+5=8, etc. (more…)

Basic Layout Fundamentals with HTML5 and CSS3

 by Jake DiMare- August 13, 2010

Here it comes…HTML5 and CSS3 will most likely be widely supported by this time next year in all of the major, current browsers. It will probably take a little longer for large scale acceptance …Microsoft is going to have to dump IE6, 7 and 8 for that to happen. But, if you are a working web developer with real world requirements, it is probably the right time to start thinking about how you will put it to work. (more…)

Older Posts »