Archive for the ‘administration’ Category

Installing Alternative PHP Cache (APC) on Debian Etch

Wednesday, January 9th, 2008

Obtaining and installing APC

Alternative PHP Cache (APC) is a free, open, and robust framework for caching and optimizing PHP intermediate code. It’s an PECL extension which shares the packaging and distribution system with its sister, PEAR.

Provided that you have PEAR (php-pear) package installed on your system, the procedure is as simple as pecl install apc. Alternatives.

meglohvat:# pecl install apc
downloading APC-3.0.16.tgz ...
Starting to download APC-3.0.16.tgz (114,298 bytes)
.............done: 114,298 bytes
45 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
Use apxs to set compile flags (if using APC with Apache)? [yes] :

As probably corectly guessed by PECL package managers, you are runing an Apache web server so you should confirm by typing yes or hitting Enter key.

Errors which you may (I did) encounter

checking for re2c... no
configure: WARNING: You will need re2c 0.9.11 or later if you want to \
regenerate PHP parsers.

The re2c package was missing on my system ›› apt-get install re2c.

checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no

I had no gawk or nawk but mawk pattern scanning and processing language installed on system ›› apt-get install gawk.

checking whether apc needs to get compiler flags from apxs...

Sorry, I was not able to successfully run APXS.  Possible reasons:

1.  Perl is not installed;
2.  Apache was not compiled with DSO support (--enable-module=so);
3.  'apxs' is not in your path.  Try to use --with-apxs=/path/to/apxs
The output of apxs follows
/tmp/tmpJQuZdD/APC-3.0.16/configure: line 3846: apxs: command not found
configure: error: Aborting
ERROR: `/tmp/tmpJQuZdD/APC-3.0.16/configure --with-apxs' failed

Missing APache eXtenSion (APXS) tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server. APXS is found in apache2-threaded-dev package. The command apt-get install apache2-threaded-dev will also install a long chain of dependencies.

Setting up APC

A good place to start is Alternative PHP Cache chapter in PHP manual. There it’s written that the default configuration is sutable for most instalations, but they single out two settings: apc.shm_size and apc.stat.

apc.shm_size
Here you should enter the size of each shared memory segment in MB, the default value being 30MB. By default, the maximum size of shared memory segment in Debian is 33554432 or 33MB. You can check it by cat /proc/sys/kernel/shmmax command. If you want to know more about shared memory segments, read this forum thread.
UPDATE: “Of course you can always raise the maximum size of a shared memory segment, using sysctl. Do this only when you know what you are doing. Run “man sysctl” for more information.” (source).
UPDATE: I’ve increased the apc.shm_size to 256MB without changing any kernel setting and it works fine.
apc.stat
From PHP manual:
Be careful if you change this setting. The default is for this to be On which means that APC will stat (check) the script on each request to see if it has been modified. If it has been modified it will recompile and cache the new version. If you turn this setting off, it will not check. That means that in order to have changes become active you need to restart your web server. On a production server where you rarely change the code, turning stats off can produce a significant performance boost.

For included/required files this option applies as well, but note that if you are using relative path includes (any path that doesn’t start with / on Unix) APC has to check in order to uniquely identify the file. If you use absolute path includes APC can skip the stat and use that absolute path as the unique identifier for the file.

If you change these settings or not, the next step is to move the /usr/share/php/apc.php script into your webserver path and access it with browser. It provides a detailed look at what is happening with your cache and, with GD enabled in PHP, also shows you graphs of the situation of your cache.

After checking if caching actualy works, you should point your eyes to the Cache full count value (on the left tables under File Cache Information). The number tells you how many times the cache filled up the allocated memory and had to be cleared of entries not accessed within number of seconds set up with apc.ttl setting. “You should configure your cache to minimize this number if not the resulting cache churn is going to hurt performance. You should either set more memory aside for APC, or use apc.filters to cache fewer scripts.”*

Updates

When I tried to replicate the above installation process on my production server running on minimum required software I encountered some additional problems/missing packages.

    meglohvat:# pecl install apc
    downloading APC-3.0.16.tgz ...
    Starting to download APC-3.0.16.tgz (114,298 bytes)
    .........................done: 114,298 bytes
    45 source files, building
    running: phpize
    sh: phpize: command not found
    ERROR: `phpize' failed

phpize is a shell script to prepare PHP extension for compiling. It is a part of php5-dev package ›› apt-get install php5-dev

Upgrade

To upgrade the APC extension run the command:

meglohvat:# pecl upgrade apc
downloading APC-3.0.19.tgz ...
Starting to download APC-3.0.19.tgz (115,735 bytes)
.........................done: 115,735 bytes
47 source files, building
running: phpize
Configuring for:
PHP Api Version:         20041225
Zend Module Api No:      20060613
Zend Extension Api No:   220060519
Use apxs to set compile flags (if using APC with Apache)? [yes] :

And if everything went well you should see something like this in the end.

Build process completed successfully
Installing '/var/tmp/pear-build-root/install-APC-3.0.19//usr/lib/php5/20060613/apc.so'
upgrade ok: channel://pecl.php.net/APC-3.0.19
You should add "extension=apc.so" to php.ini
meglohvat:#

Setting up SSL with Apache2 on Debian Etch

Friday, December 21st, 2007

For more detailed instructions, pleae follow the link below and do read the comments too, since the solution I used is mentioned in the comments.

1. Create folder

        # mkdir /etc/apache2/ssl

2. Create SSL certificate (you should have openssl package installed)

        openssl req -new -x509 -days 365 -nodes -out /etc/apache2/ssl/apache.pem \
	-keyout /etc/apache2/ssl/apache.pem

3. Enable SSL Apache module

        klopotec:~# a2enmod ssl
	Module ssl installed; run /etc/init.d/apache2 force-reload to enable.

4. Tell Apache to accept connections on port 443 by adding the line below into /etc/apache2/ports.conf

        Listen 443

5. Configure virtual host adding:

        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/apache.pem

i.e.

NameVirtualHost *:443
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName earth.my.flat    DocumentRoot /var/www/

ErrorLog /var/log/apache2/error.log    CustomLog /var/log/apache2/access.log combined

</VirtualHost>
<VirtualHost *:443>    ServerName earth.my.flat

DocumentRoot /var/www/    ErrorLog /var/log/apache2/error.log

CustomLog /var/log/apache2/access.log combined    SSLEngine on

    SSLCertificateFile /etc/apache2/ssl/apache.pem</VirtualHost>

6. Restart/reload Apache

        /etc/init.d/apache2 reload

This walkthrough created on the basis of:
Setting up an SSL server with Apache2

Setup and maintain accurate time with NTP

Wednesday, December 19th, 2007

Network Time Protocol (NTP) is “a protocol for synchronizing the clocks of computer systems.”¹ You can read more about it at www.ntp.org.

To start with, we should first apt-get the required packages:

apt-get install ntp ntpdate

Basically this is it. Your server will pick a different set of four servers from a pool of NTP servers every time it starts up. If you have (low) resources, please do consider to join the pool.

--- Personal notes: do not read below this line :-)  ---

Since my server resides in an academic network with own NTP servers I’ve changed the default settings and replaced the pool of servers with a set of two servers from our network.

server  ntp1.my_network.org
server  ntp2.my_network.org
--- End of personal notes ---

For more setting options and in depth coverage check:
Quick HOWTO: The NTP Server
Accurate Global Time Synchronization

How to make Linux desktop feel quicker

Tuesday, October 9th, 2007

Found this today and implemented it. We’ll see the results.

For the purpose of (my) safety I’m copying the main things below. Do visit the link below for full explanation.

1. Moto

“Screw data. Prioritize code.”

2. Tuning swappiness to prevent impromptu RAM hijacking

To tune swappiness, run as root:

sysctl -w vm.swappiness=1

To make the change permanent, write vm.swappiness=1 on your /etc/sysctl.conf file.

3. Filesystem caches are more important than other caches

How to tell Linux that we want it to prefer inode/dentry cache to other caches?
sysctl -w vm.vfs_cache_pressure=100
To make the change permanent, put vm.vfs_cache_pressure=50 on your /etc/sysctl.conf file.

Tales from responsivenessland: why Linux feels slow, and how to fix that

Resizing ntfs partition using Open Source tool

Monday, September 10th, 2007

Today I helped my friend to setup data partition on her laptop. She used to have one partition for her window$ and just.

Usualy I use Knoppix for this, but recently I discovered a new live CD and this was the perfect opportunity to test it. It is called GParted LiveCD. It is an ~50mb distribution containing basic tools and runs GParted in Fluxbox window manager. Using the GUI is straightforward, but the disc in question had bad sectors so I had to use ntfsresize in command-line. The GUI
The following instructions are copied from http://crashrecovery.org/CrashRecoveryKit/iso/2.4.21/HOWTO.ntfs.html. I’ve copied the instructions since the originating page of these excerpts is not accessible and I’m afraid that this might happen also with the page hosting these excerpts. I’ve just added the notes for dealing with partitioning discs with bad sectors.

(more…)

Debian Etch and HP Deskjet 5440

Thursday, July 12th, 2007

I’ve installed the printer under Sarge and don’t remember all the details of how I did it. Here I will just mention the things I had to do to make it functioning after the upgrade to Etch.

First I searched the Internet and found www.linuxprinting.org and their OpenPrinting database. There I found information about the drivers for my printer that work with Linux.

To do it Debian way I opened Synaptic and checked if there is HPLIP package and sure it was. Installed it and the printer was once again responding to the print commands.

added on 3.9.2007

One day my printer stopped to respond and searching for solution I found even easyer setup method.

apt-get install printconf

Printconf installs some additional packages and after the installation is finished, my printer worked again.

Installing web camera on Debian Etch

Wednesday, May 30th, 2007

It was about two years ago that I last tried to install my web camera. It was in the Sarge “era” and my Linux knowledge was limited that time, so I got lost in the driver installation procedure and all the other technicalities.

My knowledge of this things didn’t improve much from that time, but Debian did. After installing Etch I tried again and the process couldn’t be simpler.

(more…)

Rescuing Linux after window$ (re)install

Wednesday, May 23rd, 2007

I knew before, that i should first install windows and then Linux, but windows tends to have an annoying have-to-reinstall-to-fix-a-problem “feature”.

Luckily the solution is simple. All you need is a live CD distribution with which you boot into your computer and reinstall GRUB (probably also Lilo – I don’t know because I don’t use it). I use System Rescue CD. It works with other LiveCD as well, but System Rescue CD was made for exactly this (kind of) job. It is a command line distro.

(more…)

Setup wireless pcmcia card on Debian Etch

Sunday, April 29th, 2007

Netgear WG511v2 on Compaq Presario 703jp

With the combination of hardware mentioned above I followed the step by step instructions from the article on Debian Administration: Wireless networking using the ndiswrapper module.

While the article was written in the time of Sarge, the only thing I had to change was the line: (more…)

Apt-get: WARNING: The following packages cannot be authenticated!

Sunday, March 25th, 2007

When upgraded form Sarge to Etch I started to notice a warning when using apt-get install from command line. The warning said:

WARNING: The following packages cannot be authenticated!

Googling with the warning text as a keyword turned out (Debian style!) simple solution:

apt-get install debian-archive-keyring
apt-get update

Nice to know that this is becouse Debian offers another level of safety in installing packages.

Little bit more about this topic is avilable at the origin of the above solution:
How to solve “The following packages cannot be authenticated” – The Changelog