How to enable the MySQL slow query log

MySQL slow query log can be to used to determine queries that take a longer time to execute in order to optimize them. The slow query log consists of SQL statements that took more than `long_query_time` seconds to execute, required at least `min_examined_row_limit` rows to be examined and fulfilled other criteria specified by the slow query log settings.

Before enabling the MySQL slow query log, we must decide criteria for SQL statements that will be logged and also select the location where they will be logged.

Continue reading »

How to fix WordPress 404 Error on saving a new post or updating a post?

I was working on a blog post and had written a part of it and saved it. After some days, I visited the post again to complete it but it would not save, clicking on “Save Draft” button displayed a 404 not found page.

I tried to edit the post with same new content multiple times but same 404 error. Then, since I already had some post content saved, I tried to save it again with no update; it worked. So, I started updating the post content in steps, it was working and content was saving.

Continue reading »

How to use cookies in JavaScript?

A Cookie is a piece of information that is stored locally on users browser and is sent with each HTTP request to the server. HTTP being a stateless protocol, cookies provide a mechanism by which we can remember user preferences and share information between web pages.

The cookies have a limit of 4KB thus when this limit is reached, you will likely be unable to create a new cookie. To make it more clear, size of all cookies under a specific domain cannot exceed 4KB.

Continue reading »

Understanding & Installing Node.js and NPM

We have been using client side/front end JavaScript to build dynamic pages where we embed the JavaScript code in HTML file, react to events and make AJAX calls for fetching data from the server.

Node.js allows you to write server side and networking applications with JavaScript.

Node.js is an open-source, cross-platform run-time environment that executes JavaScript code server-side. It is build on built on Chrome’s V8 JavaScript engine. It uses an asynchronous event-driven model and is designed for writing scalable internet applications, notably web servers.

Continue reading »

How to drop all tables in MySQL database

Once I faced a situation wherein I had no option to delete the database and was limited to use only the MySQL command line. I wasted a lot of time find and trying different ways to delete all tables in the database. So, I thought it will be worth sharing things that ultimately worked for me.

$ mysqldump -hHOSTNAME -uUSERNAME -pPASSWORD --add-drop-table --no-data DB_NAME | grep -e '^DROP \| FOREIGN_KEY_CHECKS' | mysql -hHOSTNAME -uUSERNAME -pPASSWORD DB_NAME;

Continue reading »

How to upload large files in PHP

By default PHP is configured to allow files upload of size upto 2M.

We need to adjust the following PHP configuration directives:

  1. upload_max_filesize: By default this value is 2M. We need to increase it to the maximum size of single file that we want to upload.
  2. post_max_size: It defines the maximum size of POST data that PHP will accept. This value should be greater than ‘upload_max_filesize’.
  3. memory_limit: This sets the amount of memory a PHP script is allowed to use during its execution. Set this to a value greater than ‘post_max_size’ so that PHP script can load and process the uploaded file.

Continue reading »

How to disable textarea resizing

If we add a simple textarea in a HTML form then we see that we can resize it by clicking on the bottom right corner of the textarea and dragging the mouse.

<textarea id="txt1" name="txt1" rows="5" cols="50"></textarea>

If we want to stop this resize then you have to just add a simple css as shown below.

textarea {
    resize: none;

Continue reading »

How to set up HTTP authentication with nginx

We will demonstrate you how to setup HTTP Authentication with Nginx on Ubuntu in this article. We are using Ubuntu 16.04.1 and have nginx version: nginx/1.10.0 installed in our machine.

“htpasswd” is used to create and update the files used to store usernames and password for basic authentication of HTTP users.

Following are the steps that we need to follow:

  1. apache2-utils
  2. Create username and password
  3. Update Nginx configuration
  4. Reload the Nginx Configuration

Continue reading »

How to temporarily disable Foreign Key Checks or Constraints in MySQL

While importing a database that has tables with foreign keys defined we get to see error “#1452 – Cannot add or update a child row: a foreign key constraint fails“.

Even while trying to delete some tables from such a database, we come across situation where we face foreign key constraint error: “#1217 – Cannot delete or update a parent row: a foreign key constraint fails

To avoid such errors first disable the foreign key checks, then do your job of importing the database or deleting the table and finally enable the foreign key checks.

Continue reading »

WinSCP: How to view the hidden files like .htaccess

WinSCP comes with a configuration setting that allows you to show or hide the hidden files . To view the hidden files, activate the setting by going to:

Options >> Preferences >> Panels

Select the “Show hidden files”  option under the common settings and click the “OK” button.

Continue reading »

Back to top