Drupal 8 / CentOS 7
How to Successfully Install Drupal 8 on CentOS 7 With All Errors Resolved
First, go to https://www.drupal.org/download to access the latest version of Drupal Core:
I clicked on read release notes to best orient myself with this version of Drupal.
At the time of this writing, the latest production version of Drupal was 8.7.10:
1) I right-clicked download tar.gz,
2) I selected Copy link address
3) I selected my CentOS console window
4) I navigated to the appropriate directory on my CentOS server
4) I typed in wget
5) I right-clicked to paste the copied link address
6) I pressed <ENTER> to download the archive to my CentOS server
7) I used tar to unpack the archive
8) I re-named the archive to the right directory name for the apache web server
9) I used a web browser to navigate to the home page of the Drupal website
Choose Language:
The first screen you see is the Choose language screen:
I accepted English as my language and clicked on Save and continue.
Choose Profile Screen:
The second screen you see is the Select an installation profile screen
I accepted Standard as my installation profile and clicked on Save and continue.
So far, so good, but we are soon going to see silly installation errors that have persisted in Drupal for over 10 years now, and that a simple post-installation script would resolve and ease the lives of thousands and thousands of Drupal newbies.
Instead, the Drupal Team admits the problem and forced Drupal newbies to troll the Internet for hours searching for solutions to problems that should have been programmed away!
Galactic FAIL
Anyways, here we go, into error-land!
How To Resolve FILE SYSTEM Errors When Installing Drupal 8 On CentOS:
For some mysterious reason there's no sites/default/files directory installed on a default Drupal 8 installation - even though almost every Drupal installation in the world needs this directory! In fact, this directory has been required by Drupal since version 6, which came out in February 2008!
Almost 12 years later, thousands of Drupal newcomers are being stymied by this bad design/deployment decision on the part of the Drupal Core team.
Anyways, getting rid of this error (by creating and configuring this directory) is very simple:
1) the /sites/default/files directory needs to be manually created
2) Its ownership needs to be set to the web server process, because that is where Drupal puts files that you upload through the GUI, which runs in the security context of the web server (FYI: my web server security context is apache)
3) It needs to be set to SELINUX read/write mode (rw), because the default mode for web content under SELINUX is read-only (r).
Here's the commands that accomplish this task:
# cd sites/default
# mkdir files
# chown apache:apache ./files
# chcon unconfined_u:object_r:httpd_sys_rw_content_t:s0 files
Checking to see if we have resolved the problem (by pressing F5 to reload the Drupal install progress web page) reveals...
WOW! The error went away! Great!
How To Resolve settings.php Errors When Installing Drupal 8 On CentOS:
The next error that people are likely to see is with respect to the settings.php file, which Drupal needs to be able to find to function correctly, because that's where it stores its database connection settings and other important information
Thankfully, there's a little more help here than in the case of the files subdirectory, in the form of an example default.settings.php file that you can just copy and use:
# ls -1
default.services.yml
default.settings.php
files
NOT SO FAST! If you copy this file and expect Drupal 8 to "just work" you are going to be sorely disappointed, because it will be under the wrong user context for the Drupal GUI, which runs as apache:
# whoami
root
# cp default.settings.php settings.php
# ls -l
total 72
-rw-r--r--. 1 mymanthemaker.com mymanthemaker.com 6762 Nov 14 07:20 default.services.yml
-rw-r--r--. 1 mymanthemaker.com mymanthemaker.com 31342 Nov 14 07:20 default.settings.php
drwxr-xr-x. 2 apache apache 6 Nov 20 10:48 files
-rw-r--r--. 1 root root 31342 Nov 20 11:34 settings.php
What you will see is the following error, which does not really help to point to what needs to be done to resolve the situation:
At this point a lot of people who don't understand Unix/Linux filesystems throw up their hands and just set the settings.php file to 777 or "world readable and world writeable".
Generally speaking this is a bad idea, because it opens up a huge security hole.
Also, in the case of CentOS, it may not solve your problem. Remeber, in CentOS the following should always be observed to protect system integrity:
A) Directories and Files should be owned by the most appropriate security context / user
B) Directory and File permissions should be loosened as little as possible
C) SELINUX permissions should be loosened as little as possible
This "Trinity of Principles" should always be on your mind if you are running a CentOS server:
OK - lets totally open up settings.php to see what happens:
Please don't do this!
Read the next section, Here's a better way, to do this the right way!
The next section is included only for EDUCATIONAL purposes, as a WARNING!
# chmod 777 settings.php
# ls -lZ
-rw-r--r--. mymanthemaker.com mymanthemaker.com unconfined_u:object_r:httpd_sys_content_t:s0 default.services.yml
-rw-r--r--. mymanthemaker.com mymanthemaker.com unconfined_u:object_r:httpd_sys_content_t:s0 default.settings.php
drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 files
-rwxrwxrwx. root root unconfined_u:object_r:httpd_sys_rw_content_t:s0 settings.php
Checking to see if we have resolved the problem (by pressing F5 to reload the Drupal install progress web page) reveals...
WOW! The error went away! Great!
Not great. What you've just done is leave a HOLE in your Linux security model that might come back to bite you later! Now, there's a possibility that someone could hack your system by messing with the settings.php file, because it's owned by the wrong user (root), has read/write permissions and is executable within the security context of the superuser, root.
The Bottom Line Is This: Don't Use 777 To Get Things Working! It's Dangerous!
Here's a better way:
Here's a much more elegant and safe way to get your Drupal 8 settings.php file installed and working correctly under CentOS.
# cp default.settings.php settings.php
# chown apache:apache settings.php
# chmod 446 settings.php
# chcon unconfined_u:object_r:httpd_sys_rw_content_t:s0 settings.php
# ls -lZ
-rw-r--r--. mymanthemaker.com mymanthemaker.com unconfined_u:object_r:httpd_sys_content_t:s0 default.services.yml
-rw-r--r--. mymanthemaker.com mymanthemaker.com unconfined_u:object_r:httpd_sys_content_t:s0 default.settings.php
drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 files
-r--r--rw-. apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 settings.php
Now, checking to see if we have resolved the problem (by pressing F5 to reload the Drupal install progress web page) reveals...
WOW! The error went away! Great!
Yes, that's great. And done in a much, much safer way!
How To Resolve Clean URLs Warning When Installing Drupal 8 On CentOS:
The next bit of work is necessary to enable Clean URLs in Drupal, which is a convenient feature that re-writes Drupal web page address to something humans understand better.
Here's the Drupal explanation:
If you want to learn more about Clean URLs, see the Wikipedia article for more information.
Most people will want this functionality (I know I do), so we we are going to make this error go away. Trouble is, fixing this error will almost certainly require us to leave the context of Configuring Drupal and enter the context of Configuring Apache, without any preparation or warning!
To make Clean URLs happen, we need to tell the Apache Web Server to "rewrite" both incoming and outgoing URLs. This doesn't happen inside of Drupal, it happens one layer below Drupal, inside Apache.
There's two ways of making this happen:
A) Make sure the .htaccess file in the directory of this Drupal 8 installation on CentOS has been configured to enable CLEAN URLs (rewriting), which would limit the impact of this modification to this installation only.
B) Change the configuration of the Apache server, which could impact every website hosted on this server.
Using the CentOS "Trinity of Principle", let's go for the smallest change possible first, which means taking a look to see if there is an .htaccess file:
#cd /var/www/vhosts/mymanthemaker.com/www/content
# ls -al .htaccess
-rw-r--r--. 1 mymanthemaker.com mymanthemaker.com 7866 Nov 14 07:20 .htaccess
OK, the file exists, but is apache configured to read the .htaccess file at all?
The place where this needs to be checked is inside the apache server configuration file, which is located far, far away from where the Drupal 8 installation is located. A specific stanza needs to be added to the
# vi /etc/httpd/conf.d/vhosts.conf
###############################################################################
# GL 2019-11-19 mymanthemaker.com
###############################################################################
<VirtualHost *:80>
ServerName www.mymanthemaker.com
ServerAlias mymanthemaker.com
DocumentRoot /var/www/vhosts/mymanthemaker.com/www/content
CustomLog /var/www/vhosts/mymanthemaker.com/www/logs/access_log common
ErrorLog /var/www/vhosts/mymanthemaker.com/www/logs/error_log
Alias /webalizer /var/www/vhosts/mymanthemaker.com/www/webalizer
# This setting is necessary for CLEAN URL's in Drupal
<Directory "/var/www/vhosts/mymanthemaker.com/www/content">
AllowOverride All
</Directory>
</VirtualHost>
Next, we need to get the apache server to re-load its configuration file by asking it to restart:
NOTE: For barely acceptable reasons, the actual name of the apache server service in CentOS is httpd (don't ask why - I'll just go off on another rant).
# service httpd restart
Redirecting to /bin/systemctl restart httpd.service
Checking to see if we have resolved the problem (by pressing F5 to reload the web page) reveals...
WOW! The error went away! Great!
How To Resolve MySQL Errors When Installing Drupal 8 On CentOS:
The next big challenge when overcoming Drupal 8 Installation Problems On A CentOS Server is to connect Drupal to a database. In my case, it's always been a MySQL Server database, and I have had good results with that database technology.
Here's the screen I got:
So I filled it in with my preferred values and clicked on Save and continue:
Here's what I got in response:
HUH?
Here's what the Drupal 8 Installation script wants to know:
A) Is the database server running?
OK, let's check.
# service mariadb status
Redirecting to /bin/systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-10-06 12:59:55 HKT; 1 months 14 days ago
OK, MySQL is loaded and active, so that potential problem isn't relevant.
B) Does the database exist
Doesn't simply supplying the desired database name would get Drupal to create it?
NOPE.
As it turns out, you have to create the back-end database for Drupal 8 manually, as I have had to do with every version of Drupal for almost 10 years. Why the Drupal Team insists on inflicting this task on Drupal newcomers I have no clue, as it is one of the most anti-social behaviours I have ever seen persist in the open source community.
Amending the Drupal 8 installation script to include the creation of the MySQL (or whatever) back-end database shouldn't take 10 years to NOT accomplish, when doing so would dramatically increase the adoption rate of Drupal in the face of much friendlier sytems!
So, it turns out that you have to Exit or Suspend the Drupal 8 Installation so as to go and create a database for Drupal 8 to then be able to connect to be able to proceed with its own installation.
Celestial FAIL
Anyways, here's how to create a MySQL back end database so Drupal 8 can install itself:
Installing a MySQL Back End Database for Drupal 8 On CentOS
The things you need are:
1) The username of the MySQL administrative account
2) The password of the MySQL administrative account
3) A name for your Drupal 8 database
4) A Drupal 8 username for the Drupal 8 database
5) A password for the Drupal 8 username
Here's what I used to Install A MySQL Database Back End for Drupal 8 On CentOS
MySQL User: <my secret>
MySQL Pass: <my secret>
Drupal 8 Data: mymanthemaker
Drupal 8 User: themaker
Drupal 8 Pass: <my secret>
Note: In the above example "<my secret>" is a value you make up, not a literal value.
01 - Log in to MySQL as the MySQL Administrator
# mysql -p
Enter password: <my secret>
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 39648
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [mysql]> use mysql;
Database changed
02 - Create the Drupal 8 Database
Now that the MySQL database server command line interface (MCLI) has been accessed, we can go ahead and Create A Drupal 8 Back End Database Under CentOS:
MariaDB [(none)]> CREATE DATABASE mymanthemaker CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Query OK, 1 row affected (0.00 sec)
03 - Create the Drupal 8 User (with Password)
MariaDB [(none)]> CREATE USER themaker@localhost IDENTIFIED BY '<my secret>';
Query OK, 0 rows affected (0.05 sec)
04 - Grant Drupal 8 User Access to the Drupal 8 Database
MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON mymanthemaker.* to themaker@localhost;
Query OK, 0 rows affected (0.01 sec)
Checking to see if we have resolved the problem (by pressing F5 to reload the web page) reveals...
WOW! The error went away! Great!
If things go well, you should see a progress bar sliding to the right, showing what Drupal 8 modules are being installed:
How To Configure Drupal 8 On CentOS:
Once the modules are filled, you will be asked to provide some basic information about your new Drupal 8 site.
Here's my screen(s) as an example:
Next, click on Save and continue...
Here's what I saw next:
Great Success!
REFERENCES:
https://www.drupal.org
https://www.drupal.org/download
https://www.drupal.org/docs/8/troubleshooting-drupal-8/fix-drupal-8-clean-urls-problems
https://www.drupal.org/docs/8/install/step-3-create-a-database