Install APC for PHP on Debian 5 Lenny

I have recently moved from hosting on a CentOS box to Debian and needed to install PHP’s APC opcode cache on it. I’ve posted about how to do this before on a CentOS box which is a very manual process and now add this post to install APC on Debian which is much easier.

As the root user or using sudo run the following command:

aptitude install php-apc

Everything else is done for you and all that is needed now is to gracefully reload Apache, again running as the root user or using sudo:

apache2ctl graceful

The configuration file is at /etc/php5/conf.d/apc.ini should you wish to change any of the settings such as the APC memory size etc.

If you want to have a page showing the current APC statistics, run the following command:

gzip -dc /usr/share/doc/php-apc/apc.php.gz > /path/to/apc.php

Make sure /path/to/apc.php is a location available in a web browser (and ideally password and/or IP address restricted) and then you can view detailed statistical information. I have some screenshots available here from an older post.

Changing exim4 settings with Debian 5 Lenny

Exim4 is a mail transfer agent for sending and receiving emails on a server. This post looks at how to change the major configuration options on Debian 5 Lenny, which incudes how to allow remote delivery of emails to avoid the “Mailing to remote domains not supported” error.

These instructions are for Debian but should also work for Debian derived Linux distributions with exim4 installed such as the Ubuntu family, Knoppix, Mepis etc.

To start the exim4 configuration dialog on Debian 5 Lenny run the following command either as the root user or using the sudo utility command:

$ dpkg-reconfigure exim4-config
 

This will start the configuration dialogs. Depending on your terminal size, the first screen will appear over two pages (as I’ve shown below) or as a single screen.

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 ââ
 â Please select the mail server configuration type that best meets yourâ
 â needs.â
 ââ
 â Systems with dynamic IP addresses, including dialup systems, shouldâ
 â generally be configured to send outgoing mail to another machine, calledâ
 â a 'smarthost' for delivery because many receiving systems on theâ
 â Internet block incoming mail from dynamic IP addresses as spamâ
 â protection.â
 ââ
 â A system with a dynamic IP address can receive its own mail, or localâ
 â delivery can be disabled entirely (except mail for root and postmaster).â
 ââ
 â<Ok>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

After hitting <enter> to select the <OK> option you will then be taken through to the dialog where you select which type of mail server configuration. By default exim4 will be set up to allow local delivery only and if you try to send email to a remote address you will get an error in the log files stating that “Mailing to remote domains not supported”.

To allow outbound mail, select the “internet site” option. I also tried the second option but it still wouldn’t send mail. Selecting the internet site option allowed the mail to be sent. There must be some other configuration option with the smarthost options but I couldn’t work it out.

ââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââ
 â General type of mail configuration:â
 ââ
 âinternet site; mail is sent and received directly using SMTPâ
 âmail sent by smarthost; received via SMTP or fetchmailâ
 âmail sent by smarthost; no local mailâ
 âlocal delivery only; not on a networkâ
 âno configuration at this timeâ
 ââ
 ââ
 â<Ok><Cancel>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

The remaining screens vary a little depending on which option was selected. Those shown below are when “internet site” was selected as the type.

The next dialog allows you to specify the hostname for the mail server.

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 â The 'mail name' is the domain name used to 'qualify' mail addressesâ
 â without a domain name.â
 ââ
 â This name will also be used by other programs. It should be the single,â
 â fully qualified domain name (FQDN).â
 ââ
 â Thus, if a mail address on the local host is foo@example.org, theâ
 â correct value for this option would be example.org.â
 ââ
 â This name won't appear on From: lines of outgoing messages if rewritingâ
 â is enabled.â
 ââ
 â System mail name:â
 ââ
 â sitehost.securehosting.co.nz_____________________________________________ â
 ââ
 â<Ok><Cancel>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

The next screen allows you to select the IP addresses that the mail server will listen on to accept mail from. If your terminal is large enough it will show the next two screens below on one screen.

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 ââ
 â Please enter a semicolon-separated list of IP addresses. The Exim SMTPâ
 â listener daemon will listen on all IP addresses listed here.â
 ââ
 â An empty value will cause Exim to listen for connections on allâ
 â available network interfaces.â
 ââ
 â If this system only receives mail directly from local services (and notâ
 â from other hosts), it is suggested to prohibit external connections toâ
 â the local Exim daemon. Such services include e-mail programs (MUAs)â
 â which talk to localhost only as well as fetchmail. External connectionsâ
 â are impossible when 127.0.0.1 is entered here, as this will disableâ
 â listening on public network interfaces.â
 ââ
 â<Ok>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

If you only want the server to listen to incoming emails from the local machine then leave it as 127.0.0.1; if you want to allow remote connections then specify 127.0.0.1, then a semi-colon and then the IP address of the server itself.

ââââââââââââââââ⤠Mail Server configuration âââââââââââââââââ
 â IP-addresses to listen on for incoming SMTP connections:â
 ââ
 â 127.0.0.1________________________________________________ â
 ââ
 â<Ok><Cancel>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

This screen allows you to specify which domains the mail server will accept mail for.

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 â Please enter a semicolon-separated list of recipient domains for whichâ
 â this machine should consider itself the final destination. These domainsâ
 â are commonly called 'local domains'. The local hostnameâ
 â (sitehost.securehosting.co.nz) and 'localhost' areâ
 â always added to the list given here.â
 ââ
 â By default all local domains will be treated identically. If bothâ
 â a.example and b.example are local domains, acc@a.example andâ
 â acc@b.example will be delivered to the same final destination. Ifâ
 â different domain names should be treated differently, it is necessary toâ
 â edit the config files afterwards.â
 ââ
 â Other destinations for which mail is accepted:â
 ââ
 â sitehost.securehosting.co.nz_____________________________________________ â
 ââ
 â<Ok><Cancel>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

This screen allows you to specify which domains the mail server will relay mail for.

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 â Please enter a semicolon-separated list of recipient domains for whichâ
 â this system will relay mail, for example as a fallback MX or mailâ
 â gateway. This means that this system will accept mail for these domainsâ
 â from anywhere on the Internet and deliver them according to localâ
 â delivery rules.â
 ââ
 â Do not mention local domains here. Wildcards may be used.â
 ââ
 â Domains to relay mail for:â
 ââ
 â _________________________________________________________________________ â
 ââ
 â<Ok><Cancel>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

It’s possible to always relay mail from a particular IP address(es) or range. This next screen allows you to specify these. For example you might have several web servers but want all of them to send their mail via a specific mail server. You would then enter those servers IP addresses here, separated by semi-colons.

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 â Please enter a semicolon-separated list of IP address ranges for whichâ
 â this system will unconditionally relay mail, functioning as a smarthost.â
 ââ
 â You should use the standard address/prefix format (e.g. 194.222.242.0/24â
 â or 5f03:1200:836f::/48).â
 ââ
 â If this system should not be a smarthost for any other host, leave thisâ
 â list blank.â
 ââ
 â Machines to relay mail for:â
 ââ
 â _________________________________________________________________________ â
 ââ
 â<Ok><Cancel>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

The next option is about DNS queries. You’d normally leave this as the default <No>

âââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 ââ
 â In normal mode of operation Exim does DNS lookups at startup, and whenâ
 â receiving or delivering messages. This is for logging purposes andâ
 â allows keeping down the number of hard-coded values in theâ
 â configuration.â
 ââ
 â If this system does not have a DNS full service resolver available atâ
 â all times (for example if its Internet access is a dial-up line usingâ
 â dial-on-demand), this might have unwanted consequences. For example,â
 â starting up Exim or running the queue (even with no messages waiting)â
 â might trigger a costly dial-up-event.â
 ââ
 â This option should be selected if this system is using Dial-on-Demand.â
 â If it has always-on Internet access, this option should be disabled.â
 ââ
 â Keep number of DNS-queries minimal (Dial-on-Demand)?â
 ââ
 â<Yes><No>â
 ââ
 ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

The next option is how to store locallly delivery mail. Select the option you prefer and then <OK>

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 â Exim is able to store locally delivered email in different formats. Theâ
 â most commonly used ones are mbox and Maildir. mbox uses a single fileâ
 â for the complete mail folder stored in /var/mail/. With Maildir formatâ
 â every single message is stored in a separate file in ~/Maildir/.â
 ââ
 â Please note that most mail tools in Debian expect the local deliveryâ
 â method to be mbox in their default.â
 ââ
 â Delivery method for local mail:â
 ââ
 âmbox format in /var/mail/â
 âMaildir format in home directoryâ
 ââ
 ââ
 â<Ok><Cancel>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

Finally choose how the configuration is stored. You would normally just leave it as the default <No> unless you have some reason to do it differently.

 ââââââââââââââââââââââââ⤠Mail Server configuration âââââââââââââââââââââââââ
 ââ
 â The Debian exim4 packages can either use 'unsplit configuration', aâ
 â single monolithic file (/etc/exim4/exim4.conf.template) or 'splitâ
 â configuration', where the actual Exim configuration files are built fromâ
 â about 50 smaller files in /etc/exim4/conf.d/.â
 ââ
 â Unsplit configuration is better suited for large modifications and isâ
 â generally more stable, whereas split configuration offers a comfortableâ
 â way to make smaller modifications but is more fragile and might break ifâ
 â modified carelessly.â
 ââ
 â A more detailed discussion of split and unsplit configuration can beâ
 â found in the Debian-specific README files in /usr/share/doc/exim4-base.â
 ââ
 â Split configuration into small files?â
 ââ
 â<Yes><No>â
 ââ
 âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
 

After accepting the last setting the settings application closes and the exim mail server is restarted:

Stopping MTA for restart: exim4_listener.
 Restarting MTA: exim4.
 

It will now be working with the new set of options.

Changing the default message of the day with Debian 5 Lenny

When you first log in to a default install of a Debian 5 Lenny machine from the command line you’ll be greeted with a message like “The programs included with the Debian GNU/Linux system are free software…”. This is controlled by the “message of the day” file. This post looks at how easy it is to change this so you can get rid of the default text.

The default MOTD message in Debian 5 Lenny is along the lines as this, where the first line will have been set to whatever your kernel and kernel date is:

Linux debian 2.6.26-1-686 #1 SMP Sat Jan 10 18:29:31 UTC 2009 i686
 
 The programs included with the Debian GNU/Linux system are free software;
 the exact distribution terms for each program are described in the
 individual files in /usr/share/doc/*/copyright.
 
 Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
 permitted by applicable law.
 

To change or remove the message, simply edit the /etc/motd file in your favourite text editor either as the root user or using sudo and then save the file. Clear all the text for no MOTD or replace it with whatever you would prefer. The next time you log in it will show the new (or no) text message.

This will work for now, but on reboot the file is reconstructed by the /etc/init.d/bootmisc.sh script. It writes out “uname -snrvm” to /var/run/motd (/etc/motd is a symbolic link to /var/run/motd) and then adds the text from /etc/motd.tail

Therefore to change what goes into the motd file on reboot, edit the /etc/motd.tail file, making it blank for no message of the day.

If you don’t want the uname information to be included in the motd file then you would also need to modify the /etc/init.d/bootmisc.sh file.

Run scripts at system startup on Linux

This post looks at how to run additional scripts or applications at system startup / system boot up on Linux. I can confirm that this works on CentOS (and should therefore work on Red Hat Enterprise Linux from which is it derived, and Fedora and Fedora based distros) and Debian (and therefore on Debian derived distros).

After all the other processes are started by the init command at boot time, the following script is run on Red Hat / CentOS based systems:

/etc/rc.d/rc.local
 

And this script on Debian based systems:

/etc/rc.local

You can put your additional commands or scripts to run into this script with the knowledge that everything else has already started up, and doesn’t require the complex initialisation scripts that appear in the /etc/rc.d/init.d or /etc/init.d directory.