Ceci est une ancienne révision du document !
This article is an updated version of some notes I made years ago about installing Drupal on Ubuntu Server.
From the Drupal website: “Drupal is a free software package that allows you to easily organize, manage and publish your content, with an endless variety of customization.” Drupal, Wordpress, and Joomla are among the most popular web content management systems. Drupal is very modular compared to other content management systems. Wordpress tends to include a lot of features right off the initial install whereas Drupal is more of a ‘start small and tailor to your needs’ system.
I have a habit of forgetting tasks I don’t do everyday. When it’s a task that requires quite a few steps, I like to document the steps because I find that instructions provided by projects sometimes skip steps or make assumptions I don’t know. Installing and configuring Apache alone can be quite a task, particularly if you’re setting up multiple domains or have special library requirements. Add the complexity of learning MySQL (many people learn phpmyadmin) and things get a bit more challenging.
For the purpose of this article, I’m assuming access to the command line of a fresh install of Ubuntu Server 14.04.
Step #1 - Update Ubuntu Server:
sudo apt-get update
sudo apt-get dist-upgrade
Step #2 - Install Apache, MySQL, PHP, and some basic PHP libraries:
sudo apt-get install apache2 mysql-server php5 php5-mysql php5-gd
Several other dependencies are automatically added when you install Apache, MySQL and the basic PHP libraries.
During the install process, you’ll be asked to enter a password for the root user to access MySQL databases. The password you use should be long and complex, especially if you plan on exposing the site to the Internet (as opposed to Intranet).
When the installation finishes you may notice a message similar to: “apache2 could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the ‘ServerName’ directive globally to suppress this message.”
We need to set the fully qualified domain name (FQDN).
Step #3 - Set the Fully Qualified Domain Name:
The FQDN consists of 2 parts, the hostname of the computer running the server, and the domain name. There are a couple of ways you can solve the FQDN problem, the first is to set the FQDN with the 127.0.1.1 I.P. address in /etc/hosts (in this case my hostname is drupal8).
127.0.1.1 drupal8
The second, and preferred method is to set the ServerName directive in /etc/apache2/conf-available/fqdn.conf and enable the configuration with the apache program a2enconf. First set the ServerName directive in /etc/apache2/conf-available/fqdn.conf:
ServerName localhost
Next we need to enable the configuration file. It’s important to note that the conf file must end in .conf. We can enable the configuration file with a2enconf:
sudo a2enconf fqdn
Lastly we need to reload Apache:
sudo service apache2 reload
Step #4 - Download and unpack Drupal and move it to /var/www/html:
For the purpose of this article I’m assuming you’re just running a single website on a single server. If you plan on running multiple sites on the server your setup will be a little different. For multi-site setups, you’ll need to know a bit about modifying apache configuration files in /etc/apache2/sites-available. For this single site, we’re just going to use the already enabled 000-default.conf file which points to /var/www/html for the web server.
The simplest method to download Drupal is to use wget. Version 7.39 is the current stable version at the time of this article.
wget http://ftp.drupal.org/files/projects/drupal-7.39.tar.gz
Next unpack Drupal 7:
tar -zxvf drupal-7.39.tar.gz
At this step, you may want to change into the drupal-7.39/ directory and read the INSTALL and README files. If you’re using PostgreSQL instead of MySQL, be sure to read the INSTALL.pgsql.txt file. If you run into problems installing with MySQL, you might also want to have a look at the INSTALL.mysql.txt file. The INSTALL.txt file gives an overview of an overall installation. If you’ve changed into the drupal-7.39 directory, make sure you’re above it for the next step, moving the drupal folders to /var/www/html:
sudo mv drupal-7.39/* /var/www/html
sudo mv drupal-7.39/.htaccess /var/www/html
If your server is also your desktop machine (generally not a great idea), you can check it out in a web browser by typing http://localhost/ into the web browser. From another Linux machine, you can type in the hostname of your web server http://drupal/. Despite adding the drupal files to /var/www/html, we still get the apache splash screen because there’s an index.html file in the /var/www/html folder. Getting rid of this file will display the drupal installation when you navigate to the hostname/FQDN.
Step #5 - Create the MySQL database to hold the drupal files:
Before we can set drupal up, it needs a database to write to. MySQL is one of the most common databases in the world and a great choice here. You can use a web interface to mysql, but I’ve always preferred to just run mysql itself and issue commands:
mysql -u root -p
The -u switch tells mysql the user is the root user. The -p switch is used for passing the password, but if you don’t put one after the -p, it will prompt you for the password (a better idea if you work with other people around). A tip worth remembering is that mysql commands are terminated with a semicolon. At the mysql> prompt, create a database with whatever name you want, I tend to use d_sitename:
create database d_test;
If the command is successful, you’ll see a “Query OK, 1 row affected” message. To see what other databases exist, use the show databases; command. Next we want to grant rights to access the database to a user who exists on the system. In my Ubuntu installation I used the username charles. The proper rights for the database can be found in the INSTALL.mysql.txt file.
grant select, insert, update, delete, create, drop, index, alter, create temporary tables on d_test.* TO ‘charles’@’localhost’ IDENTIFIED BY ‘MyExtra0rdinarilyL0ngPaddw0rd’;
Don’t forget the .* after your database name. I did this several times when I was first starting to use mysql and couldn’t figure out why I kept getting an error.
Next quit mysql by issuing the quit; command. If you run ls -al on the files in /var/www/html, you’ll notice they all have your username and group attached to them. Before installing drupal we want to change the group to the www-data group:
sudo chown -R :www-data * sudo chown :www-data .htaccess
If you want to specify a different username, specify it before the colon. For example:
sudo chown -R charles:www-data *
Be a bit careful about the files you’re changing permissions on. Make sure you’re in the path where your drupal files are. Drupal also needs to be able to write to the configuration file in the sites/default directory, so temporary write permission needs to be given to this directory:
sudo chmod a+w sites/default
It’s important that this write permission be removed immediately after the installation or your server could get hacked!
Drupal has a default.settings.php file in the sites/default directory that needs to be copied as settings.php.
sudo cp sites/default/default.settings.php sites/default/settings.php
(Note: the above command is all one line with a space between default.settings.php and sites/default/settings.php) The settings.php file also must be writeable, and as with the sites/default directory, you should remove write permission after the installation.
sudo chmod a+w sites/default/settings.php
We’re almost ready to install drupal, there’s one more step we need before running the installation PHP script, enabling mod_rewrite. Mod_rewrite is an apache module that enables rewriting of urls so they look more clean. For example: Instead of your browser going to yoursite.com/en/ref=as_ss_tl?, the web site points to yoursite.com/example. To accomplish this type:
sudo a2enmod rewrite
Because mod_rewrite affects apache a restart is needed.
sudo service apache2 restart
Step #6 - Start the drupal install from a browser:
The next step is to run the install.php file from a browser. If you’ve eliminated the index.html (not index.php) file, you should be redirected to the install.php file when you open the URL to your web server. I use Linux almost exclusively most of the time, but if you’re using a Windows machine to access your Linux web server, you may need to tell the Windows machine hosts file which I.P. address your Linux server resides on. On Windows, this file is C:\WINDOWS\system32\drivers\etc\hosts. On Ubuntu/Xubuntu, just enter your server URL into the browser. For example: http://drupal/
Choose Standard Installation. English is the built-in language. Other languages can be added and there’s a link on how to do this on the installation page. The INSTALL.txt file covers installing other languages. For the moment click Save and Continue.
If all the steps above have been completed correctly you’ll see the Drupal database configuration screen. If write permission is not set on sites/default, or the settings.php file is missing from that directory, you’ll see an error message indicating so.
Enter the database information from the earlier database you created into the database configuration page and click Save and Continue.
At this point Drupal will write the settings to the settings.php config file. We can now safely remove write permissions on this file and the sites/default directory:
sudo chmod go-w sites/default/settings.php
sudo chmod go-w sites/default/
The last step in setting up our Drupal installation is to enter your site information, including the name of your site, the site e-mail address (the address that will send mail to users from), your admin username/password and admin email address (called the site maintenance account), the server’s default country and time-zone, and whether or not you want to check for drupal updates automatically and receive email notifications of releases (a good idea). Click Save and Continue.
Now you can proceed to log into your newly created Drupal site.
This article has covered a basic installation of Drupal. Some of the concepts, such as creating a mySQL database, enabling mod_rewrite, installing PHP and PHP libraries will be useful installing other content management systems and wikis. It’s a complex process and although the INSTALL.txt files are available, I always found I needed to write down my own steps to remember the steps I got stuck on. If you get stuck during the process of installing Drupal, there are several good resources: • The INSTALL.txt and README.txt files in the drupal-7.39/ directory • Drupal’s Quick Install for Beginners: https://www.drupal.org/documentation/install/beginners • Apache virtual hosts examples: http://httpd.apache.org/docs/2.2/vhosts/examples.html • 2bits.com - Besides having developed more than 30 modules for Drupal and being a server tuning company, 2bits has a lot of useful articles on Drupal - http://2bits.com/contents/articles