Main Page

Revision as of 20:04, 4 November 2011 by Admin (talk | contribs) (PHP)
Jump to navigation Jump to search


"Can you take a look at my server and tell me what's going on?"

Starting Points

Who is on the server?


Show top processes.

top -c

Load averages.

sar -q

Ram usage.

sar -r

I/O wait

sar -s

After you get a good idea of what is causing load / unresponsiveness, you can start narrowing things down.


Apache Status


Apache connection


Check settings in httpd.conf. Added +160 usually located around that line number.

vim /usr/local/apache/conf/httpd.conf +160

Think Apache is causing server to go OOM? Check PHP memory limit. If it's above 32M ask client if they need it this high.

grep memory_limit /usr/local/lib/php.ini

Find all users php.ini files.

find /home/*/public_html/* -name php.ini


Useful for seeing what queries are doing what.

watch -n 1 'mysqladmin proc stat'

Check /tmp for sess_* files. Can mean tables are corrupt.

ll /tmp/

Check the logs.


Then check MySQL settings

vim /etc/my.cnf

Network Stuff

New server missing some IPs it was supposed to come with?

 service ipaliases restart


One Liners

See MySQL status. Updates every 1 s.

watch -n 1 'mysqladmin proc stat'

Optimize Tables.

for i in $(mysql -e "show databases;" | sed 's/Database//') ; do for each in $(mysql -e "use $i; show tables;" \
| sed 's/Tables.*//' ;) ; do mysql -e "use $i ; optimize table $each" ; done ; done

MySQL check that will: check all databases, analyze, optimize and repair. Pretty useful, usually safe.

mysqlcheck -Aaor

Dump a database.

mysqldump database > database.sql

Import a database.

mysql database < database.sql

Viewing and Deleting Tables and Databases

Look at databases and tables.

> use databasename;
> show tables;

Drop (delete) a database. Can be useful if importing a database and it gives you an error.

> drop database databasename;

Optimization Scripts

While the default configs here are a good starting point. These scripts will help in finding any issues with the users current MySQL config.

Note: I like to run these like : '/scripts/ > /root/tuning-primer.txt[n]' This saves the output, so you don't feel compelled to add it as a note to a ticket or admin comments. You can also use it to compare the results after 48 hours. This is a great way to document these changes.

wget -O /scripts/
chmod +x /scripts/

If is down, try:

wget -O /scripts/

wget -O /scripts/
chmod +x /scripts/

Upgrading MySQL

Template:Box Warning

If pre-MySQL 5.0:

 mysqlcheck -Aaor

If MySQL 5.0 to 5.1:

 mysqlcheck -Agr

And back up all the databases:

 mkdir -p /backup/mysqldumps
 cd /backup/mysqldumps
 for i in $(mysql -e "show databases;" | cut -d ' ' -f2 | grep -v Database); do `mysqldump $i > $i.sql`; done

Enabling a Slow Query Log

How to enable a slow query log

touch /var/lib/mysql/slow.log

chown mysql. /var/lib/mysql/slow.log

In the my.cnf file under the mysqld section add this:


Then restart mysql and you have a slow query log.

If you want to specify the number of seconds that indicates a long or slow query, use this line in /etc/my.cnf :

long_query_time = 5

changing 5 to whatever number of seconds you want.


Parse Error

Parse error: syntax error, unexpected T_STRING


Force PHP5

Add to .htaccess:

AddType application/x-httpd-php5 .html .htm

Apache PHP Handlers

Can use this command to change owner and group

chown -R user:group /directory/


Ownership - permissions should be 755



Ownership - permissions should be 755



Email accounts not showing up in cPanel.

Check /home/user/etc Make sure the passwd file and shadow file have proper permissions also make sure they are located in



Can't find file: 'horde_sessionhandler.MYI'

/etc/init.d/mysqld stop
rm /var/lib/mysql/horde/horde_sessionhandler.frm
/etc/init.d/mysqld start

>CREATE TABLE horde_sessionhandler (session_id VARCHAR(32) NOT NULL, session_lastmodified INT NOT NULL, session_data LONGBLOB, PRIMARY KEY 
(session_id)) ENGINE = InnoDB;

>GRANT SELECT, INSERT, UPDATE, DELETE ON horde_sessionhandler TO [email protected];


Find top sending IPs in exim logs:


Find authenticated users who may be spamming:


Spam comming from scripts:


Removing all queued messages at once in a safe way:




'''/scripts/smtpmailgidonly on'''


Add relaying from another server:

Add the IP to the "remote service IPs" in cPanel


To search for available packages:

yum search example

Find packages and where they lead to:

rpm -qa | grep example
rpm -ql example

Java + Tomcat

Regular install:

yum install java-1.6.0-openjdk.x86_64
yum install tomcat5


Configuration file, lots of settings can be changed here:

vim /usr/local/apache/conf/httpd.conf

Includes (external settings that Apache reads in case the conf was rebuilt)

cd /usr/local/apache/conf/includes

Check for a basic Dos, or heavy traffic:


Count the processes:

ps aux | grep httpd | wc -l
ps aux | grep php | wc -l


cPanel not working for some accounts on some servers:

chgrp user /var/cpanel/users/username
vim /etc/proftpd/username