How to fix SQLSTATE[HY000] [1698] Access denied for user ‘root’@’localhost’ (1698) Laravel

How To fix the following Error in Laravel when Try connect to the database?

APP_NAME=gestion_magasin
APP_ENV=local
APP_KEY=base64:6o5/esvKCiBvWTN1q2nWqvNMa0m6zJe8lEwheglLctM=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=gestion_magasin
DB_USERNAME=user
DB_PASSWORD=password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

You need to create New User for MySQL and don’t try with root credential :

$ sudo mysql -u root

Then CREATE or ALTER a non-root user (use ‘127.0.0.1’ instead of ‘localhost’ if needed):

CREATE USER 'admin'@'localhost' IDENTIFIED BY 'adminspassword';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';
FLUSH PRIVILEGES;

And edit the .env file:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3630
DB_DATABASE=yourdbname
DB_USERNAME=admin
DB_PASSWORD=adminspassword

at end, better clear cache :

php artisan cache:clear
php artisan config:clear
php artisan cache:clear

 

How to Exclude Files and Folder when Make a tar archive

If you want to make an archive of your files and folders, but you want to exclude some files or folders, this tutorial explains how to do this.

In this tutorial, using the tar command, we want to archive all the files and folders in the directory where we are. But “wp” folders and files with the “tar.gz” extension are excluded.

The procedure is very simple, in general, if you want to archive all the contents of your folder, we run the following command:

$ tar -zcvf /backup/filename.tgz .

In the example above, -zcvf is to apply the command settings, “/backup/filename.tgz” is to specify the name and path of the archive storage. And “.” To specify the folder we want to archive.

But since we want to exclude the “wp” folder, adding exclude is done as follows:

$ tar --exclude='./wp' -zcvf /backup/filename.tgz .

If we want to add more than one template to the set of exceptions, we do the following:

$ tar --exclude='./wp' --exclude='./upload/folder' -zcvf /backup/filename.tgz .

 

If we want to add more than one template to the set of exceptions, we do the following:

$ tar --exclude='./wp' --exclude='*.tar.gz' -zcvf /backup/filename.tgz .

 

Attention :

Make sure to put --exclude before the source and destination items.

How to Generate Certificate Signing Request (CSR) on Linux

CSR stands for ‘Certificate Signing Request’, that is generated on the server where the certificate will be used on. A CSR contains information about to your organization and domain name, locality, and country and a public key that will be included in your certificate.

This article has 3 methods to create CSR (Certificate Signing Request) on Linux systems. You can choose any one of below methods. All methods will do the same task, only they have a detailed explanation.

Read More

How to enable passive FTP connections in ProFTPD

Passive mode can sometimes resolve certain clients ability to connect to the FTP server which may have been blocked by firewalls. If you are having issues connecting remotely,  would like you to try to to enable passive connections in ProFTPD you will need to edit /etc/proftpd.conf.

1. Edit the /etc/proftpd.conf file:

vi /etc/proftpd.conf

And add the following lines with the letter “i” to insert:

PassivePorts 60000 65535
AllowStoreRestart on
 AllowRetrieveRestart on
 TimeoutNoTransfer 65535
 ListOptions "-la"
 TimeoutIdle 65535

2. You will then also need to add the passive range in the firewall.

IPtables:

  • Add the new rule:
iptables -A INPUT -p tcp -m tcp --dport 60000:65535 -j ACCEPT
  • Save the ruleset:
iptables-save > /etc/sysconfig/iptables

Firewalld: 

  • Add the new port range:
firewall-cmd --permanent --add-port=60000-65535/tcp
  • Reload the firewall:
firewall-cmd-reload

3. Testing The FTP Service

You can test the FTP configuration locally first to ensure the daemon is running by using netstat

# netstat -plan|grep :21

You can also connect locally by installing the ftp client

yum install -y ftp

And then making a connection to the localhost or 127.0.0.1

 ftp localhost

How add .iso extension on IIS mime type file

If you want download iso file from IIS webserver may you got 404 Error like following screen :

You must add the correct MIME type for the file you’re trying to download.

From IIS Manager, go to Sites > YOUR_SITE> and in the features view, double-click MIME Types.

Under actions, click Add.

Enter the file extension iso and the MIME type application/octetstream

Click OK and retry your download.

How run MySQL dump inside mysql console

Sometimes it may be necessary to use the mysqldump command in the mysql command line. As you know, this command is an external command and must be executed separately, but with the method we teach, you can also use it in the mysql command line.

 

For this purpose, it is enough to use the phrase \!at the beginning of the command.

\! mysqldump -u username -p database > database_dump.sql