Some handy scripts and one liners for web development and management.

As a web developer I personally prefer a LAMP setup on CentOS. This is where I feel best operating websites and web applications, but I’m flexible to the needs of the situation. I certainly enjoy Node.js, and I do work a lot with applications developed in JAVA running on Tomcat and on occasion have to deal with IIS and ASP.  In this post I’m going to just cover a couple of handy scripts and one-liners I’ve collected over the years to help me get through or reduce the mundane.

FollowSymLinks in .htaccess on CentOS/Apache 2.4.x

This is a super annoying issue, specifically when you have a CMS installed like Drupal, Joomla, or WordPress that insist on managing .htaccess for you whenever you update or come stock with FollowSymLinks. Unfortunately, if you are running virtualhosts and apache as the host user and not the system user, FollowSymLinks will throw errors on your server and cause issues. Instead you need SymLinksIfOwnerMatch. Unfortunately if your .htaccess continually gets overwritten by something where the default is to use the former, then you have to replace it all the time… so I got this one liner with a little help from Stack Overflow.

find ./ -type f -readable -writable -name \.htaccess -exec sed -i "s/FollowSymLinks/SymLinksIfOwnerMatch/g" {} \;

Update Drupal 7 from Source Code Repository

I have managed several Drupal 7 websites and eventually found that I liked to use Git to manage the site themes and modules, while using Drush to manage Core. This is really a nice effective way to manage a Drupal site and track changes as well, only the shell commands are a bit tedious, so I made this simple script to set maintenance mode, pull from the repo, run updates, and turn the site back on.

cho "*** Updating Drupal ***"
cd public_html

echo "--> Putting site in maintenance mode."
drush vset maintenance_mode 1

echo "--> Updating the code from git repo."
git pull

echo "--> Running pending Drupal updates."
drush updatedb -y

echo "--> Clearing the Drupal cache."
drush cc all

echo "--> Bringing site back online."
drush vset maintenance_mode 0

Others

I’ve got more, I just have to dig them up from my archives, then I’ll come back and update this post when I do.

 

Leave a Reply

Your email address will not be published. Required fields are marked *