Tuning Apache

Modified: 05 Jan 2015 18:06 UTC

When tuning Apache, remember to take into account the amount of RAM your SmartMachine contains, and the typical amount of RAM that all the processes on your SmartMachine consume.

The following table shows typical directives in /opt/local/etc/httpd/includes/mpm.conf for different sized SmartMachines to reduce the amount of RAM used on multiple requests:

Apache Directive 1/4GiB 1GiB 2GiB 4GiB
StartServers 2 8 16 32
MinSpareServers 1 4 8 16
MaxSpareServers 2 8 16 32
ServerLimit 8 64 128 256
MaxClients 8 64 128 256
MaxRequestsPerChild 0 0 0 0
ListenBacklog 1000 1000 1000 1000

If your site serves up a lot of static content, you may want to serve up that content from a separate light weight server such as Nginx or Lighttpd.

Always setup your databases on a separate SmartMachine. You can then setup the databases to connect to your Apache web servers through a private IP. 

When running PHP with Apache you would want to enable an opcode cache so that PHP opcodes are not recompiled on each page request.

View current Apache status

Apache is configured with a web based system status module that is very useful in getting the current status of your web server.

To enable mod_status you must SSH into your SmartMachine and become root:

1) Add these lines to the top of your Apache config file for the virtual server you want to monitor:

2) In the same config file add this location in the Virtual server after your cgi-bin declarations:

You should only enable this when you are troubleshooting your server as this makes your status available to all IP's.

You can limit who is allowed to view the status page by un-commenting the Deny rules and adding hosts to the Allow rule

3) Restart your Apache server:

4) To view status from a web browser:

To have the page refresh ever 5 seconds:

To view from the command line:

You can also use get a machine readable version of this page fro scripts by calling:

Apache Configuration for Maximum Open Files

Older versions of PHP have a known file descriptor bug. This has been fixed in Joyent's PHP 5.3.5 package.

Error on running out of file descriptors are recorded in your Apache error log. This normally is an issue with customer applications.

You can view what files are being used by Apache with the command:

pfiles $(pgrep http)

How to check what you have set presently (as root or sudo)

prctl -i process -n process.max-file-descriptor `pgrep httpd`

Check to see if a project entry exists in /etc/project for httpd (as root or sudo)

cat /etc/project | grep httpd

If it does not exist (the command returns no result), then use projadd command to include an entry for apache

projadd -p 103 -c "httpd Project" -K "process.max-file-descriptor=(basic,1024,deny)" httpd

Number of Connections

By default Apache comes with 1024 possible open files for each worker. This translates into 1024 ports which means your total maximum connections.

To increase the port limit: 

  1. Run these commands:
    prctl -r -t privileged -n process.max-file-descriptor -v 32768 -i process `pgrep httpd`
    prctl -t basic -n process.max-file-descriptor -x -i process `pgrep httpd`
  2. Then to make it reboot ready, run this command:
    projmod -s -K "process.max-file-descriptor=(basic,32768,deny)" httpd
  3. Change the SMF start/exec property to run under the "httpd" project:
    svccfg -s http:apache setprop start/exec=astring: \"newtask -p httpd /opt/local/sbin/httpd -k start\"
    svcadm refresh http:apache
  4. Restart Apache:
    svcadm restart http:apache

Use Static IP in conf files

You will reduce memory usage of Apache clients by binding the Server and VirtualHosts to a specific IP. Another way of saying this is not to use wildcard IP's ( * ):

You will have to update your conf files if you change IP's on your SmartMachine.

You can do this by modifying the following files:


And change the existing entries to have the Apache server listen on the specific IP:

Uses less memory:


Uses more memory:

Listen *
Listen *:80
Listen *:443

Also update your Virtualhost entries in:


Uses less memory:


Uses more memory:

<VirtualHost *:80>
<VirtualHost *:443>

Disabling mod_passenger

If you are not using Phusion Passenger (for Ruby on Rails apps), you can safely comment out the lines to load the dso under /opt/local/etc/httpd/includes/dso.conf:

#LoadModule passenger_module lib/httpd/mod_passenger.so

and /opt/local/etc/httpd/httpd.conf that loads the module:

#Include etc/httpd/includes/passenger.conf

Helper Services

There are many services that you can run to assist you in debugging and increasing the performance of your web application:

Install your free version of New Relic

Install New Relic on your SmartMachine - it is free if you have a 1G or larger system and it provides so much information that we in Support can better assist you. Really, with the graphs and monitoring that they have allow you to quickly tell if it is code or database causing you issues.


Go there, set up your free account and install the client on your SmartMachines.

Enable caching

For PHP the Apache plugin APC can greatly reduce your apps load time by caching objects.

For database queries enabling MemCache can speed up database calls with caching.

Use a lightweight web server instead

Apache is great. However, it's full features may be more than what you need.  You can dramatically increase performance of your SmartMachine and reduce your memory foot print by using a lightweight web server.

For example, here is an external article on how to setup and configure Ngnix on a Joyent SmartMachine: http://ecarmi.org/writing/setup-nginx-joyent-solaris-smartmachine/

External Apache Tuning articles


At a Glance

This page shows you some values you can use to tune Apache to use less RAM.

For more information, see Apache 2.2 Performance Tuning Guide

                                        <div class="tabletitle">
                        <a name="comments">

                    <table border="0" width="100%">
                            <td >
                                <a name="comment-5144833"></a>
                                <font class="smallfont"><p>The svccfg command gives 'Syntax error.'</p>

I think the correct command is:

svccfg -s http:apache setprop start/project = astring: httpd

svccfg -s apache setprop start/exec=astring: \"newtask -p httpd /opt/local/sbin/httpd -k start\"