Solved: letsencrypt certbot KeyError: ‘Directory field not found’

While running certbot command I got following error:

[root@vps147238 letsencrypt]# certbot --apache certonly --cert-name purabtech.com -d purabtech.in
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): purab@test.in
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
An unexpected error occurred:
KeyError: 'Directory field not found'
Please see the logfiles in /var/log/letsencrypt for more details.

I am using centos 7.

Solution for this is run following command:

yum install python-certbot-apache -t stretch-backports

It solved my issue.

[root@vps147238 letsencrypt]# certbot --apache certonly --cert-name purabtech.com -d purabtech.in
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Requesting a certificate for purabtech.in
Performing the following challenges:
http-01 challenge for purabtech.in
Waiting for verification…
Cleaning up challenges

CentOS Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org An unexpected error occurred:

While running certonly command I got following error:
[root@vps147238 letsencrypt]# certbot --apache certonly --cert-name purabtech.com -d purabtech.in
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org
An unexpected error occurred:
ConnectionError: (‘Connection aborted.’, gaierror(-2, ‘Name or service not known’))
Please see the logfiles in /var/log/letsencrypt for more details.

I solved this issue by doing following:

$vi /etc/letsencrypt/cli.ini

Put following code in that
server = https://acme-v02.api.letsencrypt.org/directory

It solved my problem…

create self signed certificate for website and use in linux

Within in 5 minutes you can can create self signed certificate on linux machine. First you need to open console and execute following command. Before executing following command first check openssl utility is installed on your linux machine.

# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mysitename.key -out mysitename.crt

Then open your apache configuration file and put following code in that file.

NameVirtualHost *:443

#purabtech.in

  ServerAdmin purabtech@gmail.com
  DocumentRoot /home/purab/public_html/purabtech.in/
  ServerName purabtech.in

  <Directory "/home/purab/public_html/purabtech.in/">
    Order Deny,Allow
    Allow from all
    AllowOverride All
  

  ErrorLog logs/purabtech.in-error_log
  CustomLog logs/purabtech.in-access_log combined
  RewriteLog logs/purabtech.in-rewrite_log

  SSLEngine on
  SSLCertificateFile /home/purab/projects/purabtech.in/self-sign/mysitename.crt
  SSLCertificateKeyFile /home/purab/projects/purabtech.in/self-sign/mysitename.key
  SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
  CustomLog logs/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

Additional:
For gettting pem certificate from ssl cert.
openssl x509 -in mysitename.crt -out mysitename.pem -outform PEM

delete some days old files and folder linux command

Linux systems are always used as server. Many times we need to cleanup the server. I found nice solution for deleting older files and folders from server without any issue.

For deleting files or folder you can use following command:

rm -rf `find /home/purab/* -type d -mtime +90`

Above command will find all files and folders which are created 90 days ago and delete those folders and files.

Before running above command be careful about directory path. please directory path. rm -rf command is always dangerous.

Above We used find command for searching all files in folder.

-mtime is used to calculate time.

If you want to keep only 5 latest folders on server than you can use following command.

ls -dt /home/purab/*/ | tail -n +6 | xargs rm -rf

Above command has three parts.

upgrade to mysql 5.7 in linux from old mysql version

In this tutorial we will show steps to upgrade to mysql 5.7 in linux. We have many server which are running on old mysql versions. What we want to do is, without loosing any data we want to upgrade mysql version.

We are using centos 6 as linux system for our servers. Following commands can be used for any linux os like fedora, debian, centos and redhat.

upgrade to mysql 5.7 in linux

First execute following command.
rpm -qa | grep mysql
Make a note of result. It will show you list of mysql programs which are installed on your system. In case of any issue this list will be with you.

Note: Before upgrading mysql version don’t forget to take mysql database backup of all databases.

Now download latest repository from mysql community server.
Go here and download repo https://dev.mysql.com/downloads/repo/yum/

Look for Red Hat Enterprise Linux 6 / Oracle Linux 6 (Architecture Independent), RPM Package
(mysql57-community-release-el6-7.noarch.rpm) You need to download this rpm.

Using following command you can install mysql 5.7 community repository.
rpm -Uvh mysql57-community-release-el6-7.noarch.rpm

After that stop mysql server using following command.
/etc/init.d/mysqld stop

After that update mysql community server on linux box. use following command.
yum update mysql-community-server

After that install or update following mysql 5.7 dependencies using following command
yum install gcc-c++ gperf uuid-devel libuuid libuuid-devel uuid boost-devel libevent libevent-devel

Install one another dependency of mysql server.
yum install mysql-community-libs-compat

Now your mysql server is updated to 5.7 version. First thing you need to do is check my.cnf file which is mysql configuration file. If my.cnf file is got replaced than put your old file and start mysql server using following command.
/etc/init.d/mysqld start

if mysql server is not starting than you need to start mysql server in safe mode using bellow command.

I faced many issues while mysql upgrade following is one of them. you can check mysql errrors in /var/log/mysqld.log file. I found following error.

InnoDB: pthread_create returned 11

I solved above issue by changing increase the stack size. I executed following command. which solved my issue.

ulimit -s 8192

mysqld_safe --skip-grant-tables &

Now it is time to upgrade your database to mysql 5.7 version. login to your mysql using root password.
mysql -u root -p

For upgrading your database use bellow command.
mysql_upgrade -u root -p --force

Congratulations! you successfully upgraded mysql version to 5.7 version.

Install drush on CentOS using command line with simple steps

Drush is great native application for development of drupal project. I really like to use this tool in every project. There are some good steps to install drush on Linux or windows environment. I recently installed drush on my centos machine. Here are those steps:

Commands has been highlighted in blue color.

[root@ap107 purab]# wget http://files.drush.org/drush.phar
–2016-04-21 11:50:43–  http://files.drush.org/drush.phar
Resolving files.drush.org… 54.231.81.40
Connecting to files.drush.org|54.231.81.40|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 5264426 (5.0M) [application/octet-stream]
Saving to: “drush.phar”

100%[===========================================================================================================================================================>] 5,264,426    221K/s   in 65s

2016-04-21 11:51:50 (78.5 KB/s) – “drush.phar” saved [5264426/5264426]

[root@ap107 purab]# php drush.phar core-status
PHP configuration      :  /etc/php.ini
PHP OS                 :  Linux
Drush script           :  /home/purab/drush.phar
Drush version          :  8.0.5
Drush temp directory   :  /tmp
Drush configuration    :
Drush alias files      :

[root@ap107 purab]# chmod +x drush.phar

[root@ap107 purab]# mv /usr/local/bin/drush /usr/bin/drush
[root@ap107 purab]# drush init
Copied example Drush configuration file to /root/.drush/drushrc.php                                                                                                                       [ok]
Copied example Drush bash configuration file to /root/.drush/drush.bashrc                                                                                                                 [ok]
Copied Drush completion file to /root/.drush/drush.complete.sh                                                                                                                            [ok]
Copied example Drush prompt file to /root/.drush/drush.prompt.sh                                                                                                                          [ok]
# Include Drush bash customizations.
if [ -f “/root/.drush/drush.bashrc” ] ; then
source /root/.drush/drush.bashrc
fi

# Include Drush completion.
if [ -f “/root/.drush/drush.complete.sh” ] ; then
source /root/.drush/drush.complete.sh
fi

# Include Drush prompt customizations.
if [ -f “/root/.drush/drush.prompt.sh” ] ; then
source /root/.drush/drush.prompt.sh
fi

Append the above code to /root/.bashrc? (y/n): y
Updated bash configuration file /root/.bashrc                                                                                                                                             [ok]
Start a new shell in order to experience the improvements (e.g. `bash`).                                                                                                                  [ok]
[root@ap107 purab]# drush

how to install memcached on centos

We given steps for install memcached on centos. Memcached server is used for increase server performance and response time. Here we given the commands for installing memcached on centos.

how to install memcached on centos

I always need to install the memcached on my linux servers like fedora or centos. On fedora box installing the memcached is very easy through yum install. But Centos installing and using memcached is not so easy.

how to install memcached on centos
how to install memcached on centos

For my Ruby on Rails and PHP applications I always need to install the memcached on server. Here I am going to give you the steps for installing the memcached.

Very important note: you need to install the gcc compiler for memcached binary installation. Using the memcached with php installation you need the phpize and php-pecl-memcached installed. follow my steps and memcached binary installation.


# yum install gcc*
# cd /usr/src
# wget http://pecl.php.net/get/memcache-2.2.5.tgz
# tar zxvf memcache-2.2.5.tgz
# cd memcache-2.2.5
# phpize
# ./configure
# make
# make install

For checking the php.ini file path use following command.


php -i | grep php.ini

Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini

or your php.ini file will be following location


# vim /etc/php.ini

Put following line in that file
extension = “memcache.so”
Restart the apache server

# /etc/init.d/httpd restart

To check is memcache extension loaded in php, execute following command.

#php -i | grep memcache

After restarting the machine memcache need to restart. For that us ( Use this step for only Admin Adserver Box)

# vi /etc/rc.local

Put following contect in to rc.local file (file location – /etc/rc.local)

# memcached -d -p 11211 -u nobody -c 1024 -m 1024

How to install imagemagick binary on CentOS

For many application we need to install the imagemagick on Centos linux server. Many Ruby on rails and PHP applications need the support of imagemagick for image resizing.

How to install imagemagick binary on CentOS

 

How to install imagemagick binary on CentOS
How to install imagemagick binary on CentOS

We all the very traditional way of installing the application on linux machine which is as follows:

# yum install imagemagick

This command will not install the imagemagick on Centos properly. So use following commands for installing the imagemagick on centos

#yum install gcc*

#cd /tmp

# wget ftp://ftp.fifi.org/pub/ImageMagick/ImageMagick-6.6.1-10.tar.gz

# tar xzf ImageMagick-6.6.1-10.tar.gz

# cd ImageMagick-6.6.1-10

# ./configure

# make

# make install

After using the above commands imagemagick will be installed the properly on CentOS machine.

If you have any trouble or issues during installation then get back to me.

how to install php-pear on centos or redhat

centos is linux based operating system which is used for server purpose. in this article I given the detailed information about, install php-pear on centos or rehat os.

For this example I used the RHEL 5.3 edition. If server is new then use follwoing commands to keep server up to date.
When I tried to install php-pear lib in server I am not able to install all the pear libs. Then I Used following commands for installing the php-pear fully.

install php-pear on centos

# yum update
# up2date -u
# yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy php-pear php-devel httpd-devel mysql-server mysql-devel

The 2 RPMs which we need are:
epel-release and remi-release

# wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
# rpm -Uvh epel-release-5-3.noarch.rpm

# wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
# rpm -Uvh remi-release-5.rpm

# yum install php-pear*

# /sbin/service httpd start
# /sbin/service mysqld start

# php -v

install php-pear on centos
install php-pear on centos