Glad you could stop by the Linux Basement site. Linux Basement is an informational Podcast about Linux, open source software and lots of other wonderful technology. If you want to find out more about open source technologies, subscribe and have a listen!

#linuxbasement is up at irc.freenode.net

MP3 Feed
Ogg Vorbis Feed
MP3 Feed (all episodes)
Ogg Feed (all episodes)

Video blog (not the show!)

 

Installing Drupal

Welcome to the Installing Drupal Tutorial. This tutorial assumes that you have already installed LAMP on your Linux Desktop in some way shape or form. I will be using Ubuntu Gutsy, and I've already removed the apache2-default/ folder from my /var/www folder on my LAMP install by moving to the directory:

cd /var/www

and doing:

sudo rm -r apache2-default/

 now if you do a ls on your /var/www directory, you should see nothing, because it should be empty. If you've gone ahead and created an index.html file so you could see it being served off of your localhost, like i suggested in episode 2, then good on yah! However, to install drupal, you may want to delete that now. If you've grown attached to it, you could create a subdirectory like /var/www/drupal and install drupal there instead, so that your web address would then be http://localhost/drupal

However, for the purposes of this tutorial, we will be installing drupal under the root of our web directory, which in Debian distributions(like Ubuntu) is /var/www

The first thing we need to do, to make administering our MySQL databases easier, is to install a package called phpmyadmin. Phpmyadmin gives you a web interface you can log into to administer your Mysql databases. You could also do this on the command line, but I find beginning users like the graphical user interface of phpmyadmin, and so that is what we will cover in this document.

To install phpmyadmin, do the following on the command line:

sudo apt-get install phpmyadmin

It will prompt you about which type of web server we are running. You want to select the first choice, which is apache2 and hit ok. That's it!

Now, if you got http://localhost/phpmyadmin you should see your new phpmyadmin login screen. To login, you will use the username "root" and the password is the password for your mysql installation. You were prompted to enter this password durring your mysql installation.

phpmyadmin login

Once you are logged in, you should see the phpmyadmin main page. We are going to create a new user, and a new database all at the same time. To do so, go to the Privileges page, the link is near the bottom of the page.

phpmyadmin main page

The privileges screen will show you the users on your system. Right now since this is a fresh install, there will only be several default users, including the root user we used to login with. Please select "Add a new User".

add a new user

Now we create a new mysql user, and a new database all at the same time. Use the following Criteria:

User name:drupal
Host: localhost
password: whatevayouwant **please note in a production environment, this should be a strong password different from your root password.**

Database for user should be changed to "Create database with same name and grant all privileges." This will create a database with the same name as the user that you are creating. In our case, Drupal. This user does not need any Global privileges. Click GO to save your settings at the bottom of the page.

adding a new user and database

 

That's it. You now have an empty database called drupal, with a user in Mysql called drupal, that has full rights to the database. You should see drupal (0) in the databases dropdown menu. Now that we have a database ready and waiting for Drupal, its time to go install it!

 Time to head over to drupal.org and get the latest stable release of Drupal. As of this writing, that is Drupal 5.3. When working in the command line, I find it easiest if you right click on the direct link and do a "copy link location." Then when you go back to your command line you can right click and past, or middle click the direct path to the download which pastes it in the command line. So you want to do the following to download the package.

sudo wget http://ftp.drupal.org/files/projects/drupal-5.3.tar.gz

You should see something like this:

--10:07:40--  http://ftp.drupal.org/files/projects/drupal-5.3.tar.gz
           => `drupal-5.3.tar.gz'
Resolving ftp.drupal.org... 140.211.166.134
Connecting to ftp.drupal.org|140.211.166.134|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 753,427 (736K) [application/x-gzip]

100%[====================================>] 753,427      795.90K/s            

10:07:41 (793.03 KB/s) - `drupal-5.3.tar.gz' saved [753427/753427]

If you see something different, it probably means you did not get the direct download link, and instead have a .html redirect. You need to look for the direct download link from the downloads page.

Now that Drupal is downloaded, go ahead and untar it:

sudo tar xfvz drupal-5.3.tar.gz

 You should now have a drupal-5.3 directory. Let change directory, and then move all the files in that directory over to our /var/www folder. I do this by:

cd drupal-5.3

sudo mv * /var/www

sudo mv .htaccess /var/www

ls

You should see nothing else in this directory now, because we've moved it all over to the /var/www which is the root of our web server. If you'd like to keep a copy of the files, you could alwasy do a cp -R * /var/www instead of mv. But you don't really have to do this as you could always untar a new copy.

Ok, now we have an empty database ready for drupal, and a web server that has all of the drupal files in it's root. I think it is time to connect the two! Navigate to /var/www/sites/default

**Please note that in the podcast I did these steps manually by editing the settings.php conf file. We will do it in the tutorial the easy way, which is by using the web interface.**

In this folder you will see a settings.php file. We need to give write access to drupal so it can modify this file, or we can modify it manually. Let's do:

sudo chmod 777 settings.php

Great, now you can go in and modify these settings in your settings.php file, or you can navigate to http://localhost/ and you should see this.

drupal database config page

Remember these settings from when we created our drupal user and database in phpmyadmin? Well here is where we enter them again. Once you've entered them, hit Save Configuration. If all went well and you spelled your password right, you should see:

Install complete

Note here that it tells you it just modified ./sites/default/settings.php. Remember what I said before? Lets go in and have a look at that file. Using your favorite text editor, hop in and take a look. I will use nano.

nano /var/www/sites/default/settings.php

If you scroll down a little ways, you will see your database settings. Look at the following line:

$db_url = 'mysql://drupal:yourpasswordhere@localhost/drupal';

See that database configuration page above, really all it did was modify this one line, to include the path to your drupal database in MySQL. So if you wanted to, you could have just gone in and modified this line, and your install would have worked just as well. Pretty neat huh? This is also a good thing to keep in mind, because if this file, settings.php ever gets overwritten, you will lose your database connection, and your site will go down!

Lets go ahead and exit out of the settings.php file and finish up our install. We want to chmod the settings.php file back to read only access.

sudo chmod 644 /var/www/sites/default/settings.php

Now click on "your new site" and you should see your fresh drupal installation. We need to go ahead and create the first account immediately, as this is the master administrative account for the site. Lick on create first account, and create a username and put an email in. When you submit, you will be redirected to that user page, where you can change this user password. CHANGE IT NOW. Being that this is the administrative account for the site, you may want to make it a strong password, depending on your environment.

hat's it! Wow, now that was a lot for one session. Did you get it all? If not, head over to the forums and ask questions, I will be more then happy to help.

 

Security question

I'm just wondering why, if settings.php has the password stored in plain text, all we need to do is remove write permissions on it? If groups and others still have read permission, why isn't that a risk?