Steps to install wkhtmltopdf in Centos 7 Redhat

Steps to install wkhtmltopdf in Centos 7 Redhat Linux


As you may know, wkhtmltopdf is a tool that is used to create a pdf on the fly from the Linux/Unix shell from any html document. You are probably running Centos 7 Redhat on (AWS) Amazon EC2 server. Outlined here are the simple steps on how to install.

Step 1 is to create a html document
Step 2 is to call wkhtmltopdf with the html document as input and pdf as output

But, before that, we need to install wkhtmltopdf in the Linux server machine.

Install wkhtmltopdf in Centos 7

Before we install wkhtmltopdf, we need to install the dependencies or support packages, which are required for wkhtmltopdf to work as expected.

So, we execute the following steps.

i. sudo yum install -y xorg-x11-fonts-75dpi
ii. sudo yum install -y xorg-x11-fonts-Type1

Let us get the rpm package from the link gna.org using the link below.
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm

sudo rpm -Uvh wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm

error: Failed dependencies:
        libXext is needed by wkhtmltox-1:0.12.2.1-1.x86_64
        libXrender is needed by wkhtmltox-1:0.12.2.1-1.x86_64

As you can see, there are two libraries that are missing. Let us install them too.


Install dependencies libXext libXrender for wkhtmltopdf


iii. sudo yum install libXext libXrender

Loading mirror speeds from cached hostfile
 * base: mirror.web-ster.com
 * epel: mirrors.cat.pdx.edu
 * extras: mirrors.xmission.com
 * updates: centos.eecs.wsu.edu
Resolving Dependencies
--> Running transaction check
---> Package libXext.x86_64 0:1.3.3-3.el7 will be installed
---> Package libXrender.x86_64 0:0.9.8-2.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved



Installing:
 libXext                                  x86_64                               1.3.3-3.el7                                    base                                39 k
 libXrender                               x86_64                               0.9.8-2.1.el7                                  base                                25 k



Install  2 Packages

Total download size: 64 k
Installed size: 127 k
Is this ok [y/d/N]: y
Downloading packages:
(1/2): libXrender-0.9.8-2.1.el7.x86_64.rpm                                                                                                      |  25 kB  00:00:00
(2/2): libXext-1.3.3-3.el7.x86_64.rpm                                                                                                           |  39 kB  00:00:00

Finally, let us try installing the rpm package again.

iv. sudo rpm -Uvh wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:wkhtmltox-1:0.12.2.1-1           ################################# [100%]

We have successfully set up and installed wkhtmltopdf on our machine.

Now, let us test if the module is working. We will try to create a pdf document  out of Google's first page.

wkhtmltopdf https://www.google.com google.pdf

Fatal Error Call to undefined function mcrypt_encrypt() .php on line 13

Call to undefined function mcrypt_encrypt() in file.php on line

Recently, we were trying to port a php application from the test server to the live Centos server and encountered this unusual undefined function mcrypt_encrypt error.

When porting from my local server to the live server for testing, the php page was not loading and returned an Error 500 or Internal Server Error.


Analyse Apache error logs

Apparently, the error logs of the Apache web server had to be analyzed. 

So, as a first step, we tried to analyse the apache error logs to shortlist the reasons. On closer look, the following line seemed to hold the key to the problem.

PHP Fatal error:  Call to undefined function mcrypt_encrypt() in /path/to/myAppFolder/myFile.php on line 13


The reason for undefined function mcrypt_encrypt() problem

Missing php-mcrypt module


The issue seems to be related to a missing module in the Centos server. The php program was using the php-mcrypt module and it was not yet installed on the server yet.


Install php-mcrypt and restart Apache


The next logical step is to setup thephp-mcrypt module. So, we installed the php-mcrypt module using the below command

sudo yum install php-mcrypt

Once the php-mcrypt was installed, we need to restart the Web Server. As a final step, we restarted the Apache Web Server using the following command.

sudo systemctl restart httpd

After this, we tested the web application to see if the undefined function mcrypt_encrypt problem persists. To our relief, calling the php program did not generate error now. 

Problem of Fatal Error Call to undefined function mcrypt_encrypt() php 7 SOLVED.

Ajax call not working as expected in Firefox



Ajax call not working as expected in Firefox

Okay, I had this peculiar problem of my web form updating the relevant tables when being called from Google Chrome and not doing so, when the call was made through Firefox.

The form went into sleep and did not respond after the Submit button was clicked. It looked as if the Ajax call was in indefinite loop in Mozilla Firefox.

As we went digging for reasons that this was happening, we realised that Firefox is strict about how data has to be sent to it. For the ajax call to work as expected, the ajax code needs to follow a certain format.

Google Chrome is someone who tries to make sense out of the data and so, the code got accepted by Chrome.

Ultimately, we understand that what we need to return from a php program, which is being called through an ajax request, is content preceded by a header, which indicates the type of content that follows.

It could be any of these types as defined below.

Header Content-type: Common examples:
application/json
application/x-www-form-urlencoded
application/pdf
multipart/form-data
text/html
text/plain
image/png
image/jpeg

image/gif

So, at the end of your php code, you will  have something like what you are seeing below. In the first example, the returned value is a json content, while the second example returns a plain text message in response to the Ajax request.

Php program returning JSON in response to an Ajax call, Example 1:


    header('Content-type: application/json');
    echo json_encode($response_array);
?>


Php program returning text value to Ajax call, Example 2:


    header('Content-type: text/plain');
    echo 'success';
?>

Finding at the end of the exercise: Firefox expects that the ajax return value, json or otherwise, be preceded by a header. This has to be strictly followed for our ajax call to work correctly.

Imagen 3: A New Era of AI Image Creation?

  Google has just unveiled Imagen 3, the latest iteration of their Gemini AI. They're making bold claims about enhanced image quality, ...

Most Popular

Copyrighted.com Registered & Protected DWYE-NHTO-NBNH-7FFM