Pages

Thursday, September 6, 2012

Updating Drupal 7 to the Latest Version


Updating a Drupal site is vital for security.
In this tutorial we're going to show you how to update your Drupal 7 site from one minor version to another. That means from 7.0 to 7.2 or 7.2 to 7.4. and so on.
Unfortunately moving between major versions such as from 5 to 6 or from 6 to 7 is a much bigger topic and too large for a single tutorial.
Before you start, please remember one thing: backup, backup, backup, backup, backup, backup, backup, backup your site!

Step 1: Check for Available Updates

tutuploadsmedia_1309637650420.png
To get started with updating your Drupal site, click on "Configuration" and then "Available updates".
tutuploadsmedia_1309637693049.png
This page will show you an updates you need to make. They will be marked in red as in the image above. If there are updates, it is worth putting your site in maintenance mode at this point to avoid any problems for your users as you update.

Step 2: Download the Update Files

tutuploadsmedia_1309637713390.png
Drupal will show you a link to download the files for the new update.

Step 3: Upload the Update Files

tutuploadsmedia_1309638026715.png
Unzip the files that you've just downloaded.
IMPORTANT: Delete the /sites/ folder from these unzipped files. Do not upload the /sites/ folder as this will overwrite any custom work that you have done. Make sure that you leave the exisiting /sites/ folder intact on the server.
Then open up your FTP program or file manager and navigate to your existing Drupal site files. Simply upload the new files over the top of the existing ones.
tutuploadsmedia_1309638514359.png
Once the upload is complete, you can refresh your "Available updates" page and hopefully it will now be marked in green rather than red.

Step 4: Run the Update Manager

Drupal Updates
Click on "Modules" and then click on "Always run the update script each time a module is updated".
tutuploadsmedia_1309639399700.png
Click "Continue".
tutuploadsmedia_1309639419498.png
Click "Apply pending updates".
tutuploadsmedia_1309639442264.png
You should now see a page saying the update has been successful with no errors.
Click on the "Administration pages" link and go "Configuration" then "Maintenance mode" to put the site back online.

Wednesday, September 5, 2012

Basic Drupal site configuration


Here I will point out some things that should be done by yourself after you have installed Drupal. It's a basic Drupal site configuration - some things that I always do when I create new Drupal website.
I assume you have installed Drupal on your web server. Installation is very easy, it's a matter of "point and click". Just make sure you create your database before that. More info on Drupal installation can be found in install.txt file that comes with Drupal installation.
So, you've just installed Drupal on your web-server (or your localhost), and now you ask yourself: "Hmmmm..... Now what?". Of course, it depends on the nature of your future website what you want to do with it, but before all that there's some basic Drupal site configuration that I always do, and I suggest you do it as well.
You are presented with a nice blue theme and a welcome message "Welcome to your new Drupal website!" and some additional info on setting up your Drupal website. I suggest you read that text and then do the following:
1. Go on and create your first account by clicking "create the first account." link. That first account that you create will be the admin account for your drupal website! It will have a user id of 1. You can name it "admin" or whatever you like.
2. After that you are back to frontpage of your installation. Go to your admin section, and click on "Modules". On modules listing page, mark checkboxes for the following modules: Contact, Path, Search and Statistics. Click "Save configuration". This will install some additional core modules that are not enabled by default, but I always use them.
3. Enable Clean URLs by visiting admin -> Site configuration -> Clean URLs (you need to have mod_rewrite Apache module enabled for this to work).
4. Go to admin section. If you see a message at the top that says "One or more problems were detected with your Drupal installation. Check the status report for more information.", don't worry about it, we'll fix that in a minute. Click "Site information" and fill in all those fields for your Drupal website. I think they are all pretty much self-explanatory :-)
5. Next, click "File system" in admin section. You will hopefully get a message that "Files" directory was created. Click "Save configuration".
6. Now we need to setup Cron for out Drupal installation. In case you didn't know, cron is a unix process that works in a background all the time and it can execute certain commands for you at any time you tell it to do so. Drupal NEEDS cron job to be set up in order to function properly. So, login to your VPS (or dedicated server) and type following command:

crontab -e
This opens up your cron edit screen. Add the following line to it:

0 9 * * * wget -q http://www.your-domain.com/cron.php
This tells your cron to execute cron.php script at exactly 9am every day. You should be fine with it, although you can choose whatever time of the day you want.
(in case you don't have shell access, and you are on shared hosting, you should have some kind of setting up a cron. I know that in Cpanel you can set up a cronjob very easy, through graphical user interface. If you cannot do that, I suggest you contact you hoisting provider for assistance about setting up your cronjob for Drupal).
7. Ctrl+X and 'Y' and Enter. You should be out of your cron settings program. You can check if you successfully added cronjob by executing
crontab -l
8. Now go back to your browser, to your admin page of Drupal installation. You can run cron manually now, and then you shouldn't do it anymore, since we've just set up a cronjob for Drupal. Now you shouldn’t receive any error messages at the top of the window in admin section.
9. Go to front page of your Drupal website. You are going to create your first piece of content in Drupal.
Create content - > Story
Create it! Be creative ;) Write something just for fun, as we have a little bit more to configure. After you click Submit, your "story will be created. Congratulations, you've just created your first piece of content (node) in Drupal.
10. Go to your webroot directory where your Drupal installation is. Open up your .htaccess file and add following lines to it:

RewriteCond %{HTTP_HOST} ^your-domain.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
or, if you have 'www' part in your domain name, add this instead:

RewriteCond %{HTTP_HOST} ^(www.)?your-domain\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
Save ".htaccess" file.
What this does is that it gets rid of a trailing slash at the end of your Drupal URLs. So, if you type URL with a slash at the end, it will automatically get rid of it. This is extremely important for search engines like Google and your website ranking, that's why we do this.
You should now have a basic Drupal website up and running with minimal number of modules running.
I suggest you now play around your Drupal website, explore the admin section a little bit more, just to see that it's nothing really difficult there. Any questions or suggestions, I'd be happy to read them.

How to make a photo gallery with thumbnails in Drupal


Here we will create a simple photo gallery for Drupal CMS that will have thumbnails listed in a table with 3 columns. First of all, please have a look at how our final result will look like:
Would you like to have something like that on your website? Read on…
The way I made this photo gallery is kind of a hack, or workaround. It might not be the right way of doing it, but IT WORKS, which is the most important thing.
1. Enable following modules: Image, CCK, Views, CCK Nodereference, Path, Pathauto
2. Go to Image settings in admin section and set the options just like on the following picture and save configuration:
Capture1.jpg
3. Create a new content type “Album” with just “title” field enabled. We will just need to enter title for our albums.
4. Go to Pathauto setup and set following options:
For “Pattern for all Album paths:” put “gallery/[title]”
For “Pattern for all Image paths:” put “gallery/[title]”
Save configuration.
5. Create a new view and name it “album_list”, check “Provide Page View”. For URL you can put anything you want. For view type select “Table view”
  • In fields section, add field “Node: title”
  • In filters section add filter “Node: type” and select operator “is one of “ and for value select “Album”.
  • Add filter “Node: published”, for operator select “Equals”, for value select “Yes”
  • Click Save. Now we have our view that we will make a reference to.
  • Go to admin -> content types -> Image
  • Click “Add field” tab
  • Give it a name “album”, and for Node reference select “Select List”
  • On the next screen, for label put “Album”, check “Required”
  • Click on link “Advanced - Nodes that can be referenced (View)”, and for View select “album_list” from dropdown list.
  • Save field settings
6. Now, go on and create a new album”… Create content -> Album. Name it whatever you want, for example “My photos”.
7. Extract the archive attached to this article. There are 2 files “node-album.tpl.php” and “node-image.tpl.php”. Make sure you upload them to your themes/your_theme directory.
8. Now we will add some images to your album. Go to Create content -> Image. Click “Choose” to choose your image. For Album, select the name of your photo album that you have already created ("My photos" or whatever).
9. When you create your image, it will take you to something like
http://www.iwant2visit.net/gallery/amsterdam-1 . The last part of URL is the name of your image.
10. Keep on adding images to your photo album. Don’t forget, every time you upload an image you have to select name of the album that a new image will belong to.
Now you can have as many photo albums as you want and as many images as you want.
You can also experiement and make those pathauto settings to suit your own needs.

How to make Drupal piece of content that refreshes itself every 24 hours


This Drupal tutorial is easy, yet it can come very handy and useful sometimes. For one website, I needed to make one part on the frontpage to display teaser of random article, and refreshes itself every 24 hours. Easy, I thought, I could use block_cache module and that's all. The thing is, I am not using this block on sidebars, I need to display it on the frontpage, and on the specific part of the page... That means I need to display block from the template directly.
After some research, I found out about one module that is called insert_block. Its function is to insert contents of any block from your templates. Of course you can do this with Drupal API, using php code, but this is much easier, and safer.
So, we're going to use a combination of views, block_cache and insert_block modules to display our random content in a block that refreshes itself every 24 hours. This could be useful, for example for your frontpage, to have a "featured article", that will change every day.
Take a look at Overcome anxiety and depression website . At the frontpage in the lower right part, there is a "featured article" That is actually a block that is using one view that randomly selects one article and displays it using insert_block.
I will assume you already have some articles on your website.
1. Enable modules: Views, Block Cache, Insert Block.
2. Make the following view:
  • name it "feat_article"
  • check "Provide Block", view type is "Teaser list"
  • nodes per block: 1
  • in Fields section add "Node: Title" and Node: Body (teaser)
  • in Filters section add "Node: type" is one of "Page" (or whatever your type is) and "Node:published" equals to "yes".
  • in "Sort criteria" select "Random" from dropdown menu, and add criteria.
  • Save your view.
3. Go to Administer > Site configuration > Input formats
4. We will use "Full HTML" input format, so click "Configure" next to "Full HTML"
5. In Filters section, check "insert block filter" and Save configuration.
6. Now, go to Administer > Site building > Blocks. Find block "feat_article [[-CACHED-]]". Click "Configure". Uncheck everything and for the "Cache lifetime" put 86400. That is the number of seconds our block will refresh itself. 86400 seconds = 24 hours. So our block will refresh itself every 24 hours. If you need different interval, just find out how many second it is and put it in. Save block.
7. Find out what is delta number of "feat_article [[-CACHED-]]" block. Hover over "configure" link next to "feat_article [[-CACHED-]]" block and see the number at the end. Write down that number, you will need it in a second.
8. Go to your template where you want to insert this block. For the frontpage I use regular page content type. The syntax for inserting a block is:
[block:name of module=delta of block]
So if your delta number of block is 20, your syntax would be:
[block:blockcache=20]
For input format select "Full HTML".
9. Save everything.
Now you should have your piece of content refreshed every 24 hours automatically. The more nodes you have, the better. It will randomly select one node and display its teaser for the following 24 hours. It's pretty cool stuff.