Thursday, 27 April 2017

Change modified time of file using PHP Touch()

<?php

$file = 'touch.php';

// One you use filemtime it stores, You will need to clear cache before using it again.
echo '<br/>';
echo "$file was last modified: " . date ("F d Y H:i:s.", filemtime($file));

clearstatcache();
 
// This is the touch time, we'll set it to one hour in the past.
$time = time() - ( 3600 * 24 ); // 1 day before

// Touch the file
if (!touch($file, $time)) {
    echo 'Whoops, something went wrong...';
} else {
    echo "<br/> $file was last modified: " . date ("F d Y H:i:s.", filemtime($file));
}

?>

Monday, 24 April 2017

Set permissions for all files and folders recursively PHP LINUX COMMAND

PrestaShop : While installation PS every time this F*****g  Folder and Files permission issue happens to me.

In general cache folder needs 777 permission and rest are 755 for folders and 644 for files. Following is PHP script which will do that. It solved many permission related issues.

Following PHP script will update all folder permission to 755 and all files with 644 permission.

<?php
exec ("find /path/to/folder -type d -exec chmod 0755 {} +");
exec ("find /path/to/folder -type f -exec chmod 0644 {} +");
?>


What are File Permissions?

There are three types of permissions:

  •     Read
  •     Write
  •     Execute

You can view your file permissions in your cPanel File Manager or FTP Client.  They will display not with the letters, but with numbers.  The numbers used are:

    7 = read, write, execute
    6 = read, write
    5 = read, execute
    4 = read only
    3 = write, execute
    2 = write only
    1 = execute only
    0 = Access Denied

The File Permissions will show as three numbers. The numbers always go in the same order:

  •     User
  •     Group
  •     World


Thursday, 20 April 2017

HTTP Error Codes and Fixes

HTTP codes describe the status of a URL when a visitor attempts to access it, and include error messages that describe the problems that the visitors encountered. The codes are three-digit numbers.
There are five classes of HTTP codes, which are divided into categories by the first digit.
A first digit of 1, 2, or 3 represents a fully functional request.

A first digit of 4 represents a client-side error. The most common codes span 400 to 404.

A first digit of 5 represents a server-side error. Common codes span 500 to 510.

Note:
For more information, read the Wikipedia article on HTTP codes.
4xx Errors

These errors are technically the result of a problem with the client's (for example, the browser's) request, but they often point to a problem on a website. For example, if a faulty link is on your home page, and visitors click it, they will see a 404 error.

For this reason, it is important that you monitor these errors and investigate their causes. Because these are also among the highest-profile codes (visitors see them the most), you may want to customize these error pages in cPanel's Error Pages interface (Home >> Advanced >> Error Pages).

400 Bad Request
The user's request contains an incorrect syntax.

401 Unauthorized
The requested file requires authentication (a username 
and password).

403 Forbidden
The server will not allow the visitor to access the requested file. If a visitor sees this code in error, check the file's permission settings. You can also check to see whether the file is protected in cPanel's Index Manager interface (Home >> Advanced >> Index Manager).

404 Not Found
The server could not find the file that the visitor requested. This error commonly occurs when a visitor mistypes a URL.
5xx Errors
These errors occur when a server cannot fulfill an apparently valid request from a visitor. Often, you will need the help of a server administrator in order to investigate these errors.
It is also important to consider that many times, a chain of servers handles an HTTP request. This means that your web server may not be the server that returned the error.

500 Internal Server Error
This error signifies that the server encountered an unexpected condition. It is a multipurpose error that displays when the server cannot gather any specific information about the problem. This error often occurs when the server cannot fulfill an application request because the application was misconfigured.

501 Not Implemented
This error signifies that the server does not support the HTTP method that the client used. This error occurs often if the server is out of date. This error is very rare and generally requires that the system administrator update the web server.

502 Bad Gateway
This error usually occurs due to improperly configured proxy servers. However, the problem may also arise when there is poor IP communication between backend computers, when the client’s ISP is overloaded, or when a firewall functions improperly.
The first step to resolve the issue is to clear the client’s cache. This action should result in the use of a different proxy to resolve the web server’s content.

503 Service Unavailable
This error occurs when the server cannot handle requests because of a temporary overload or because the server is temporarily closed for maintenance. The error signifies that the server will only be unavailable temporarily. It is possible to receive other errors in place of 503.
Contact the server administrator if this problem persists.

504 Gateway Timeout
This error occurs when a server does not receive a timely response from another server. Slow communication between upstream servers causes this problem.
To resolve this issue, contact the system administrator.

505 HTTP Version Not Supported
This error occurs when the server refuses to support the HTTP protocol that the client computer specifies. It occur if the client computer does not specify the protocol properly (for example, if it specifies an invalid version number).
This error should not occur if you have a current installation of cPanel & WHM.

506 Variant Also Negotiates
This error indicates that the server is not properly configured. Contact the system administrator to resolve this issue.

507 Insufficient Storage
This code indicates that the server is out of free memory. This error is likely to occur when a requested application cannot allocate the necessary system resources in order to run.
To resolve the issue, the system administrator must restart the server, or take steps to free or add disk space. Contact the system administrator for more information about this error message.

509 Bandwidth Limit Exceeded
This error occurs when you reach the bandwidth limit that the system administrator imposed. The only solution for this issue is to wait until the limit is reset in the following cycle.
Consult the system administrator for information about how to acquire more bandwidth.

510 Not Extended
This error occurs when the web server does not support an extension that is attached to the HTTP request.
To resolve the issue, you may need to update the server. Consult the system administrator for more information.

Thursday, 13 April 2017

PrestaShop Path

PS PATHS

01 $base_dir { root folder of your shop }
02 $base_dir_ssl { root folder of your shop using HTTPS protocol }
03 $content_dir { root folder of your shop depending on the SSL settings }
04 $img_ps_dir { root folder containing images "/img/" }
05 $img_dir { images folder in your current theme directory }
06 $css_dir { css folder inside the current theme folder }
07 $js_dir { JavaScript inside the theme folder }
08 $tpl_dir { theme root folder }
09 $modules_dir { modules root folder }
10 $mail_dir { mail templates root folder }
11 $lang_iso { current language ISO code }
12 $come_from { previous page address [absolute] }
13 $shop_name { your specified shop name }
14 $cart_qties { total number of products in the cart }
15 $cart { shopping cart contents }
16 $currencies { pulls available currencies }
17 $id_currency_cookie { selected currency id [cookie dependent] }
18 $currency { active currency }
19 $cookie { active cookie }
20 $languages { grabs available languages }
21 $logged { checks whether users is logged in }
22 $page_name { current page's name }
23 $customerName { customer name [session dependent] }
24 $priceDisplay { current price display settings [currency dependent] }
 

THEME CSS AND JS FOLDERS

$img_ps_dir //URL for the PrestaShop image folder.
$img_cat_dir //URL for the categories images folder.
$img_lang_dir //URL for the languages images folder.
$img_prod_dir //URL for the products images folder.
$img_manu_dir //URL for the manufacturers images folder.
$img_sup_dir //URL for the suppliers images folder.
$img_ship_dir //URL for the carriers (shipping) images folder.
$img_dir //URL for the theme’s images folder.
$css_dir //URL for the theme’s CSS folder.
$js_dir //URL for the theme’s JavaScript folder.
$tpl_dir //URL for the current theme’s folder.
$modules_dir //URL the modules folder.
$mail_dir //URL for the mail templates folder.
$pic_dir //URL for the pictures upload folder



Usage in template files
<img src="{$img_dir}abc.jpg" >

Sunday, 2 April 2017

MySQL: How to export and import an .sql file from command line?

<?php
set_time_limit(0);
exec("mysqldump -u root -pPASSWORD databasename | gzip > dump.sql.gz");
?>

=====================================

To EXPORT

   
If it's an entire DB, then:
$ mysqldump -u [uname] -p[pass] db_name > db_backup.sql


If it's all DBs, then:
$ mysqldump -u [uname] -p[pass] --all-databases > all_db_backup.sql


If it's specific tables within a DB, then:
$ mysqldump -u [uname] -p[pass] db_name table1 table2 > table_backup.sql


You can even go as far as auto-compressing the output using gzip (if your DB is very big):
$ mysqldump -u [uname] -p[pass] db_name | gzip > db_backup.sql.gz


If you want to do this remotely and you have the access to the server in question, then the following would work (presuming the MySQL server is on port 3306):

$ mysqldump -P 3306 -h [ip_address] -u [uname] -p[pass] db_name > db_backup.sql


=====================================

To import

Type the following command to import sql data file:
$ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql


In this example, import 'data.sql' file into 'blog' database using Sathish as username:
$ mysql -u sat -p -h localhost blog < data.sql


If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
$ mysql -u username -p -h 202.54.1.10 databasename < data.sql


OR use hostname such as mysql.cyberciti.biz
$ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql



If you do not know the database name or database name is included in sql dump you can try out something as follows:
$ mysql -u username -p -h 202.54.1.10 < data.sql

Refer: http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html