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.

Disappearing SSL certificates from IIS 7.0 Manager



Disappearing SSL certificates from IIS 7.0 Manager


Keep in mind that they are going to cost you much.

If you have two ssl certs for a domain.com and then a sub.domain.com, these two certs cannot be installed in IIS servers upto version 7.5.  IIS8 on Windows 2012 supports it though.

Note: you need to create the csr on the machine where you will be installing the ssl certificate. otherwise, the private key is not present and the ssl certificate is not installed properly.

Solution:

Got this below information from elsewhere...

JBrunelle
April 9, 2014 at 8:01 am
If anyone is still watching this thread… I came across this with a digicert cert as well. What I did was import it anyway into IIS. After adding it, but before it disappeared I right-clicked and selected view on the cert, went to the Details tab, and selected copy to file. Selected to export the private key, and assigned a password. Then I refreshed (cert was gone) and re-imported the now .pfx cert and entered the password.

Worked like a charm.

1. Import cert anyway

2. Right-click > View

3. Details tab > Copy to File

4. Export PK, assign password, export as .pfx

5. Import new .pfx





It didn't work for me, though. Because, I had created the csr from a Centos 7 linux server.

It is indicated that the certificate may not be installed and doesn't work if the private key is not part of the SSL certificate.

So, I copied the issued certificate to my Centos 7 server and then issued the following command to export it to .pfx format

openssl pkcs12 -export -out sub.domain.com.pfx -inkey sub.domain.key -in sub.domain.com.crt -certfile sub.domain.com-intermediate-cert.crt
Enter pass phrase for sub.domain.key:
Enter Export Password:
Verifying - Enter Export Password:

In the above, enter the pass phrase you keyed in during the creation of the certificate signing request.

The resultant .pfx file created may be used to install the SSL certificate in your IIS server.

After all this effort, if you are trying to install the two certificates on an IIS 7.5 web server or less, you are bound to be unsuccessful, because multiple certs for multiple domains are supported only in IIS 8+ onwards.

That is what we found the hard way. May be we should have researched better.

So, that's what we will be doing. Setting up the Windows 2012, IIS 8+ and install the certificates separately.

Will keep you updated.

A simple introduction to jQuery

jQuery - A small introduction

What is jQuery?


jQuery is a JavaScript library, one of many available in the market, which can be used to create actions on your web pages, based on user interactions.

All that can be done using jQuery can be done using JavaScript itself. But, it is going to be a big task, in terms of time spent and repetitive code content. By using jQuery, you avoid repetitive code blocks, while making code writing simple and making it easy to make corrections to your code.

What can I do with jQuery?


You can make highly interactive user interfaces, which create rich user experience for the end user.

Show me a simple example of jQuery

jQuery is used in tandem with HTML and JavaScript and BootStrap, usually. The steps involved are creating the HTML document, with the necessary lines to refer to the JavaScript and the BootStrap libraries.

Next, the HTML text is created, if required.

Finally, the jQuery code is written.

The code, given below, will show a message which informs the user "jQuery says Hello!".


The HTML + jQuery Code


<!DOCTYPE html>
<html>
<head>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

</head>

<body>
This is a sample HTML file created to demonstrate jQuery. Refresh this page to see again the message alert created through jQuery.
<script>
$(document).ready(function() {
alert("Hello from jQuery!");
});
</script>
</body>
</html>

The Explanation

What you need to notice is the statement $(document).ready();

That will be your default statement for all your html, if you want jQuery in your html. The above code tells the browser to execute the code within the function when the entire document has been loaded.

What we have done:

We have inserted a JavaScript function inside the ready() function and gave an alert() call with a greeting message.

function() {
alert("jQuery says Hello!");
}

The function; it is called an anonymous function, since we have not attributed a name to it, will be called right at the moment when the html document has finished loading.

Congratulations! You have just now completed your first jQuery program.

How do I calculate the fixed tax amount from the overall amount


How do I calculate the fixed tax amount from the overall amount


This was a task that came to me today. One of our colleagues wanted to calculate the tax payable to the government. 

Most businesses, especially when doing business in known circles are given only a rounded amount for services rendered or products purchased.

So, if the product is 1200 + taxes, the customer will only pay 1200 nett.

The onus is on the seller, to calculate the actual amount of tax payable.

Now, I wanted to find out what will be my tax amount, that is the amount I will have to pay the government as tax, from the 1200 i received from my customer.

The tax percentage is 28.75. I need to find out x, which will be the value I will retain and 1200 -x will be the tax amount payable.

My equation for the solution was this.

1200 =x + (x * 28.75/100)

I wanted a quick answer. My algebra was rusty due to years of disuse. It was then mathpapa.com came to my rescue, with its algebra calculator that gave me the simplified equation.

Mathpapa Algebra Calculator

It is a simple algebra calculator, which enabled me to calculate the tax amount from the overall amount.

So, when I filled in the formula in the text box, the site calculated the formula and the value of x for me; which is 1200/1.2875

So, there you are!

Formula to calculate the fixed tax amount from the overall amount

Tax amt payable = Overall amount / 1.(Tax percentage x 100)

Parse error: syntax error, unexpected '=' in path/to/filename.php on line


Parse error: syntax error, unexpected '=' in path/to/filename.php on line xxx

It is usual to get cryptic error messages when executing php code. It is not intentional but essentially it tells us that the code is not right in just about the indicated area. 

Take a look at the sentence given below.

variable ="select item from my_images where id =$key";

We will have to look a little ahead and a little behind the "=" symbol, in this case.

At first glance, everything seems to be in order. This is true, especially, when one is in an agitated condition.

But, if you analyse the php program statement carefully, you will notice that you have forgotten to place the mandatory $ sign, which indicates that the word is a php variable.

This is a common error in php. 

Place the $ sign before the variable name and all things seem okay.

As to the question of why you need the $ in the first place, it is to declare that this specific word will store some information within.

It provides more clarity to the code and the habit is continued from other programs such as Perl, where a $ is prefixed to define a variable as well.

Bluetooth on off Switch missing in Windows 10

  Sometimes, what happens is that you are unable to switch the Bluetooth in your PC or laptop. Even if you are a professional, it gets you f...

Most Popular

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