Apache error 500 after PHP upgrade

When upgrading your server from old PHP release to 5.4 make sure your application does not use deprecated functions such as session_register.
This function may be used in older CMS versions, as Tiger CMS.

To comment out all occurrences of incompatible functions in the code you can use following command:
Example for session_register:

find . -type f -exec sed -i 's/session_register/\/\/session_register/g' {} \;

Generic troubleshooting steps for error 500 in Apache:

1. Check Apache error log
/var/log/apache2/error.log

2. Turn on PHP Error reporting in etc/php.ini (/etc/php5/apache2/php.ini)

error_reporting(E_ALL);

3. Create an info.php file to test php, with content:

<?php phpinfo; ?>

So you can see what version you use and if it is loaded correctly.

Good Luck!

Essential MySQL server performance tuning

Most important MySQL server configuration options to improve performance on new server installation:

1. innodb_buffer_pool_size – Amount of memory MySQL will use for data cache.
Set to ~80% of server RAM. (If server is dedicated for DB). Example for server with 32GB RAM:

innodb_buffer_pool_size=24G

2. innodb_flush_log_at_trx_commit = 2 – log writes will happen once per second instead of every commit. Major I/O bottleneck with many writes.

innodb_flush_log_at_trx_commit = 2

3. innodb_log_file_size – The larger the value, the less checkpoint flush activity is needed in the buffer pool, saving disk I/O.

innodb_log_file_size = 512M

After changing the value, gracefully shutdown MySQL and move /var/lib/mysql/ib_logfile* somewhere safe just in case. If MySQL starts successfully, delete moved files.

4. innodb_log_buffer_size – enables large transactions to run without writing the log to disk before the transactions commit, again – saving disk I/O. Default = 1MB.

innodb_log_buffer_size = 8M

5. innodb_file_per_table – Not a performance setting, however a very important parameter to set right after server installation as it will be hard to change it later.

In file-per-table mode, each newly created table will have its own data file, that will allow to reclaim used space after table deletion, and have other advantages

Summary:

innodb_buffer_pool_size=24G
innodb_flush_log_at_trx_commit = 2
innodb_log_file_size = 512M
innodb_log_buffer_size = 8M
innodb_file_per_table

MySQL Replication configuration example

Database replication will synchronize databases between two different servers.
Should any record change on primary server, it will be automatically sent to secondary (slave) server.

  • Primary server
  • Edit MySQL config file /etc/my.cnf

    server-id=1
    log_bin=/var/log/mysql/mysql-bin.log
    

    log_bin – specifies the location of MySQL binary log, which is used for replication.

    You can limit the binary logging to only one database by specifying parameter binlog_do_db=database .
    However this is not recommended, see (dev.mysql.com )

    Save changes and restart MySQL server.

    service mysql restart

    Now we should grant privileges on slave user which will be used for replcation.

    mysql -u root -p
    GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'pass';
    FLUSH PRIVILEGES;
    

    Now lock and dump DB to the file to transfer it to the second server.

    FLUSH TABLES READ LOCK;
    SHOW MASTER STATUS;
    

    Save “Position” field.

    If you do something in this window database will automatic unlock,
    you should open new window and do it there:

    mysqldump -u root -p -f db1 > db1.sql

    db1 – name of database, that you want to dump

    Unlock database.

    UNLOCK TABLES;

    Now it’s time to configure secondary server.

  • Secondary server
  • CREATE DATABASE db1;

    Import dump from first server:

    mysql -u root -p -f db1 < db1.sql

    Edit MySQL config file /etc/my.cnf

    server-id=2
    relay-log=/var/log/mysql/mysql-relay-bin.log
    log_bin=/var/log/mysql/mysql-bin.log
    

    Restart MySQL:

    service mysql restart

    Server configured and ready for replication.
    To activate replication on slave server execute following command in mysql console:

    CHANGE MASTER TO
    MASTER_HOST='IP-address or primary server',
    MASTER_USER='slave_user',
    MASTER_PASSWORD='pass',
    MASTER_LOG_FILE='mysql-bin.000001',
    MASTER_LOG_POS=XXX;

    Remember “Position” field from “SHOW MASTER STATUS” command and write value in place of XXX.

    And start replacation:

    START SLAVE;

    Look at status::

    SHOW SLAVE STATUS\G

    Slave_IO_State: Waiting for master to send event

    To stop replication use:

    STOP SLAVE

    PS: MySQL uses TCP port 3306 for communication, so it should be open between them.

    Zabbix icmpping not working cnt=0 rcv=0

    After doing a clean install of zabbix-proxy on a CentOS 6 server, all our icmpping / icmppingsec items started to return zero values.

    Zabbix debug log showed following lines:

    
    

    31790:20140611:073610.004 In process_ping() hosts_count:1
    31790:20140611:073610.004 /tmp/zabbix_proxy_31790.pinger
    31790:20140611:073610.004 10.211.7.245
    31790:20140611:073610.004 /usr/sbin/fping -C5 -p200 -b1024 -t1000 2>&1 The problem was in SELinux policy, however audit.log did not show any blocked events until the following command was run:

    yum install -y policycoreutils-python
    /usr/sbin/semodule -DB
    
    The -D option disables dontaudit rules; the -B option rebuilds policy.
    type=SYSCALL msg=audit(1402473587.551:550371): arch=c000003e syscall=5 success=no exit=-13 a0=0 a1=7fff2c862c70 a2=7fff2c862c70 a3=238 items=0 ppid=16064 pid=16065 auid=0 uid=500 gid=500 euid=500 suid=0 fsuid=500 egid=500 sgid=500 fsgid=500 tty=(none) ses=87526 comm="fping" exe="/usr/sbin/fping" subj=unconfined_u:system_r:ping_t:s0 key=(null)
    type=AVC msg=audit(1402473588.556:550372): avc:  denied  { getattr } for  pid=16067 comm="fping" path="/tmp/zabbix_proxy_31776.pinger" dev=dm-0 ino=784936 scontext=unconfined_u:system_r:ping_t:s0 tcontext=unconfined_u:object_r:initrc_tmp_t:s0 tclass=file
    
    To add an exception for this event run following command:
    grep fping /var/log/audit/audit.log | audit2allow -M zabbix_fping
    semodule -i zabbix_fping.pp
    
    Now icmpping / icmppingsec checks should succeed:
    29940:20140611:071726.366 In process_ping() hosts_count:1
     29940:20140611:071726.366 /tmp/zabbix_proxy_29940.pinger
     29940:20140611:071726.366     10.20.2.20
     29940:20140611:071726.366 /usr/sbin/fping -C5 -p200 -b24 -t900 2>&1 
    

    Compiling PHP for Zabbix 2.2 frontend

    To compile PHP for Zabbix 2.2 frontend you will need to use the following keys:

    ./configure --enable-mbstring --enable-sockets --with-mysql  --with-mysqli --with-ldap --enable-fpm --enable-bcmath  --with-gettext --with-xmlrpc --with-openssl --with-mcrypt --with-gd --with-zlib --with-freetype-dir=/usr/include/freetype2 --with-jpeg-dir=/usr/lib 
    

    PHP ini required values (minimal):

     memory_limit = 128M
     post_max_size = 16M
     upload_max_filesize = 2M
     max_execution_time = 300
     max_input_time = 300
     session.auto_start = 0