Friday, April 20, 2018

Drupal : PHP Fatal error: Interface 'Symfony\Component\HttpKernel\HttpKernelInterface' not found in core/lib/Drupal/Core/DrupalKernelInterface.php on line 15

While running drupal import database command or any similar drupal command using command line, if you get following error :

Fatal error: Interface 'Symfony\Component\HttpKernel\HttpKernelInterface' not found in core/lib/Drupal/Core/DrupalKernelInterface.php on line 15

You need to update composer with optimize autoloader, Here is the command.

Solution :

composer update --optimize-autoloader

composer - mpdf - php fatal error : class mPDF not found

Same vendor folder of one server is not working on another server. There may be reason that working server has php 5.5 and non working server has php 5.6

Add following lines in file vendor/composer/autoload_classmap.php

'UCDN' => $vendorDir . '/mpdf/mpdf/classes/ucdn.php',
'bmp' => $vendorDir . '/mpdf/mpdf/classes/bmp.php',
'cssmgr' => $vendorDir . '/mpdf/mpdf/classes/cssmgr.php',
'directw' => $vendorDir . '/mpdf/mpdf/classes/directw.php',
'grad' => $vendorDir . '/mpdf/mpdf/classes/grad.php',
'mPDF' => $vendorDir . '/mpdf/mpdf/mpdf.php',
'meter' => $vendorDir . '/mpdf/mpdf/classes/meter.php',
'mpdfform' => $vendorDir . '/mpdf/mpdf/classes/mpdfform.php',
'otl' => $vendorDir . '/mpdf/mpdf/classes/otl.php',
'tocontents' => $vendorDir . '/mpdf/mpdf/classes/tocontents.php',
'wmf' => $vendorDir . '/mpdf/mpdf/classes/wmf.php',
Add following lines in file vendor/composer/autoload_static.php
'UCDN' => __DIR__ . '/..' . '/mpdf/mpdf/classes/ucdn.php',
'bmp' => __DIR__ . '/..' . '/mpdf/mpdf/classes/bmp.php',
'cssmgr' => __DIR__ . '/..' . '/mpdf/mpdf/classes/cssmgr.php',
'directw' => __DIR__ . '/..' . '/mpdf/mpdf/classes/directw.php',
'grad' => __DIR__ . '/..' . '/mpdf/mpdf/classes/grad.php',
'mPDF' => __DIR__ . '/..' . '/mpdf/mpdf/mpdf.php',
'meter' => __DIR__ . '/..' . '/mpdf/mpdf/classes/meter.php',
'mpdfform' => __DIR__ . '/..' . '/mpdf/mpdf/classes/mpdfform.php',
'otl' => __DIR__ . '/..' . '/mpdf/mpdf/classes/otl.php',
'tocontents' => __DIR__ . '/..' . '/mpdf/mpdf/classes/tocontents.php',
 'wmf' => __DIR__ . '/..' . '/mpdf/mpdf/classes/wmf.php',
Now run the same web page again in browser. You should not get error.

Lets encrypt error while renewing

The client lacks sufficient authorization :: Invalid response from

Full error :


Attempting to renew cert (domain.co.in) from /etc/letsencrypt/renewal/domain.in.conf produced an unexpected error: Failed authorization procedure. domain.co.in (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://domain.co.in/.well-known/acme-challenge/jfJj7OuSofik58w5Zv9QGADQFTR4OK_nfgVNOfg1xTw: "<!DOCTYPE html>
<html lang="en-US" class="bg-black">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width". Skipping.


Solution :
Do not renew it, instead of install certificates again
sudo certbot --apache -d domain.co.in

Install Lets encrypt on Linux AMI

Run Following Commands :
curl -O https://dl.eff.org/certbot-auto
chmod +x certbot-auto
sudo mv certbot-auto /usr/local/bin/certbot-auto

Make sure apache is running on 443 port and it is opened.

Install mod ssl using following command

sudo yum install mod24_ssl
We have used this command because we have installed httpd using `sudo yum install -y httpd24 php56 php56-mysqlnd`

If you have installed httpd using `sudo yum install httpd`, install mod_ssl using

`sudo yum install mod_ssl`
 
Now install certificates using

certbot-auto -d domain.com --debug

https://coderwall.com/p/e7gzbq/https-with-certbot-for-nginx-on-amazon-linux

Client with the currently selected authenticator does not support any combination of challenges that will satisfy the CA.

lets encrypt has one security vulnerability so changed command for generating https certificates

Solution :
sudo certbot --authenticator webroot --installer apache
Now it will ask the domain name to install certificates for it. Follow the instructions and you can install certificates successfully.

Note :
Now this issue has been fixed. Update lets encrypt and use regular commands.

s3cmd - 400 Bad Request

ERROR: S3 error: 400 (Bad Request):

Solution :
Use latest version of s3cmd
https://sourceforge.net/projects/s3tools/files/s3cmd/

mod_qos(004): failed to create mutex (ACT)(/var/tmp/K564968484.mod_qos): No space left on device

Solution :
Apache cannot be started because of this error, it means you have installed and enabled qos module in apache to avoid ddos attack. Now apache is crashed automatically and you are not able to start it.

Disable qos module

sudo a2dismod qos
Restart apache2

Error : django.db.utils.ProgrammingError: permission denied for relation django_migrations

While running django migrations for postgresql if you get above error, there may be chances that postgresql user which is used in connection file does not have sufficient permissions to run the migrations command. You need to provide privileges to postgresql user using super user.
1. Log into the database which is going to be migrated using super user
\c database name

2. Run following queries
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public to username;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public to username;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public to username;

Change text username with postgresql user which is used in server side postgresql connection file.

Note :
Generally you get this error while running python manage.py migrate 
and above solution works well for this error.

Apache - Block IP or an IP Range to prevent opening your site


If you want to block IPs from accessing your site, you can simply achieve it using an htaccess file. Add following line in .htaccess and IP owner will not be able to open your site anymore.


Suppose you want that your site should not be opened from IP 46.161.9.67, you need to add a line your .htaccess file.
Deny from 46.161.9.67
If there are multiple IPs and you want to block them all. Add following line in .htaccess.
Deny from 46.161.9.67 46.161.10.187 46.161.58.89
Block a whole IP Range
Here is the tricky part, If you want to block a whole IP Range like 69.0.0.0 to 69.0.0.255. Use following code in your .htaccess 

Deny from 69.208.0.0/24
If it is from 69.0.0.0 to 69.0.255.255
Deny from 69.208.0.0/16
And If it is from 69.0.0.0 to 69.255.255.255
Deny from 69.208.0.0/8

Refer Link for more wide Range :
https://www.mediawiki.org/wiki/Help:Range_blocks

Sort all files of present working directory and sub directories by modified date and time

If you want to sort all files of a folder and its subfolders by modified date and time, Here is the command.
find . -type f -printf "%T@ %Tc %p\n" | sort -n
Latest modified file will be last in the sequence.

If you want to reverse the sequence i.e. latest modified should be on top.
find . -type f -printf "%T@ %Tc %p\n" | sort -nr

Dot (.) indicates the present working directory. You can use absolute path also.

Laravel Error - No supported encrypter found. The cipher and / or key length are invalid.

While running  composer install or php artisan optimize, If you get this error, here is the solution.

Solution :

Change values in config/app.php

'cipher' => 'AES-256-CBC',
to
'cipher' => MCRYPT_RIJNDAEL_128,

Now run again composer install or php artisan optimize , you will not get the same error again.