How to install Drupal on CentOS 7

In this article, we will show you how to install Drupal on a CentOS server.

1.    Login to your server via SSH or KVM, via root.
2.    Disable selinux;

setenforce 0
sed -i ‘s/enforcing/disabled/g’ /etc/selinux/config

3.    Run the following command to install all the required packages for your Apache & MySQL stack, which will host the Drupal site;

yum install httpd mariadb-server mod_ssl -y

4.    We now need to install a version of PHP above 5.5.9 to be compatible with Drupal 8 and nano.

yum install centos-release-scl -y
yum-config-manager –enable rhel-server-rhscl-7-rpms -y
yum install php55 php55-php-gd php55-php-mysqlnd php55-php-pdo php55-php-json php55-php-curl php55-php-fpm php55-php-mbstring php55-php-opcache nano -y

5.    Run the following commands to the file /etc/httpd/conf.d/php.conf, this allows for Apache to pass the requests to PHP-FPM;

echo ‘<IfModule !mod_php5.c>’ >> /etc/httpd/conf.d/php.conf
echo ‘<FilesMatch \.php$>’ >>  /etc/httpd/conf.d/php.conf
echo ‘SetHandler “proxy:fcgi://″‘ >>  /etc/httpd/conf.d/php.conf
echo ‘</FilesMatch>’ >> /etc/httpd/conf.d/php.conf
echo ‘</IfModule>’  >> /etc/httpd/conf.d/php.conf

6.    Update the Apache config to allow for htaccess and PHP to be used, and update the timezone configuration in PHP (drupal will need this later);

sed -i ‘s/AllowOverride [Nn]one/AllowOverride all/g’ /etc/httpd/conf/httpd.conf
sed -i ‘s/DirectoryIndex index.html/DirectoryIndex index.php index.html/g’ /etc/httpd/conf/httpd.conf
sed -i ‘s/;date.timezone =/date.timezone = “America\/New_York”/g’ /opt/rh/php55/root/etc/php.ini

7.    Start Apache & MySQL on the server;

systemctl start httpd && systemctl start php55-php-fpm && systemctl start mariadb

8.    You should now be able to confirm that Apache is started by going to either your server IP address or the domain name you have pointed to the server, in this example we will use the server IP address.

9.    Create the MySQL user and database for Drupal, enter the mysql command to get to a prompt (choose a different password to the below one, just make sure it is secure!)

GRANT ALL PRIVILEGES ON drupal.* TO ‘drupal’@’localhost’ IDENTIFIED BY ‘Eh4wph8WItSO’;

10.    Download and put into place the latest version of Drupal, you’ll need to find the latest version of Drupal by going to the Drupal website (at the time of writing this is 8.2.1);

curl -O
tar zxvf drupal-8.2.1.tar.gz
rmdir /var/www/html
mv drupal-8.2.1 /var/www/html

11.    Update the permissions so that we can upload files through the Drupal control panel;

chown -R apache:apache /var/www/html

12.    You can now go to your site URL or IP address in the browser to complete the Drupal installation, below are the following pages you should go through to complete the install;

Your server should verify all of the requirements with this configuration and continue past the “Verify requirements” screen.

On the following page you should enter the details that you used earlier when creating the MySQL database;

Now enter the details below that you want for the site and the installation will complete and automatically redirect you to the Drupal admin panel.

  • great video. Would love to see a minecraft server setup where you are able to launch the server via service mc start command. On CentOS 6 and/or 7.

  • Andrew,

    I have php PHP 5.6.6 installed but when I try to go to the Web page, it says “Your PHP installation is too old. Drupal requires at least PHP 5.5.9. See the system requirements page for more information.” So my assumption is it is not recognizing the 5.6.6 version of PHP on my machine.

    Can you tell me how I can point this php version to apache and drupal, please.

      • Thanks for getting back to me on that. I realized I had an older php version pre-installed on the VM. Removing the older php fixed my issue. However, now I cannot wrap my head around the httpd.conf and other config files from php. I have been working to get drupal working on RHEL 7.2 and there’s still something missing. I get the following error:

        handle($request); $response->send(); $kernel->terminate($request, $response);