Installing phpmyadmin in hhvm

when installing phpmyadmin under hhvm and nginx especially, you might get an error like so:

“Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly”

this is due to hhvm settings, got /etc/hhvm/php.ini and comment out all the php options like so:

; php options
;session.save_handler = files
;session.save_path = /var/lib/php5
;session.gc_maxlifetime = 1440

restart hhvm and it should work.

CPanel exim unrouteable address

if exim is showing up errors like “unrouteable address”, it means that exim is trying to send mail locally. If your local dns is borked, you will get this error. The fix is to fix your local mx entry. If you have configured an external dns server, then you should go to

DNS functions -> edit dns zone -> email routing for -> check “remote mail exchanger”. That way, we are telling exim to use remote DNS server.

In the backend, it is the process of moving the domain entry from /etc/localdomain to /etc/remotedomain. But don’t edit the file locally because these files are versioned controlled via whm. Change them from Whm as per described above.

Cpanel unblock IP

sometimes your IP gets blocked if you have done something funny on the server. Best way is to ssh into the server

csf -r (Restart CSF)
csf -d (quick deny an ip: csf -d xxx.xxx.xxx.xxx)
csf -a (quick allow / whitelist an ip: csf -a xxx.xxx.xxx.xxx)
csf -dr (unblock an ip and remove from the deny list: csf -dr xxx.xxx.xxx.xxx)

How to harden and optimise whm/cpanel

Cpanel website provides some good tips to harden your server

After login to whm, go to configserver security & firewall and add your IP to the “allow ip” list.

https://documentation.cpanel.net/display/CKB/How+to+Prevent+Email+Abuse

WHM > Server Configuration > Tweak Settings, Mail -> Set Initial default/catch-all forwarder destination to false

https://documentation.cpanel.net/display/CKB/Tips+to+Make+Your+Server+More+Secure

go to security center -> security advisor and follows the advise from there.
-> Allow modsecurity and rebuilt apache.
-> Update password strength to something greater than 70
-> disable ssh password authentication
-> run security advisor and update as necessary

go to service configuration -> service manager and disables unused services like mailman.

if php is showing ini_set error, go to home -> service configuration -> php configuration editor and remove ini_set under safe_mode. might as well allow proc_open for composer. restart apache

If cannot access files after updating or transferring cpanel accts, try changing permission for all files. suphp means owner and group user must be acct user and all dir must be 755 and file 644.

find /home/user/public_html -type d -exec chmod 755 {} \;
find /home/user/public_html -type f -exec chmod 644 {} \;

To optimise php, use apc cache with fcgi

http://virtualhosts.dk/centos-6-with-cpanel-and-whm-using-litespeed-webserver-and-php-apc/step-6-install-php-apc-alternative-php-cache

or better still go for hhvm (but cpanel doesnt yet support this)

https://codeable.io/community/speed-up-wp-admin-redis-hhvm/

Deploying to wordpress from git

If you are using git and are writing plugins for wordpress, its a hassle to switch between the 2 SCM. Why not commit once and deploy to 2 places? that is what many people are trying to do.

this script does exactly that: https://github.com/benbalter/Github-to-WordPress-Plugin-Directory-Deployment-Script

Create a plugin first. I suggest using all lowercase, eg blarblar-blarblar-blarblar. create a repo for it in github. git clone that plugin in your plugins folder. Make all changes.

Create the version number in the readme and plugin master file.

copy the deploy.sh into the wp-content/plugins folder, one level above your plugin. then run:

 ./deploy.sh

you will be prompted to enter the name of the plugin and everything should work.

cpanel php exec – memory or cannot fork error

If you are using php, and try to run command line scripts containing php command, you will get a loop that fails with a warning “cannot fork” or memory error.

This is because you are most likely using suphp in cpanel. While suphp is popular, it fails misery when trying to execute php command line. You might have something like this:

exec(‘composer update’,$output);

to see the errors:

exec(‘composer update 2>&1’, $output);
print_r($ouput);

You could have use the php system() function instead. The result is the same. You will see lots of loops and php die with cannot fork error.

So what is the error? Google doesn’t reveal anything. The reason is that php by default is using /usr/bin/php which suphp works on top of. You need to use a php free from suphp and use the full path. try this

exec(‘/usr/local/bin/php /usr/local/bin/composer update 2>&1’, $ouput);
print_r($output);

it will work. viola!

bitbucket post hook sample json

Like github, bitbucket sends a useful json post data to a url specified by you if you add a post hook in a the bitbucket repo. The post json can be useful if you want to determine the file changes of the branch that has the change. example json is

Array
(
[payload] => {"repository": {"website": "", "fork": false, "name": "repo_name", "scm": "git", "owner": "your_group", "absolute_url": "/your_group/your_repo/", "slug": "your_repo", "is_private": true}, "truncated": false, "commits": [{"node": "727a3b3c6b37", "files": [{"type": "modified", "file": "code/yourfile.php"}, {"type": "modified", "file": "code/yourfile.php"}], "raw_author": "your name <bernard@youremail>", "utctimestamp": "2014-11-26 04:13:10+00:00", "author": "yourname", "timestamp": "2014-11-26 05:13:10", "raw_node": "727a3b3c6b37f0b9c03fde57943f3f463a12f9e5", "parents": ["2405db2a7a94"], "branch": "develop", "message": "update deploy scripts\n", "revision": null, "size": -1}], "canon_url": "https://bitbucket.org", "user": "yourname"}
)

cpanel changing document root of primary domain

there might be times when you want to restructure the default public_html directory structure. The document root might reside somewhere deep in for security reasons.

go to /var/cpanel/userdata/USERNAME/DOMAIN.COM

edit the documentroot line

then

/scripts/rebuildhttpdconf
service httpd restart

Allow different order status in woocommerce

sometimes it is necessary to add new order type, for example some of the items i sell requires installer confirmation. Thanks woocommerce, the hooks are easy to use. In your functions file:

// New order status - Waiting for Installer Response
function register_waiting_installer_order_status() {
  register_post_status( 'wc-waiting-installer', array(
    'label' => _x( 'Waiting for installer Response', 'Order status', 'woocommerce' ),
    'public' => false,
    'exclude_from_search' => false,
    'show_in_admin_all_list' => true,
    'show_in_admin_status_list' => true,
    'label_count' => _n_noop( 'Waiting for installer response <span class="count">(%s)</span>', 'Pre Order <span class="count">(%s)</span>', 'textdomain' )
  ) );
}
  
add_action( 'init', 'register_waiting_installer_order_status' );

function waiting_for_installer_response_order_status($o) {
	$o['wc-waiting-installer'] = _x( 'Waiting for installer response', 'Order status', 'woocommerce' );
	return $o;
}

add_filter( 'wc_order_statuses', 'waiting_for_installer_response_order_status' );