Basic set up of a Debian web server and Drupal installation

Submitted by admin on Tue, 05/16/2017 - 11:41

Today i published the first article from the curriculum of Drupal Admin sysadmin training organized by our team.

What does it take to set up a web server from scratch and install Drupal to that server? 
Let’s find it out. 

The web server we will be using runs under Linux Debian / Ubuntu and has the standard set of Apache, MySql, Php on board, all with default configs. We will also consider basic set up of Drupal and some nuances about that environment. 

The prerequisites: a server with Debian installed, root access via ssh.
The website’s address is drupaladmin-example.com

Note: you need to have the A entry matching the web server’s IP for your domain in the DNS registry before setting off. You can add the pair to the hosts file:

  •  c:\windows\system32\drivers\etc\hosts in Windows;
  •  /etc/hosts in Linux / Mac OS X.

Preparing the server

We’ll need a console editor. I often use nano, so let’s install this one:

root@server:~# apt-get install nano

Let’s create a user that will work with the site and call that user “webmaster”.

root@server:~# adduser webmaster

Next, we invent a password for this user, provide answers to all questions asked and we are all set.
Now we connect to the server as webmaster and create a structure of directories in webmaster’s folder:

webmaster@server:~$ mkdir domains domains/tmp domains/drupaladmin-example.com domains/drupaladmin-example.com/logs domains/drupaladmin-example.com/html

~/domains/drupaladmin-example.com/html is the directory where our website will reside.
~/domains/drupaladmin-example.com/logs is the place for web server log files.
~/domains/tmp is the Drupal’s temporary storage.

We need to have it open for all operations:

webmaster@server:~$ chmod 777 /home/webmaster/domains/tmp

Installing Apache, MySql, PHP

Now we connect to the server as root. Next, we update Debian index files:

root@server:~# apt-get update

Then we can install what we want:

root@server:~# apt-get install apache2 mysql-server php5 php5-mysql php5-gd

Important: do not forget to provide root password for MySQL.

Setting up Apache virtual host

If you need to learn more, check the docs published to Apache.org. There is a lot of info about virtual hosts there. At this stage, we stay connected as root.
First, we create /etc/apache2/sites-available/drupaladmin-example.com.conf:

root@server:~# nano /etc/apache2/sites-available/drupaladmin- example.com.conf

And this is what we paste into this file.

For Apache 2.2:

<VirtualHost *:80>
  ServerAdmin info@drupaladmin-example.com
  ServerName www.drupaladmin-example.com
  ServerAlias drupaladmin-example.com
  DocumentRoot /home/webmaster/domains/drupaladmin-example.com/html
  <Directory /home/webmaster/domains/drupaladmin-example.com/html>
    Options -Indexes +FollowSymLinks
    AllowOverride all
    order allow,deny
    allow from all
  </Directory>

  ErrorLog /home/webmaster/domains/drupaladmin-example.com/logs/apache_errors.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  # LogLevel warn

  CustomLog /home/webmaster/domains/drupaladmin-example.com/logs/apache_access.log combined
  php_admin_value upload_tmp_dir &quot;/home/webmaster/domains/tmp&quot;
  php_admin_value session.save_path &quot;/home/webmaster/domains/tmp&quot;
  AddType application/x-httpd- php .php .php3 .php4 .php5 .phtml
  AddType application/x-httpd- php-source .phps

</VirtualHost>

For Apache 2.4:

<VirtualHost *:80>

  ServerAdmin info@drupaladmin-example.com
  ServerName www.drupaladmin-example.com
  ServerAlias drupaladmin-example.com
  DocumentRoot /home/webmaster/domains/drupaladmin-example.com/html
  <Directory /home/webmaster/domains/drupaladmin-example.com/html>
    AllowOverride All
    Options -Indexes +FollowSymLinks
    Require all granted
  </Directory> 
  ErrorLog /home/webmaster/domains/drupaladmin-example.com/logs/apache_errors.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  # LogLevel warn
  CustomLog /home/webmaster/domains/drupaladmin-example.com/logs/apache_access.log combined

  php_admin_value upload_tmp_dir "/home/webmaster/domains/tmp";
  php_admin_value session.save_path &quot;/home/webmaster/domains/tmp&quot;
  AddType application/x-httpd- php .php .php3 .php4 .php5 .phtml
  AddType application/x-httpd- php-source .phps
</VirtualHost>

Now, we tell the server it can use this virtual host:

root@server:~# a2ensite drupaladmin-example.com

And activate the Rewrite module to make links look beautiful:

root@server:~# a2enmod rewrite

Time to restart Apache:

root@server:~# /etc/init.d/apache2 reload

Creating the MySql DB

We connect to MySQL as root, using the password we have entered earlier.

root@server:~# mysql -uroot -p

Now we create the database. Let’s call it drupal_admin, its user will be webmaster, the password – dbpassword. Since this is just a tutorial, this password will do, but you have to use something much, much more complicated and unique when working on live websites.

CREATE DATABASE drupal_admin;
GRANT ALL PRIVILEGES ON drupal_admin.* TO &#39;webmaster&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;dbpassword&#39; WITH GRANT OPTION;

Type quit to exit the MySQL client.

Now the server is ready to accept Drupal.

How to install Drupal

From here on, we proceed as webmaster.

You can find a detailed Drupal 7 installation guide here: https://www.drupal.org/docs/7/install
And if you need to install Drupal 8 to the server, the detailed guide is here: https://www.drupal.org/docs/8/install

First off, we download the latest Drupal release from drupal.org.

Drupal 7

webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ wget http://ftp.drupal.org/files/projects/drupal-7.54.tar.gz -O drupal.tar.gz

Drupal 8

webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ wget https://ftp.drupal.org/files/projects/drupal-8.3.2.tar.gz -O drupal.tar.gz

Next, we unpack it and move all files to /home/webmaster/domains/drupaladmin-example.com/html:

webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ tar xvfz drupal.tar.gz

When unpacking is complete, you get the directory named drupal-x.x with x.x standing for the version of Drupal you downloaded.
Now we move the files:

webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ mv drupal-x.x/* ./
webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ mv drupal-x.x/.* ./
webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ rm drupal.tar.gz
webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ rmdir drupal-x.x
webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ chmod -R 777 sites/default/files webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ cp sites/default/default.settings.php sites/default/settings.php
webmaster@server:/home/webmaster/domains/drupaladmin-example.com/html$ chmod 777 sites/default/settings.php

Next, fire up the browser, browse to http://drupaladmin-example.com/install.php and launch the Drupal installation.
Name of the DB is drupal_admin, name of the user is webmaster, password is dbpassword.
The temporary files directory is /home/webmaster/domains/tmp

That’s it! We now have a server all set up and with Drupal on board.

Теги

Add new comment

Filtered HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.