MyTrueHost launched Web Hosting for Indian clients just in Rs 60/Month with various payment options(netbanking, debit card, credit card,cash card or paypal).
Please Visit at https://www.mytruehost.in

Apache Error: Unable to open logs

Sometimes apache will fail to start. It will show the following error message in apache error logs:

Unable to open logs

This is because of the low number of file descriptors. Check the current limit of file descriptors in the file /proc/sys/fs/file-max:

$ cat /proc/sys/fs/file-max

1024

If fs.file-max is quite small (several thousands or so), it should be changed to a higher value.

$ echo “65535” > /proc/sys/fs/file-max

If you want this new value to survive across reboots you can add it to /etc/sysctl.conf.

# Maximum number of open files permited

fs.file-max = 65535

To load new values from the sysctl.conf file:

$ sysctl -p /etc/sysctl.conf

Add `ulimit -n 65536` command to /etc/rc.d/init.d/httpd and /usr/sbin/apachectl apache startup scripts before other commands.

Fsck.ext3: Unable to resolve UUID

If you are getting the FSCK error fsck.ext3: Unable to resolve ‘UUID=a3e1dbca-60ee-4aa4-bf79-60cf6d96075d’ on system booting, then you can try following steps to resolve that :

1. Use following command to get the UUID of current partitions.

blkid

2. Open the /etc/fstab file and check the UUID in the fstab and the result of blkid are same.

unni[~]# grep -A 1 /dev/sda7 /etc/fstab
# /dev/sda7
UUID=a3e1dbca-60ee-4aa4-bf79-60cf6d96075d /media/olinux ext3 relatime 0 2

unni[~]# blkid | grep /dev/sda7
/dev/sda7: UUID=”9758e919-a56d-44cc-8c7e-a6ab9ff03151″ SEC_TYPE=”ext2″ TYPE=”ext3″ LABEL=”Olinux”

3. Edit the /etc/fstab and change the UUID to that got from the blkid 

That will solve the issue.

Apache failed to start with the “No space left on device” error.

If you receive the following error while restarting Apache in the server, you need to do the following steps.

Error:-
[error] (28)No space left on device: Cannot create SSLMutex Configuration Failed

These errors means that there is no available IPC (inter-process communication)  resources in the system, such as semaphores or shared memory segments. You need to check IPC resources which are  used in the server using ‘ipcs’ command:

$ ipcs -a

—— Semaphore Arrays ——–
key        semid      owner      perms      nsems
0x00000000 201293824  apache    600        1

You will be able to see a lot of semaphores under Apache . You need to kill those processes using the following script and restart apache.

$ ipcs -s | grep apache | perl -e ‘while (<STDIN>) {@a=split(/\s+/); print `ipcrm sem $a[1]`}’
$ service httpd restart

Disable mod_security2 for a single domain

Mod_security is an open source Apache module. This can be considered as firewall for web applications. It secures the system from the attackers. We use mod_security1 for Apache1.x and Apache 2.x uses mod_security2. In case of mod_security1, we can disable it for a domain using the .htaccess file.

If you want to disable mod_sec for one domain then add the following Line in .htaccess

—————–

SecFilterEngine Off

——————

However, we can’t block mod_security2 via .htaccess on domain basis.

The following steps can be used to disable mod_security2 rule for one domain in cPanel servers.

1. Make the directory “/usr/local/apache/conf/userdata/std/2/username/domain.com”

2. Create a file “vhost.conf” in the above location

3. Add the following lines :

———-

<IfModule mod_security2.c>

SecRuleEngine Off

</IfModule>

———-

To disable mod_secuirty for a particular location :

———

<LocationMatch specify_the_path_here>

<IfModule mod_security2.c>

SecRuleEngine Off

</IfModule>

</LocationMatch>

———

To disable a particular mod_secuirty rule :

———

<IfModule mod_security2.c>

SecRuleRemoveById give_ruleID_here

</IfModule>

———

Please make sure run the following script after making the changes.

———

/scripts/ensure_vhost_includes –user=username

———

This script will uncomment the following line in apache configuration. It will customise the virtual host to use the particular include file and will restart apache.

———–

Include “/usr/local/apache/conf/userdata/std/2/username/domain.com/*.conf”

———–

Bash Script to Check Apache Memory Usage

We might have come across many situation where we need to find the memory usage by apache and which script or from which directory this process is being called. You can use the script given below to find that and log it whenever the load goes beyond a threshold value. Which also help us to refer later if we want to troubleshoot load issues on the server.

To setup the script follow the simple steps mentioned below.

1. Create a directory /var/log/process_memcheck/

2. Create a file inside /root. I gave the name process_memcheck.sh.

3. Grant executable permission to this script.

4. Open the file and paste the following contents in it.

#!/bin/bashVAL=10 #### I gave 10 as threshold value. You can use your own
LOAD=`cat /proc/loadavg | awk -F’ ‘ ‘{print int($1)}’`
HOST=`hostname`
IP=`hostname -i`

if [ “$LOAD” -ge “$VAL” ]
then
{
for i in $(netstat -plan | grep :80 | grep ESTABLISH | awk ‘{print $7}’ | cut -d/ -f1)
do
dir=$(lsof -p $i | grep cwd 2> /dev/null| awk ‘{print $9}’);
pid=$(lsof -p $i | grep cwd 2> /dev/null| awk ‘{print $2}’);
memuse=$(pmap -x $pid 2>/dev/null | grep total | sed ‘s/-//g’);
echo “Mem Use = $memuse and home dir = $dir”;
done
} > /var/log/process_memcheck/process_memcheck-$(date +%d-%m-%y:%H:%M).log
fi

5. Save and quit.

6. Open the file /var/spool/cron/root and append the following line in it.

*/5 * * * * /root/process_memcheck.sh 

7. Save and quit. Restart crond.

/etc/init.d/crond restart

Thats all. You will get a log at /var/log/process_memcheck/, which show the memory usage by each apache and the directory from which it is being called.

Run Apache and lighthttpd on port 80

Lighthttpd is the webserver which will help to increase the speed with a small memory consumption.
Now, I assume that you have already installed both apache and lighthttpd in the server.

The main thing should be noted here is we need to have 2 IP in the server so that only we can run both apache and lighthttpd in the same port.

Go to apache configuration and locate Listen directive.
Here, Add “Listen” directive to all IP addresses of the server, except the IP for lighthttpd.

Listen IP_ADDRESS1:80

Now, restart apache and then lighthttpd.
You can try to access IP in browser and make sure both are listening on port 80.

WHM failed to receive Apache Status

If the WHM is not showing the Apache status, make sure that the whm-server-status is added in the configuration.

$ vi /usr/local/apache/conf/httpd.conf

Then add the following entries in the Apache configuration file and then save.

<Location /whm-server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
ExtendedStatus On

Restart the apache service.

$ /scripts/restartsrv_httpd

Apache error: Invalid command ‘BytesLog’

If you receive the following error,

Invalid command ‘BytesLog’, perhaps mis-spelled or defined by a module not included in the server configuration

while restarting apache in cPanel servers , do the following steps.

 

$ cd /usr/local/cpanel/apache
$ /usr/local/apache/bin/apxs -iac mod_log_bytes.c
$ /etc/rc.d/init.d/httpd restart

It will install the missing module and restart apache.

How to increase the MaxClients value greater than the current HARD_SERVER_LIMIT set for Apache.

1. Check if there is any hard server limit specified for Apache max connections.

/usr/local/apache/bin/httpd -V | grep HARD_SERVER_LIMIT

2. If it is there, then you would need to look for this directive in the Apache’s header file /usr/local/apache/include/httpd.h

3.  Edit this file and increase the HARD_SERVER_LIMIT as per your requirement.

4. Recompile Apache using /scripts/easyapache

5. There you will have an option to increase the Apache HARD_SERVER_LIMIT, since easyapache looks for the header files and sees the new value while build. By default the MaxClients value will be 256.

Once the build completes, you can see the new HARD_SERVER_LIMIT.

InnoDB has been disabled for this engine

If you are getting this error so first check if InnoDB is enabled or not using following steps,

root@server[~]# mysql

SHOW ENGINES;

Above command will give you following output

mysql> SHOW ENGINES;
+------------+---------+----------------------------------------------------------------+
| Engine     | Support | Comment                                                        |
+------------+---------+----------------------------------------------------------------+
| MyISAM     | YES     | Default engine as of MySQL 3.23 with great performance         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      |
| InnoDB     | DISABLED| Supports transactions, row-level locking, and foreign keys     |
| BerkeleyDB | NO      | Supports transactions and page-level locking                   |
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) |
| EXAMPLE    | YES     | Example storage engine                                         |
| ARCHIVE    | YES     | Archive storage engine                                         |
| CSV        | YES     | CSV storage engine                                             |
| ndbcluster | NO      | Clustered, fault-tolerant, memory-based tables                 |
| FEDERATED  | YES     | Federated MySQL storage engine                                 |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                          |
| ISAM       | NO      | Obsolete storage engine                                        |
+------------+---------+----------------------------------------------------------------+
12 rows in set (0.00 sec)
Then you can check if its disabled in my.cnf
vi /etc/my.cnf
skip-innodb
Comment the above line in my.cnf using #
skip-innodb
If you cant see this line then add the following line in my.cnf
default-storage_engine=InnoDB
and then restart mysql service
service mysql restart
Now your default storage engine is set to InnoDB