Sometimes for various reasons your web server may become hung. You may for example run out of resources on the server and there is not enough memory for various processes or maybe a script is running for too long.

Whatever the reason this little script can stand guard and restart the services in your absence. Replace <keyword> with a word that appears on your website if the site is running normally.

curl localhost|grep <keyword>

if [ $? -ne 0 ] ; then
        /etc/init.d/mysqld restart
        /etc/init.d/httpd restart

You can make it run every minute by adding the following line to your crontab with crontab -e

* * * * * /path/

You can check that your script is running periodically using the following command.

tail -f /var/log/cron


The following script provides a handy way to perform a periodic backup of your databases to a S3 bucket in the form of a mysql dump encrypted in a password protected zip.


  • Install the aws cli via pip:
  • Create an s3 bucket
  • Assign a role with access to the s3 bucket to your ec2 instance
fileName="dump$(date +%y-%m-%d-%H-%M-%S)"

cd /db/bkp

mysqldump -u backup --all-databases > $fileName.sql

zip $ $fileName.sql -me9D -P <YOUR_SECRET_PASSWORD>

aws s3 cp $ s3://<YOUR_BUCKET_NAME>/$

So you’re looking to host a WordPress site in AWS using Elastic Beanstalk.

The following lines in your wp-config.php can get you going.

The line below enforces the use of a secure connection for the authentication API. It is off until you define an environment variable in your beanstalk configuration,  called FORCE_SSL_ADMIN with the value ‘true’

define('FORCE_SSL_ADMIN', getenv('FORCE_SSL_ADMIN')==='true');

If you enable secure connections on your Elastic Beanstalk load balancer and find that you keep getting redirected the line below indicates allows WP to detect that HTTPS is being used.

if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)

These settings are defined as environment variables so you  don’t have to hardcode them in wp-config.php.

define('DB_NAME', getenv('RDS_DB_NAME'));
define('DB_USER', getenv('RDS_USERNAME'));
define('DB_HOST', getenv('RDS_HOST'));