SSH: Backup all databases

You can dump all the databases into a single .sql file like so:

mysqldump --all-databases > database_backup.sql

Or you can dump them individually to a directory with the date of backup to /home/ by using a for loop, such as this:

now=$(date +"%m_%d_%Y");mkdir /home/mysql.back.$now && for i in $(mysql -BNe 'show databases'| grep -v _schema);do echo $i; sudo mysqldump $i > /home/mysql.back.$now/$i.sql ; done 

Split and merge large files

Use the split command to do this:

split --bytes=1024m bigfile.iso small_file_

That command will split bigfile.iso into files that are 1024 MB in size (1GB) and name the various parts small_file_aa, small_file_ab, etc. You can specify b for bytes, k for Kilobytes and m for Megabytes to specify sizes.

To join the files back together on Linux:

cat small_file_* > joined_file.iso

Similarly to join the split files on a Windows machine, use the copy command:

copy /b small_file_* joined_file.iso

Source:
http://linuxpoison.blogspot.com/2008/09/split-and-merge-large-files.html

Htaccess: how to force “www.” in a generic way?

This works on any domain

#Remove the below two comments to disable it on localhost
#RewriteCond %{HTTP_HOST} !=localhost
#RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

SSH: How to Fix Permissions on Files and Directories?

Here are the SSH commands to fix your permissions on a mass level:

    find ~/public_html -type d -exec chmod 755 {} \;

    find ~/public_html -type f -exec chmod 644 {} \;

Basically, the format is to find, or look, in the path of ~(which means home) and then in public_html. (If you want to look in a different directory, you can change this. e.g. ~/public_html/myblog) And then it looks for the document type, be it directory (d) or file (f), and executes the chmod(change mode) command to change the permissions on all results.

How to tar/untar, compress/uncompress files/folders using php script

How to tar/untar, compress/uncompress files/folders using php script

How to tar/untar, compress/uncompress files/folders using php script

Uploading and downloading files is a chore every webmaster has to cope with on daily basis, but if you do this by compressing the files, uploading the tar or zipped and uncompressing them on server, life becomes a little easier.

Similarly taking backup on a server becomes easier if you just compress the files/folder on server and download the tar.gz file. Usually these commands are run over SSH, but if you do not have SSH access, you can place the commands in php script too.
(more…)

SSH: How to Fix Permissions on Files and Directories?

SSH: How to Fix Permissions on Files and Directories?

SSH: How to Fix Permissions on Files and Directories?

Here are the SSH commands to fix your permissions on a mass level:

    find ~/public_html -type d -exec chmod 755 {} \;

    find ~/public_html -type f -exec chmod 644 {} \;

Basically, the format is to find, or look, in the path of ~(which means home) and then in public_html. (If you want to look in a different directory, you can change this. e.g. ~/public_html/myblog) And then it looks for the document type, be it directory (d) or file (f), and executes the chmod(change mode) command to change the permissions on all results.

Page 1 of 41234

Pin It on Pinterest