Setup Nginx drupal and phpmyadmin on ubuntu 16.04 & RHEL

How to setup nginx webserver with drupal installation & phpmyadmin I assume that you have already install nginx web server on Ubuntu 16.04/RHEL

As nginx is web server for serving static content on web, but as we are going to use it with drupal 7.x/8.x we need addition service for php support i.e php-fpm

  • Open terminal by alt+ctrl T and cd /etc/nginx/conf.d
  • Create default.conf as
  • 
      # Default server configuration
    
      server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        root /var/www/html;
    
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    
        server_name _;
    
        location / {
          # First attempt to serve request as file, then
          # as directory, then fall back to displaying a 404.
          try_files $uri $uri/ =404;
        }
        # Allow phpmyadmin to access from nginx
        location /phpmyadmin {
          root /usr/share;
          index index.php;
          try_files $uri $uri/ /phpmyadmin/index.php$args$is_args;
          location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share;
          }
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
          include snippets/fastcgi-php.conf;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
      }
      
  • Install php7.0-fpm with php-gd extension that is required by drupal:
  • 
      sudo apt-get install php7.0-fpm php7.0-cli php7.0-gd php7.0-mysql php7.0-xml -y
      
  • Configure PHP-FPM
  • We will configure Nginx to use php-fpm to serve HTTP requests for PHP pages by editing "/etc/php/7.0/fpm/php.ini" file:

    
      sudo vi /etc/php/7.0/fpm/php.ini and replace cgi.fix_pathinfo=1 with cgi.fix_pathinfo=0
      

    In this tutorial we are taking drupal-dev.com as our domain for drupal installation:

  • Now we will create a folder name like: drupal-dev.com in /var/www ex:
  • 
      /var/www/drupal-dev.com/public
      
  • Now we will create server-block in nginx for drupal-dev.com domain.
  • 
      cd /etc/nginx/conf.d create a config file like drupal-dev.conf will contain:
      server {
        listen 80;
        server_name www.drupal-dev.com;
        # rewrite ^/(.*) http://drupal-main.com/$1 permanent;
      }
      server {
        listen 80;
        server_name drupal-dev.com;
    
        root /var/www/drupal-dev.com/public/;
        index index.php;
        # For Drupal >= 7 clean url
    
        location / {
          try_files $uri /index.php?$query_string; 
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
          location ~ \.php$ {
          include snippets/fastcgi-php.conf;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
      }
      
  • Add the domain name entry to the hosts file by editing sudo vi /etc/hosts and put below line:
  • 
      127.0.0.1 localhost
      127.0.1.1 drupal-dev.com www.drupal-dev.com
      

restart nginx by sudo service nginx restart and visit your site: http://drupal-dev.com

-:Done:-

Comments

Popular posts from this blog

How to setup Drupal 8 Multisite on nginx webserver with different domain.

Install drush globally using composer on WSL

Drupal views create exposed filter programmatically