Distraction Free Writing mode Themes is a WordPress plugin I’ve been working for the past couple of weeks – it provides themes/color schemes for for Distraction Free Writing mode in WordPress. You can use one of the built-in themes or write your own with CSS.

As someone who uses a dark color scheme for programming I didn’t like the default color scheme in WordPress (black text on white background).

The plugin has six themes in total. The default theme is based on Monokai:

The form has a unique hidden value (jschl_vc) and an empty hidden value (jschl_answer).

The Javascript snippet calculates a mathematical challenge – in our case 9+50*1, which it inserts into jschl_answer and submits the form.

The jschl_vc form field uniquely identifies the challenge to CloudFlare, so that the backend knows what the answer should be. If jschl_answer is interpreted as being the correct result, a cookie called cf_clearance is created with a unique id that identifies the user as having verified the challenge.

In summary

The Cloudflare page checks whether the user has JavaScript enabled.

This looks like a really effective technique against primitive DDOS floods, which issue simple GET requests to a server.

This is a tutorial that covers the entire process of setting up CentOS 6 and installing/configuring Apache, PHP, MySQL, SELinux and iptables, as well as securing the server. This tutorial will give you a base setup for running static as well as dynamic web sites using PHP and MySQL. This tutorial suits VPS or other low-memory configuration as well as dedicated servers.

Prequisites

This tutorial assumes basic knowledge of shell/console usage and knowledge of one text editor.

You need a freshly installed CentOS 6 installation to proceed (Minimal installation is recommended) Once you’re in a root shell, start reading below!

EPEL is an extra software repository with a lot of useful software that is not in the base repo. We will need it later, so let’s add it to our CentOS install! Go to this page to get the most up to date EPEL version. Copy the link from the text epel-release-6-x.noarch and use it in the command below:

After starting mysqld, you will receive a prompt to change your MySQL root user password. The dialogue will read…
…
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
…

Two commands will be presented to you, run them both. You will need to use your server name in the second command, as the help prompt instructs you. The base commands are:

Allow your new user to sudo
sudo allows a user to temporarily take on the role as root.

vim /etc/sudoers

Note: If you are getting a blank text file (not found) in this step, install sudo with
yum install sudo
Find the line:

root ALL=(ALL) ALL

Under this line, add a new one to allow your newly created user to use sudo:

username ALL=(ALL) ALL

Save the file (it’s read-only, so you need to force the write using :wq! in Vim)

Step 13 – Configure Apache

Let’s make some sane modifications to the Apache configuration to improve default behaviour and lower the memory consumption. I am configuring this for a 512MB server, if you have more memory you may retain these values at their original settings or adjust them differently.

vim /etc/httpd/conf/httpd.conf

Allow for .htaccess overrides

Search for the AllowOverride directive in the configuration file.

Change the instances of:

AllowOverride None

to

AllowOverride All

You will also need to uncomment the general AllowOverride declaration by removing the hashtag (#) in front of it.

Before (commented out):

# AllowOverride All

After (Correct version):

AllowOverride All

Change the amount of workers spawned

Find the IfModule prefork.c directive and change according to the example below.

Setting up cron jobs is useful for scheduling tasks. For this we’re going to install CRON and Crontab.

yum install crontabs
chkconfig crond on

To see the local user crontab issue:

crontab -e

Here is a great resource for learning how to manipulate the crontab file.

Warning
Remember that the scheduled commands are run as the user whos crontab they are in. For cron jobs that require elevated privileges, using the root crontab or changing file permissions may be necessary.

Setting up a cron job to backup all mysql databases

First start editing the crontab:

crontab -e

Now add a new line, which will run our command:

0 0 * * * mysqldump --all-databases > /root/sqldump.sql

This simple command will back up all databases to the file /root/sqldump.sql at midnight every day.
Note: This requires you to set a [mysqldump] user, as advised in Step 15.

You’re done!

Congratulations on setting up CentOS 6 with LAMP. The section below contains useful commands and other tweaks you can perform.

Test disk speed

Disk speed indicative of performance, different tests test different things, different on virtual environments (such as OpenVZ and KVM) and dedi, some tests might be better for some of them.

dd if=/dev/zero of=test bs=64k count=16k conv=fdatasync

How to judge your result (note that this is only accurate for the exact test above)

0-25 MB/s -> Garbage

25-70 MB/s -> Acceptable

70-120 MB/s -> Good

>120 MB/s -> Excellent

Miscellaneous: Quick reference of useful commands

Check disk usage

df -h

Disable or enable iptables

chkconfig iptables on/off

Dump all your MySQL databases to a file (suitable for backup, in crontab or similar)

In Step 15 we saved our MySQL username and password in the MySQL configuration file /etc/my.cnf

Now we can use mysqldump without a password. To dump all databases into a file, issue:

mysqldump --all-databases > /root/sqldump.sql

Listing services that automatically run at startup, and their runlevels

chkconfig --list

Miscellaneous: Setting appropriate file permissions for PHP sites

We’d like for Apache to have as little access to the files it serves as possible. This limits the effects PHP and Apache exploits.

To accomplish this, let’s run an example with a fictional site residing in the folder:

/var/www/html/yoursite

To secure this site we are going to put up the following restrictions:

Files can only be read

Directories can only be read and executed (this is required for PHP to work)