Install Drupal on Ubuntu With Nginx, MariaDB

Install Drupal on Ubuntu With Nginx, drupal 8 themes

drupal 8 themes, Drupal is faster, more secure and more SEO-friendly than WordPress. If you are tired of WordPress and don’t mind the low number of themes and modules (aka plugins) available for Drupal, then give Drupal a try.

how to install Drupal on Ubuntu Xenial Xerus with Nginx, MariaDB and PHP7. I assume that you have already set up a LEMP stack on Ubuntu. If not so, click the link below to check out my easy-to-follow guide. Drupal also works with LAMP, but here I show you how to set it up with LEMP.

PHP7 is available from Ubuntu LTS Xenial Xerus so you no longer have to rely on third-party PPA to get PHP7 installed on Ubuntu 16.04. In this tutorial, we are going to look at how to install Nginx, MariaDB and PHP7-FPM (LEMP stack) on Ubuntu LTS Xenial Xerus.

Step 1: Update Ubuntu LTS
Before we install any software, it’s always a good idea to update repository and software packages. SSH into your Ubuntu server and enter the below commands.

sudo apt update
sudo apt upgrade

Step 2: Install Nginx Web Server
Nginx is a high performance web server. It also can be used as a reverse proxy. Enter this command to install Nginx Web server.

sudo apt install nginx

After it’s installed, we can enable Nginx to auto start when Ubuntu is booted by running the following command.

sudo systemctl enable nginx

Then start Nginx with this command:

sudo systemctl start nginx

Now check out its status.

systemctl status nginx

“enabled” indicates that auto start at boot time is enabled and we can see that Nginx is running.

Now in your browser’s address bar, type the public IP address of Ubuntu LTS server. You should see the “Welcome to nginx!” Web page which means Nginx Web server is running correctly.

You can use the following command to fetch the public IP address of Ubuntu server.

sudo apt install curl

curl http://icanhazip.com

If you are installing LEMP on your local Ubuntu box, just type 127.0.0.1 or localhost in the browser address bar.

Finally, we need to make www-data (Nginx user) as the owner of web root directory.

sudo chown www-data /usr/share/nginx/html -R

Step 3: Install MariaDB
MariaDB is a drop-in replacement for MySQL. It is developed by former members of MySQL team who concerned that Oracle might turn MySQL into a closed-source product. Many Linux distributions (Arch Linux, Fedora etc), companies and organizations (Google, Wikipedia) have migrated to MariaDB. So we’re going to install MariaDB instead of MySQL.

sudo apt install mariadb-server mariadb-client

After it’s installed, MariaDB server should be automatically started. Use systemctl to check its status.

systemctl status mysql

If it’s not running, start it with this command:

sudo systemctl start mysql

To enable MariaDB to automatically start when Ubuntu is rebooted:

sudo systemctl enable mysql

Now run the post installation security script.

sudo mysql_secure_installation

When it asks you to enter MariaDB root password, press enter because you have not set the root password yet. Then enter y to set the root password for MariaDB server.

install mariadb on Ubuntu

Next you can just press Enter to answer all the remaining questions. This will remove anonymous user, disable remote root login and remove test database. This step is a basic requirement for MariaDB database security.

mariadb secure installation

Step 4: Install PHP7
Enter the following command to install PHP7 and PHP7 extensions.

sudo apt install php7.0-fpm php7.0-mbstring php7.0-xml php7.0-mysql php7.0-common php7.0-gd php7.0-json php7.0-cli php7.0-curl

PHP extensions are commonly needed for content management systems (CMS) like WordPress. For example, if your installation lacks php7.0-xml, then some of your WordPress site page may be blank and you can find an error in Nginx error log like:

PHP message: PHP Fatal error: Uncaught Error: Call to undefined function xml_parser_create()
Installing these PHP extensions ensures that your CMS runs smoothly.

Now start php7.0-fpm.

sudo systemctl start php7.0-fpm

Check status:

systemctl status php7.0-fpm

Step 5: Create a Default Nginx Server Block File
Remove the default symlink in sites-enabled directory.

sudo rm /etc/nginx/sites-enabled/default

Then create a new default server block file under /etc/nginx/conf.d/ directory.

sudo nano /etc/nginx/conf.d/default.conf

Paste the following text into the file. Replace 12.34.56.7with your actual server IP.

server {
listen 80;
listen [::]:80;
server_name 12.34.56.78;
root /usr/share/nginx/html/;
index index.php index.html index.htm index.nginx-debian.html;

location / {
try_files $uri $uri/ =404;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}

location ~ .php$ {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}

location ~ /.ht {
deny all;
}
}

Save and close the file. Then test nginx configuration and reload it.

sudo nginx -t
sudo systemctl reload nginx

Step 6: Test PHP
To test the cli version of PHP7, we just need to enter this command:

php –version

To test PHP-FPM, first create a test.php file in the Web root directory.

sudo nano /usr/share/nginx/html/test.php

Paste the following PHP code into the file.

<?php phpinfo(); ?>

Save and close the file. Now in the browser address bar, enter server-ip-address/test.php. Replace sever-ip-address with your actual IP. You should see your server’s PHP information. This means PHP processing is fine.

How to Install PHP7.2
PHP7.2 is the latest stable version of PHP, released on November 30, 2017 and it has minor performance boost over PHP7.0. We can add the PPA from Ondrej Sury to install PHP7.2 on Ubuntu 17.10. That guy is also the maintainer of Certbot PPA.

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

Then we can install PHP7.2 and common extensions by using the following command.

sudo apt install php7.2 php7.2-fpm php7.2-mysql php-common php7.2-cli php7.2-common php7.2-json php7.2-opcache php7.2-readline php7.2-mbstring php7.2-xml php7.2-gd php7.2-curl

Now start PHP7.2-FPM.

sudo systemctl start php7.2-fpm

Enable auto-start at system boot time.

sudo systemctl enable php7.2-fpm

Check its status:

systemctl status php7.2-fpm

Using PHP7.2-FPM with Nginx
To make Nginx use PHP7.2-FPM instead of PHP7.0-FPM, we need to edit the Nginx server block file.

sudo nano /etc/nginx/conf.d/default.conf

Find the following line.

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

Change php7.0-fpm to php7.2-fpm.

fastcgi_pass unix:/run/php/php7.2-fpm.sock;

Save and close the file. Then reload Nginx for the change to take effect.

sudo systemctl reload nginx

If you refresh the server-ip-address/info.php page, you will see Nginx is now using PHP7.2-FPM.

PHP7.0 can coexist with PHP7.2. If you don’t want to use PHP7.0, then you can remove it. Please beware that some web application may not be compatible with PHP7.2 like NextCloud 12. In my test, WordPress runs well with PHP7.2.

For your server’s security, you should delete test.php file now.

Congrats! You have successfully installed Nginx, MariaDB and PHP7 (LEMP stack) on Ubuntu LTS Xenial Xerus.

When you are finished, come back here and read on.

Install Drupal, drupal 8 themes, on Ubuntu 16.04
First, upgrade all your system software to the latest version available in your software repository using the following command:

sudo apt update && sudo apt upgrade

Next, download Drupal from the official website to your Ubuntu server. You can use wget to do that. The latest stable version is Drupal 8.1.3 which is released on June 15, 2016.

wget https://ftp.drupal.org/files/projects/drupal-8.1.3.tar.gz

When you read this tutorial, there may be a newer version of Drupal available, you can check it at https://www.drupal.org/project/drupal. Simply replace 8.1.3 with the newer version number.

Once the download is completed, unpack it using the following command. This will create a drupal-8.1.3 directory under the current directory.

tar xzvf drupal-8.1.3.tar.gz

Now move all the files in drupal-8.1.3 directory to the web root. If you followed the previous LEMP tutorial, then your web root will be /usr/share/nginx/html.

sudo mv drupal-8.1.3/* /usr/share/nginx/html/

Create a Database and User for Drupal 8
Drupal is a content management system and as such it needs a database to store the content. Run the following command to log into MariaDB shell as root. Note that this is the MariaDB root user, not the root user of Ubuntu system.

mysql -u root -p

If you can’t log into MariaDB, then check out how to fix MariaDB plugin ‘unix_socket’ is not loaded error.

Once you are logged in, create a new database for Drupal using the following command. I name it drupal, you can use whatever name you like.

create database drupal;
Next, create a new database user on localhost using the following command. Again, I name it drupaluser, you can use whatever name you like.

create user drupaluser@localhost;

Set a password for the user. Replace your-password with your preferred password.

set password for drupaluser@localhost= password(“your-password”);

Then grant all permission of the new database to the new user:

grant all privileges on drupal.* to drupaluser@localhost identified by ‘your-password’;

Flush the privileges table:

flush privileges;
Exit MariaDB Shell:
exit;

Configuring Drupal

Change your working directory to the web root:

cd /usr/share/nginx/html

Copy the default settings to a new file:

sudo cp sites/default/default.settings.php sites/default/settings.php

Add write permission to settings.php file and sites/default directory

sudo chmod u+w sites/default/settings.php
sudo chmod u+w sites/default

Now we need to change the owner of web root directory to the Nginx user. The nginx user is usually nginx or www-data. You can check it in /etc/nginx/nginx.conf file.

sudo chown nginx:nginx /usr/share/nginx/html/ -R

or

sudo chown www-data:www-data /usr/share/nginx/html/ -R

Create a Nginx Config File for Your Drupal Site

sudo nano /etc/nginx/conf.d/drupal.conf

Put the following text into the file. Replace the red-colored text with your real domain.

server {
listen 80;
server_name www.your-domain.com your-domain.com;
root /usr/share/nginx/html/;
index index.php index.html index.htm;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}

location ~ ..*/.*.php$ {
return 403;
}

# Block access to hidden directories
location ~ (^|/). {
return 403;
}

location ~ ^/sites/.*/private/ {
return 403;
}

# No php is touched for static content
location / {
try_files $uri @rewrite;
}

# Clean URLs
location @rewrite {
rewrite ^ /index.php;
}

# Image styles
location ~ ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location ~ .php$ {
try_files $uri =404;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+.php)(/.+)$;
include fastcgi_params;
}
}

Save and close this file. Then test Nginx configurations and reload Nginx.

sudo nginx -t
sudo systemctl reload nginx

Finish the Drupal installation in Your Browser
Make sure that your domain name is pointed to your Ubuntu server in DNS. Then in your browser address bar, type

your-domain.com
or
your-domain.com/core/install.php
Replace your-domain.com with your real domain name. You will see the Drupal installation wizard, also know as Drupal installer. Follow the instructions to finish the Drupal installation.

Install Drupal on Ubuntu With Nginx, MariaDB

If you can’t see the installation wizard, that’s probably because some PHP extensions such as php-curl, php-mbstring, php-gd are not enabled on your server. You can enable them with the following command:

sudo apt install php-curl php-mbstring php-gd

Now let’s go through the steps.

Choose language
The language you choose in the first step will be the language of Drupal structure and the Drupal backend. You can, however, write content in other languages. If you want to build a multilingual site with Drupal, the settings can be configured later on. For this tutorial, we choose English so that the administrator interface is in English.

Choose Profile
Step 2 is to choose an installation profile. If you are installing plain Drupal core, ie, not Drupal distributions, then you options will be standard and minimal. You want to choose standard if you are a Drupal beginner. You only want to choose minimal if you really are an advanced Drupal user who like to heavily customize the site that is going to be built.

Install Drupal on Ubuntu With Nginx, MariaDB

Verify Requirement
If you followed this tutorial step by step, the requirement should be verified successfully and you don’t have to do anything in this step.

Set up database
This step is to connect to the MariaDB database. So enter the database, database user and password you created earlier.

Install Drupal on Ubuntu With Nginx, MariaDB

Click Save and continue button, it will begin installing 40 core modules which comes with the standard installation profile. If you choose minimal profile, then a lot of core modules will not be installed.

Install Drupal on Ubuntu With Nginx, MariaDB

Configure Site
This is the last step. In the site information section, enter your preferred site name and site email address. The site email address is for automated emails to be sent to site users or site visitors for registration, password recovery or other stuff. It’s used to identify your site. You don’t want to enter your personal email address such as my-name@gmail.com. Instead, enter an email address such as info@your-domain.com.

Install Drupal on Ubuntu With Nginx, MariaDB

The site maintenance account is user 1 in a Drupal site. It’s like the root user on Linux who can do anything in the system including harmful things to the system. It is not best practice to use this site maintenance account to do normal stuff in a Drupal site. Choose a username other than admin or webmaster. These two username can be easily guessed. The email address is used when you forget the password of user 1. So enter an email address different from the site email address.

Install Drupal on Ubuntu With Nginx, MariaDB

Then select a default country and default time zone. The email notifications will be sent to the email address of user 1.

Remember that all of the above settings can be changed later on. Finally, click Save and continue. You will be taken to the home page of your Drupal site.

Install Drupal on Ubuntu With Nginx, MariaDB

Congrats! You have successfully installed Drupal on Ubuntu and can now start building your Drupal site!

250000 bulk email for 1 month
bulk email services providers 7 Lacks email for 3 Months
bulk email service 30 Lacks email for 12 Months
bulk email marketing 15 Lacks email for 6 Months

Corundum
Logo
Register New Account
Reset Password
Compare items
  • Total (0)
Compare
0