How to Installation of Drupal on ubuntu 18.04

From PheonixSolutions
Jump to navigation Jump to search

Instalation of Drupal on ubuntu 18.04

Before you begin

Update the package index and system packages to the latest versions:

 sudo apt update && sudo apt upgrade

1. Create a MySQL database

 sudo apt install mysql-server

To log in to the MySQL shell type the following command and enter the password when prompted:

 mysql -u root -p

To create a database named drupal, user named drupaluser and to grant the necessary permissions to the user, run the following commands:

 mysql>CREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
 mysql>GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'change-with-strong-password';
 

2. Install PHP

[edit]

To install all required PHP modules run the following command:

 sudo apt install php7.2-cli php7.2-fpm php7.2-mysql php7.2-json php7.2-opcache php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl
 systemctl status php7.2-fpm

3. Install Composer

To install composer globally download the Composer installer with curl and move the file to the /usr/local/bin directory:

 curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

Verify the installation by printing the composer version:

 composer –version

4. Install Drupal

[edit]
 sudo composer create-project drupal-composer/drupal-project:8.x-dev /var/www/my_drupal --stability dev --no-interaction
 cd /var/www/my_drupal
 sudo vendor/bin/drush site-install --db-url=mysql://drupaluser:change-with-strong-password@localhost/drupal

we need to set the correct permissions so that the web server can have full access to the site’s files and directories. Both Apache and PHP are running as www-data user and www-data group, so we need to issue the following command:

 sudo chown -R www-data: /var/www/my_drupal

How to configure Apache for Drupal

Run the commands below to create a new configuration file calleddrupal.conf in the /etc/apache2/sites-available/ directory to host our Drupal server block.

 sudo nano /etc/apache2/sites-available/drupal.conf

In the file keep the below content

 <VirtualHost *:80>
 ServerName example.com
 ServerAlias www.example.com
 ServerAdmin admin@example.com
 DocumentRoot /var/www/drupal
 <Directory /var/www/drupal/>
 Options FollowSymlinks
 AllowOverride All
 Require all granted
 </Directory>
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
 </VirtualHost>
 Enable drupal.conf file
 sudo a2ensite drupal.conf
 sudo systemctl reload apache2

At this stage, Drupal is ready and can be launched by going to the server’s IP or hostname.

http://localhost