Tag Archives: apache

Linux: My Bash Script Collection / Server Configurations

1. Restart apache daily. Put in /etc/cron.daily directory.

#/usr/bin/systemctl restart httpd
#/usr/bin/systemctl start httpd

for (( ; ; ))
echo "checking"
sleep 120
if [ `ps auxwwww|grep httpd|grep -v grep|wc -l` -gt 0 ]
echo Apache is running.
echo Apache is not running.
/usr/bin/systemctl start httpd


2. Set Limit File Size Per User Using Limits.conf

#example : limit file size ~100MB per file per user
#create file in /etc/security/limits.d/99-hafez.conf
#enter details below:
--------------- BOF ------------------
# hard fsize
hafez hard fsize 100000
--------------- EOF -----------------
#save the file
#-- tested on centos 6.9


Linux: Apache Common Htaccess Usage (2.2 & 2.4)

  1. Maintenance mode except subnet network.

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI} !^/offline\.html$
    RewriteCond %{REMOTE_ADDR} !^10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$
    RewriteRule ^(.*)$ http://yourdomain.com/offline.html [R=307,L]

    offline.html (store your offline messages)
    !^10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$   (excepet subnet
    Tested on apache 2.4  and 2.2 on CentOS 7 and CentOS 6

Linux : read write permission for group and apache

Situation : I need a group of developers  and apache  to have reads/writes permission on a folder in /var/www/html/foldername


Solution :

  • create users and a group

    #useradd develone
    #useradd develtwo
    #groupadd developergroup
  • Append “apache” and 2 users to “developergroup”

    #usermod -a -G developergroup apache
    #usermod -a -G developergroup develone
    #usermod -a -G developergroup develtwo
  • Set ownership and gid to “foldername”

    #chown apache:developergroup foldername
    #chmod 775 foldername
    #chmod g+s foldername


done. tested on CentOS 6.5 machine with ~50 users/developers