Sunday, August 24, 2014

// // Leave a Comment

Auto fix for file permissions and ownership [CPANEL]

suPHP and FastCGI require files and folders to have a specific set of permissions/ownership from other handlers. Without these permissions set you will see a lot of errors such as: “403 Forbidden”, “500 Internal Server Error”, or simply generic errors that commonly have the word ‘permission’ in them.
It can be very time consuming to track down and check file permissions across a whole server. Luckily, fixing this on a cPanel box can be scripted. This gives us a quick and very easy script you can wget to any cPanel server. Simply run the ‘fixperms’ script, specifying the user (or all users), sit back and watch the errors just disappear. I use this script daily in my administrative work and it never fails! It is simply a good generic fix if you cannot find your permission problem, or if you have just switched your handler and need a quick way to change every user account on the server.
Credit does not go to me though. A good buddy of mine, Colin R., wrote this for ServInt. Thanks Colin for making lives easier!
***WARNING!!! The following scripts are intended for suPHP or FastCGI. If you are not running either of these two handlers, be aware of how the script works and the changes it makes. The code is posted at the end of this article; please take a moment to review it. For example, when running DSO, some files/folders may need to be owned by ‘nobody’ in order to function properly (such as in certain WordPress functions or PHP based file uploads). Running this fixperms will set everything to USER:USER. Under DSO, this is potentially not a problem for most sites, except a few core functions may not work. You can always change specific files later if any errors pop up.
Furthermore, it is highly recommended that you run a full backup of your server before running fixperms or any other script that makes changes to multiple files.
This ‘fixperms’ script is intended for cPanel servers only. It is dependent on cPanel’s internal scripts and file structure. If you’re on anything else (such as Plesk), it will simply fail to run. It won’t be able to do anything.
I know that criteria sounds very specific, but those two conditions cover a large number of the reseller/multi-user hosting servers out there. And that’s really the crowd that would benefit most from an automated script such as this.
That all being said, if you are running suPHP or FastCGI, press on; for this script will work flawlessly for you and potentially save you a TON of time & hassle.

Fixperms – for one single user

To use the fixperms script, simply log into your server as root, wget the file from our server, then run it. Type in the cPanel username and it will run only for that particular account.
It does not matter which directory you are in when you run fixperms. You can be in the user’s home directory, the server root, etc. The script will not affect anything outside of the particular user’s folder.

Fixperms – for all of the users

If you would like fix the permissions for every user on your cPanel server, simply use the ‘-all’ option:

Verbosity of Fixperms

By default, the script runs in a ‘quiet’ mode with minimal display. However, if you’re like me, you may want to see everything that is happening. You can turn on verbosity and have the script print to the screen everything that is being changed. I find this extremely useful when fixing large accounts that have many files. You can watch the changes as a sort of ‘progress bar’ of completion. The ‘-v’ option can be used per account or with all accounts.
For one single account:
For all accounts:

The code itself, what’s in it?

I understand that it can be a big security concern to simply ‘wget’ a file from a website you found, and then blindly run it on a production server. I understand your fear; I’m right there with you and would likewise be leery and very hesitant. However, I promise you that there is no malicious intent in this or anything you will ever get from my site. I have pasted the content of the file below for your examination.
 
So there you have it. An effective permissions fix for your cPanel account. When you run this, people will think you’re a hero! So, go forth and save your users from the evils of site errors!
Read More

Friday, January 31, 2014

// // Leave a Comment

How to install mod pagespeed on cpanel server

mod_pagespeed speeds up your site and reduces page load time. This open-source Apache HTTP server module automatically applies web performance best practices to pages, and associated assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow.
Features
Automatic website and asset optimization
Latest web optimization techniques
40+ configurable optimization filters
Free, open-source, and frequently updated
Deployed by individual sites, hosting providers, CDNs
mod_pagespeed
Pagespeed requires mod deflate module. You can verify this module whether installed on your server.
httpd -l | grep mod_deflate
or try to install mod deflate http://www.gnutoolbox.com/moddeflate-cpanel/
How to install mod pagespeed on cpanel server?
Solution : 1
Installing mod_pagespeed for cPanel Apache installation on CentOS is really quite easy. Connect your server SSH via root user.
cd /usr/local/src
mkdir mod_pagespeed
cd mod_pagespeed
Download the mod_pagespeed RPM to build. Please make sure which arch is your server. If you have a 32-bit install of CentOS you can find your appropriate package on Google’s Installing mod_pagespeed From Packages page.
yum install at  # if you do not already have ‘at’ installed
Mostly apache version 2.2 support for this mod pagespeed version (httpd >= 2.2 is needed by mod-pagespeed-stable-1.4.26.4-3396.x86_64)
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm

rpm2cpio mod-pagespeed-stable_current_x86_64.rpm | cpio -idmv
Copy mod pagespeed.so file to apache module directory
cp usr/lib64/httpd/modules/mod_pagespeed.so /usr/local/apache/modules/

chmod 755 /usr/local/apache/modules/mod_pagespeed.so

mkdir -p /var/mod_pagespeed/{cache,files}

chown nobody.nobody /var/mod_pagespeed/*
Open pagespeed configuration file.
vi /usr/local/apache/conf/pagespeed.conf
LoadModule pagespeed_module /usr/local/apache/modules/mod_pagespeed.so


    ModPagespeed on
ModPagespeedFetchWithGzip on
SetOutputFilter DEFLATE

    AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html

ModPagespeedFileCachePath            "/var/mod_pagespeed/cache/"
ModPagespeedGeneratedFilePrefix      "/var/mod_pagespeed/files/"

ModPagespeedRewriteLevel PassThrough

ModPagespeedFileCacheSizeKb          102400
ModPagespeedFileCacheCleanIntervalMs 3600000
ModPagespeedLRUCacheKbPerProcess     1024
ModPagespeedLRUCacheByteLimit        16384
ModPagespeedCssInlineMaxBytes        2048
ModPagespeedImageInlineMaxBytes      2048
ModPagespeedCssImageInlineMaxBytes   2048
ModPagespeedJsInlineMaxBytes         2048
ModPagespeedCssOutlineMinBytes       3000
ModPagespeedJsOutlineMinBytes        3000

ModPagespeedEnableFilters extend_cache,combine_css,move_css_to_head,rewrite_javascript,rewrite_images,add_head,rewrite_css,collapse_whitespace,remove_comments,remove_quotes,sprite_images,convert_meta_tags
ModPagespeedRespectVary on

    
          SetHandler mod_pagespeed_beacon
    

    
        Order allow,deny
        Allow from localhost
        Allow from 127.0.0.1
        SetHandler mod_pagespeed_statistics
    
Make a copy of your apache configuration httpd.conf file.
cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf_back
Edit and include the pagespeed configuration.
vi /usr/local/apache/conf/httpd.conf
Include “/usr/local/apache/conf/pagespeed.conf”
Save and restart apache service.
/etc/init.d/httpd restart
Thats finished… Test your page speed modules on website headers.
curl -I http://yourwebsite.com
HTTP/1.1 200 OK
Date: Wed, 17 Oct 2012 06:58:03 GMT
Server: Apache
X-Mod-Pagespeed: 1.0.22.7-2005
Cache-Control: max-age=0, no-cache
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
You have successfully installed mod_pagespeed module on your cPanel server.

Solution : 2

Mod_Pagespeed  install using easyapache


You can install it by using following steps
 wget http://prajith.in/scripts/mod_pagespeed-cust-opts.tar.gz
tar -C /var/cpanel/easy/apache/custom_opt_mods  -xzf mod_pagespeed-cust-opts.tar.gz
Thats it, now you can run and enable mod pagespeed
/scripts/easyapache

Solution : 3

Install Google’s mod_pagespeed.

Create a file called /etc/yum.repos.d/mod-pagespeed.repo
For 32-Bit
[mod-pagespeed]
name=mod-pagespeed
baseurl=http://dl.google.com/linux/mod-pagespeed/rpm/stable/i386
enabled=1
gpgcheck=0
For 64-Bit
[mod-pagespeed]
name=mod-pagespeed
baseurl=http://dl.google.com/linux/mod-pagespeed/rpm/stable/x86_64
enabled=1
gpgcheck=0
Install mod_pagespeed module through Yum
yum install at  # if you do not already have ‘at’ installed
yum --enablerepo=mod-pagespeed install mod-pagespeed
Above command creates following directories and files.
/etc/cron.daily/mod-pagespeed : mod_pagespeed cron script for checking and installing latest updates.
/etc/httpd/conf.d/pagespeed.conf : The main configuration file for Apache.
/usr/lib/httpd/modules/mod_pagespeed.so : mod_pagespeed module for Apache.
/var/www/mod_pagespeed/cache : File caching direcotry for web sites.
/var/www/mod_pagespeed/files : File generate prefix for web sites.
Please make sure mod_pagespeed.so file included in your httpd.conf.
To verify mod_pagespeed module, create php info page anywhere in your domain or localhost and check it.

You will see “X-Mod-Pagespeed” section in the HTTP header, like
X-Mod-Pagespeed
Turning the Module On and Off
If you don’t want to use mod_pagespeed completely, you can Turn Off by inserting the following line to pagespeed.conf file at the top.
ModPagespeed off
Turn On module
ModPagespeed on
Thats all..
Read More

Sunday, January 19, 2014

// // Leave a Comment

Social CSS Snippets and Ideas – Live Editable Examples

We all know the importance of Social networks, almost every website today has some sort of social media share or like button.
In this post, i will share some interesting social CSS code snippets that i have gathered or made myself. You can use them as a starting point to make your own. Some of them are animated using CSS3, others are just buttons or icons. They are easy to customize and you can play with them directly. I hope you will  find them useful and enjoy them as much as i did. let the ideas flow !

CSS Live Editable Examples

All of the examples below are hosted on codepen, feel free to customize them to suit your needs.

Social CSS Snippet – example 1

Social CSS Snippet – example 2

Social CSS Snippet – example 3

Social CSS Snippet – example 4

Social CSS Snippet – example 5

Social CSS Snippet – example 6


Social CSS Snippets and Ideas – Live Editable Examples


If you like those examples -share them !
Read More
// // Leave a Comment

Simple & Cool Live Examples of Image on hover Css effect

We will be playing with Image on hover effects using CSS  and One image only. I’ve created four simple examples that will work in all  browsers and another six cooler ones that will work only on webkit browsers.
They are all hosted on Codepen so you can directly play with the code and learn in the process. I  didn’t  even make any extra div to confuse you – all the images are in their main IMG tag. I’ll try to keep it short and sweet so you can absorb it even if you never touched CSS before.
In all the examples below we use this two simple things :
For CSS
img {here is the code of the initial state of the image}
and
img:hover { here is the code of the hover state of the image}
For HTML
 src="http://link to the image">
This extra div below ↓ is used  to center things on the Screen JUST IGNORE IT
style="text-align:center">
The first four live examples will work in all the modern browsers
box shadow browser support 
Lets get this party started…
Simple & Cool Live Examples of Image on hover Css effect

Shrink Image on hover

In this example we have  :hover  using height and width to change the size of the image, by adding  transition: all 1s ease;  to img we  make that change  from bigger- to smaller look smooth, changing the 1s  to 1,1s will make the transition last longer and setting it to 0,9s will make it last shorter.

Enlarge Image on hover

In this example we just change the  height and width to be bigger rather than smaller. Compare the css with the first example above and you will understand what i mean.

Rotate Image on hover

In this example we have transition again but this time in  :hover instead of the image size we have  transform: rotate(360deg); which does exactly what it says – it rotates the image 360 degrees.

Tilt Image on hover

In this example the  360 is changed to 15 degrees so it just tilts a little bit.
Simple & Cool Live Examples of Image on hover Css effect

Now for the webkit browsers the effects are much more interesting, yet also very simple to create

Blur Image on hover

Again in the img we use the transition but this time in the :hover we have added a filter -webkit-filter: blur(5px); changing the 5px to more or less will change the blur strength.

Decolorize Image on hover

This time the filter is  -webkit-filter: grayscale(100%); again setting the100% to less will change the effect

Darken Image on hover

Here we have  -webkit-filter: brightness(100%); in img again as initial state and than by adding  -webkit-filter: brightness(0%); to :hover we trigger the change. and of course again you can set up the filters % to your needs.

Hue-rotate Image on hover

In this cool example we have added the filter -webkit-filter: hue-rotate(333deg); 


Drop shadow Image on hover

For drop shadow we use -webkit-filter: drop-shadow(10px 7px 1px grey)

Opacity Image on hover

In this last example we have  -webkit-filter: opacity(0.3); as a filter.
And that concludes my Image on hover Css effect article.

I suggest that you bookmark this page and use it as a starting point anytime you wish to practice and experiment.

You can also check some other cool stuff that i have about CSS.
If you like this article please be kind to share it on your favorite social networks below.
Read More

Tuesday, October 22, 2013

// // Leave a Comment

How To (Automatically) Backup Your Website Into Dropbox or Copy.com

As owners of websites, one of the more important things you should do is to regularly backup the website. Most web hosting providers will enable daily or weekly backups, mainly for their disaster recovery purpose only. If you want to personally oversee a backup of your website, you can do it by yourself using the Backup function in hosting control panels like cPanel, Plesk and DirectAdmin. As a webmaster or domain owner, you are responsible for this task.
A good backup should have following criteria:
  • Backup your data as frequently as possible.
  • Give higher priority to critical data like database and web contents. Try to exclude temporary files.
  • Your backup should NOT be saved inside the same server.
  • Your backup should be retrievable and accessible anytime, anywhere.
  • You should get notified for every backup status which has been scheduled.
  • Your backup should be compressed, if disk space or bandwidth is your concern.
It is good if you can have your one FTP server to store backup remotely. But, what if the FTP server is down? How can we automate the backup task with limited access to the server? How can you be sure that the availability is always there? Cloud storage is your answer.
Cloud storage is becoming the best way to store files. Popular providers like Amazon S3, Dropbox, iCloud and Box.net are offering these facilities for free with some limitations. But, none of them are supporting FTP as the medium to transfer while almost all of webhosting providers only allow this transfer method.
Here’s where Backup Box/Movers.io comes in. Backup Box helps you securely transfer anything on an FTP server to your Dropbox account. Actually, Backup Box can integrate your FTP account with cloud storage providers like Amazon, GitHub, Box.net and Flickr as well. At this very moment, only Dropbox integration is supported while the others are still under development. It is free to use, with limited features like monthly backup schedule and immediate transfer schedule. In this post, I am focusing on preparing the backup data for weekly backup while running on cPanel server.
Backup Box
We can use this tool with various ways of implementation such as 1, directly copying the web directory using FTP and transferring to Dropbox (compressed or uncompressed) or 2, creating a compressed backup (cPanel backup) and using FTP to fetch the backup to Dropbox.
Before we proceed with the tutorial, ensure that you have following required information:
  • An FTP account which is mapped to your web directory. Get it from your hosting control panel.
  • A Dropbox account. You can register here for free
  • Or A Copy account. You can register here for free. (Recommended)
  • A Backup Box account. You can register here for free or movers account at http://movers.io/.

Web Directory > FTP > Dropbox

Since the database is also important, we need to prepare the database backup and put it into our web directory. If you are running on Linux hosting, you can use a task scheduler called a cron job with some help from mysqldump. In cPanel, it is located under cPanel > Advanced > Cron jobs.
Let’s use the following data as an example:
  1. Web directory path: /home/username/public_html  
  2. cPanel username: mycpanel  
  3. cPanel password: mypass123$  
Create a new weekly cron job and use the following command:
  1. mysqldump --opt -Q -u mycpanel -p'mypass123$' --all-databases > /home/username/public_html/databases.sql  

Here’s An Example:

This will create an SQL backup file which includes all the databases under your cPanel account. Login into Backup Box. On the left panel, login into the FTP account by clicking the ‘gear’ icon. On the right panel, login into your Dropbox account.
You can choose Transfer public_html as a folder in the Transfer Options. This will transfer the whole public_html folder including all files into your Dropbox account. You can now start the immediate transfer by clicking Review. This will transfer the public_html folder to Dropbox. Once done, you can create Monthly schedule to automate this backup task monthly. Just click Monthly > select Date and Time > Finalize and Run. Note: If you want to use weekly or daily backup, you need to upgrade your subscription as stated in the website. Do not forget to change the cron job setting based on when you want the backup schedule to happen

CPanel Backup > FTP > Dropbox

The good thing about cPanel is you can generate your own backup automatically using cPanel API. In this case, we will use PHP script to run on schedule to generate backup. Since the backup location needs to be exclusively for Backup Box, we will need to create an FTP account which is mapped to a new backup folder.
Go to cPanel > FTP and create an FTP account as the screenshot below. Do not create the FTP directory under public_html because it is accessible publicly via web browser (unless you protect the directory with a password):
We need to use PHP with cPanel API to trigger the backup process. Download this file (cpanel-php-backup.zip) and unzip it. You should see 2 files, cpanel-backup.php and xmlapi.php.inc. Change all required information inside cpanel-backup.php as below:
  1. // Credentials for cPanel account  
  2. $source_server_ip = ""; // Server IP or domain name eg: 212.122.3.77 or cpanel.domain.tld  
  3. $cpanel_account = ""; // cPanel username  
  4. $cpanel_password = ""; // cPanel password  
  5.   
  6. // Credentials for FTP to Backup Box  
  7. $ftpacct = ""; // FTP account  
  8. $ftppass = ""; // FTP password  
  9. $email_notify = ''; // Email address for backup notification  
Save the file and upload both files into your public_html directory using FTP. You can start to generate a backup by accessing the PHP file directly via browser, which is usuallyhttp://www.yourwebsite.com/cpanel-backup.php .
In order to automate cPanel backup creation, we need to setup a weekly cron job into cPanel and use following command:
  1. php -q /home/username/public_html/cpanel-backup.php  
Here is a sample:
Login into Backup Box. On the left panel, login into the FTP account (use the backup box FTP account) and in the right panel, login into your Dropbox account:
Since we store backup files into a dedicated folder, we can only transfer the contents of it. Select Transfer only the contents of / in the Transfer Options as the transfer method.
You can now start the immediate transfer by clicking Review. This will transfer the public_html folder to Dropbox. Once done, you can create Monthly schedule to automate this backup task monthly. Just click Monthly > select Date and Time > Finalize and Run.
Note: If you want to use weekly or daily backup, you need to upgrade your subscription as stated in the website. If you do, do not forget to change the cron job setting according to your backup schedule. Another thing, the PHP script will delete all previous cPanel backup before it generate new backups. This to make sure your backup will not eat up much disk space.
Read More