How to install PHP APC in CentOS

I assume you already have PEAR/PECL available. I am using the CentOS’s stock PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “doc.php.net”
Channel “doc.php.net” is up to date
Updating channel “pear.php.net”
Channel “pear.php.net” is up to date
Updating channel “pecl.php.net”
Channel “pecl.php.net” is up to date[/code]

Continue reading “How to install PHP APC in CentOS”

How to install PHP APC in OS X

I assume you already have PEAR/PECL available. I am using the Mac OS X PHP environment that is provided by Apple’s XCode but it shouldn’t matter how you get your PHP. First you need to update your channels:

[code lang=”bash”]kahwee:~ kahwee$ sudo pear update-channels
Updating channel “doc.php.net”
Channel “doc.php.net” is up to date
Updating channel “pear.php.net”
Channel “pear.php.net” is up to date
Updating channel “pecl.php.net”
Channel “pecl.php.net” is up to date[/code]

Continue reading “How to install PHP APC in OS X”

How to install PHP APC through PEAR

If you try to install PHP APC 3.1.5 through PHP PEAR and encounter errors regarding phpize or the following:

[code lang=”bash”]/usr/include/php5/ext/pcre/php_pcre.h:29:18: error: pcre.h: No such file or directory[/code]

…well don’t worry. You’re missing a few components. For phpize, you’ll need the php5-dev that you can fetch from Ubuntu. For the php_prce.h error, you’ll need pcre3-dev package which is essentially Perl 5 Compatible Regular Expression Library – development files.

Perform the following and install PHP APC using PECL again:

[code lang=”bash”]sudo apt-get install libpcre3-dev php5-dev
sudo pecl install apc-3.1.5[/code]

And it’s done:

[code lang=”bash”]Build process completed successfully
Installing ‘/usr/lib/php5/20090626+lfs/apc.so’
install ok: channel://pecl.php.net/APC-3.1.5
configuration option “php_ini” is not set to php.ini location
You should add “extension=apc.so” to php.ini[/code]

This is tested against Ubuntu 10.04 as well as Ubuntu 10.10 environments.

You can add it to /etc/php5/conf.d/apc.ini by:

[code lang=”bash”]nano /etc/php5/conf.d/apc.ini[/code]

Add in the following codes:

[code lang=”php”]
extension=apc.so
apc.enabled=1
apc.shm_segments=1
apc.shm_size=32M
apc.cache_by_default=1
apc.stat=1
apc.rfc1867=1 //For Drupal upload progress.
apc.stat=7200 //2 hours
[/code]

How to log slow MySQL queries

I haven’t been generous enough to spend money on higher RAM for my blogs. I started to notice slow downs in the blog recent, particularly caused by a particular plugin that does related posts. I found out by checking on slow queries log. Here’s how to get MySQL to log slow queries:

If you are using Ubuntu of Debian-based operating systems, it’s found in /etc/mysql/my.cnf. You may need to use

[code lang=”bash”]sudo nano /etc/mysql/my.cnf[/code]

Press CTRL + W, that’s search in nano. Find “slow” for the section for logging slow queries.

[code lang=”bash”]# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes[/code]

I uncommented “log_slow_queries” and “long_query_time”. I put long_query_time to 8. That requires a bit of experimentation. It depends on your environment.

I run the following command to check the slow queries:

[code lang=”bash”]sudo cat /var/log/mysql/mysql-slow.log[/code]

After you change the configuration in my.cnf, you need to restart. You can do so using:

[code lang=”bash”]sudo /etc/init.d/mysql restart[/code]

Hope it helps.

How to optimize MySQL database with a command

When you delete large portions for data from your MySQL table, the database becomes more fragmented. It is always a good idea to re-optimize your MySQL database especially if you have a lot of varying characters (VARCHAR). Here’s the command to optimize just one table:

[code lang=”sql”]OPTIMIZE TABLE foo[/code]

[ad#highlight]

But I am looking for a more command line solution and here it is:

[code lang=”bash”]mysqlcheck -op database_name[/code]

The ‘o’ refers to optimize. And the ‘p’ is the option for password requirement. You’ll be prompted for the password.

If you’re logged in as user ‘john’ in your SSH, the MySQL username will be ‘john’. If that’s not what you want, use option ‘u’ like this:

[code lang=”bash”]mysqlcheck -op -u user_name database_name[/code]

And to optimize all databases:

[code lang=”bash”]mysqlcheck -op -u user_name –all-databases[/code]

You can also use option ‘r’ to repair.

Note that the optimization only works for MyISAM, InnoDB, and ARCHIVE tables.