cPanel API curl and email filtering

Posted on: 2015-05-24

I pay for cheap shared hosting every month because it gives me a lot of flexibility. If I get tired of maintaining VPSes or hit limitations with various free PaaS providers, I use the shared cpanel host because its stable and I don't have to mess with things to get what I want working. One thing I've been using my shared hosting for recently is email for my domains. I've come to prefer this over the pain of being a mail admin and the threat of a lack of privacy from a bigger vendor like Google or Yahoo.

Thanks to SPAM I wanted an easy way to create e-mail aliases that I could turn on and off. IE: create which forwards to Should they send me more than order confirmations, I either setup spam fitering on the alias, or kill it altogether so all future emails from them would get rejected.

To get the setup I wanted, I needed to figure out how to call the cPanel API. cPanel documents it pretty well, but they tend to show PHP and Perl examples and there are 5 or 6 different APIs to choose from, so it is still more complicated than it should be at first. I was shocked that Googling for cPanel API + curl turned up basically no results. To fix that, here is what you need to get started...

Figure out what your API call will look like by reading the API Docs

Encode your login credentials by doing a

echo -n user:pass | base64

Call your API URL, replacing the Authorization Basic with the results from the previous step

curl -H "Authorization: Basic dXNlcjpwYXNz" -L -k -v ""

git Backed Static Content Web Hosting PaaS

Posted on: 2015-05-24

I've been playing with OpenShift and another PaaS vendor lately. The fact that you can do a git push and everything else is handled automatically for you is really neat. I wanted to learn more about how this all worked, so I decided to try to create my own PaaS-like setup. Since this was to be a learning experience and not a for profit product, I decided to target a simple use case of ~username static content hosting. I also figured this would be a good starting place for extension by others and I could use it to replace my current hosting service one day.

The first thing I learned with this project is that you need a git post-receive hook to checkout the users repo and then build and deploy the results. So for me that was a simple git checkout and rm -Rf ~/public_html followed finally by a cp -Rf repo/public_html ~/public_html.

Next up, since I wanted to share this project and allow others to offer the same service and potentially build a network a la I decided the server build process and other orchestration parts needed to be uniform and easy to use. Since where I work is a puppet shop, I decided to learn and use some Ansible for these pieces.

Now that the git hook, server build and backend account creation stuff was done, all I needed was a web frontend where people could sign-up for accounts. A buddy of mine had been talking about sinatra and I've been meaning to learn some more Ruby, so I created the front end using those technologies.

All and all this was a fun project and I'm very pleased with the results. If you happen to need a PaaS static content host or want a PaaS like system to extend for you own needs be sure to check out my work at

LAMP on CentOS 7

Posted on: 2014-11-02

LAMP on CentOS 7

Linux + Apache + MySQL/maria + PHP is one of the most popular and powerful web server setups in the world. Lots of large websites use that combination and several thousands of free pre-built applications can be dropped onto a LAMP server and put to work in minutes. Because of all of these things, LAMP administration is a truly invaluable skill for sysadmins to have.

Below we will be setting up an non-production-ready LAMP stack on a CentOS 7 box. We will be using Wordpress as our proof of concept test app.

Server Setup:

Install the software:

yum install mariadb mariadb-server php httpd wget php-mysql

Enable services:

systemctl enable mariadb
systemctl enable httpd
systemctl start mariadb
systemctl start httpd

Open the firewall:

firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

Set the mariadb root password:


Enter current password for root (enter for none): <enter>
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

Test mariadb:

systemctl restart mariadb
 mysql -u root -p -e 'select * from user' mysql

Test apache and PHP

systemctl restart httpd
echo '<?php phpinfo(); ?>' >> /var/www/html/test.php
Go to http://SERVERIP/test.php in your browser

Setup wordpress:


cd /var/www/html/
tar -xzvf latest.tar.gz

Database work..

mysql -u root -p
GRANT ALL PRIVILEGES ON wp.* TO "wpuser"@"localhost" IDENTIFIED BY "password";


Go to http://SERVERIP/wordpress/ in your browser
...start clicking through the screens...
Database name: wp
Database username: wpuser
Database password: password
Database host: localhost
Table prefix: wp_

If it can't creat the config file copy the block of text then.

cd /var/www/html/wordpress
vi wp-config.php
Run the install

Fill in your personal info for site title, username, etc and then click Install WordPress.

Testing LAMP + Wordpress:

  • http://SERVERIP/wordpress/
  • Login #use the account you created earlier
  • Post a blog entry


There you go. There is a good start at a LAMP server. Before you take this to production you will likely want to tweak mariadb and php settings. POST sizes, upload sizes, memory allocation, processing/post timeouts, etc. You'll also want to lockdown Apache and read up on Wordpress best practices and make sure all your directories and files have the proper permissions, etc. You'll also need some sort of caching if your site gets even marginally popular.

<<Newer Older>>