Increment mySQL field value

Here is a single query that will allow you to increment a field value in an existing database record or insert a new record if the row does not exist.  The table you use must have a unique ID defined.

INSERT INTO web_count (name, counter) VALUES (‘test.htm’, 1) ON duplicate KEY UPDATE counter = counter + 1

Restricting mySQL access to specific IP addresses. (Linux)

If you manage a web or database server, and do not have an active firewall, you may want to use the following method to restrict access to your mySQL service from the Internet. These instructions are for Linux (tested under Red Hat and CentOS), and require you to be running the iptables service. Check if you have iptables running by executing the following command as root:

service iptables status

Start iptables if the service is not running.  You should also set iptables to load on boot as well.  This can be achieved using the following command:

chkconfig -level 345 iptables on

Now that you know iptables is running, you can begin adding the new rules for allowing only specific ip addresses to connect to your mySQL database.
Note: If you do not want any external connections to your mySQL database, you can also edit the my.conf file located by default under /etc/my.cnf.  Simply add bind_address = under [mysqld], and restart the mysql service.  mySQL will now deny all external connections.

For this example, I’m going to allow access from 3 servers, and deny every other address.  Execute the following commands in order, and replace IP address 1, 2, and 3 with the addresses of your servers.

iptables -A INPUT -p tcp -s IPaddress1/32 --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp -s IPaddress2/32 --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp -s IPaddress3/32 --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j DROP

When configuring iptables, order is important.  The effects of each command are immediate, but you must save your iptables settings or you’ll lose them on your next restart.  Do this by issuing the following command:

service iptables save

You iptable settings are now saved, and will be used next time iptables is restarted.  By default in Red Hat, and centOS, the settings are stored here: /etc/sysconfig/iptables

Custom 404 error page for a subdirectory under WordPress

So you want your WordPress site to allow you to have a different 404 error page for a subdirectory.  These instructions are for WordPress sites running on Apache.

The issue with adding custom 404 error pages to your WordPress site is due to WordPress using Apache’s rewrite on your entire site.  In order to prevent this from happening on your subdirectory, you need to add a .htaccess file with the following code:

<IfModule mod_rewrite.c>
RewriteEngine Off

ErrorDocument 404 /subdirectory/404.html

This code prevents URL rewrites on your subdirectory, and specifies your custom 404 error page.  The 404 error page should link to the custom file you want to display to your visitors.


How to set up a Secure Remote Connection to a Microsoft SQL Server

Step 1: Download and install Stunnel for Windows

Step 2: Configuration
Stunnel needs to be configured to create a connection from the port which will allow remote connections (ie: 14333) to the Microsoft SQL Server port (1433). All connections to port 14333 on the server will be encrypted. On your server, set port 14333 to accept remote TCP connections, and make sure to block all remote connections to port 1433 from the Internet. Configuration may vary depending on your network structure, but only the secure port should be accessible from outside your network. You can even restrict access to the secure port further by only accepting connections from specific IP addresses.

Now, lets modify the Stunnel configuration file.  You can access the configuration file from the start menu in the stunnel program folder, there is an icon that says “Edit stunnel.conf”.

Paste the following into the stunnel configuration:

cert = stunnel.pem
debug = 7
output = stunnel.log

accept =
connect =

Replace EXTERNAL_IP with the IP address of your server. This configuration tells stunnel to use stunnel.pem for the security certificate – by default located under c:\program files\stunnel.pem. All debug output is logged to the stunnel.log file.
Make sure your MSSQL server accepts connections on and port 1433, otherwise you may need to change this information, or modify your SQL configuration.