Setting up a multithreaded environment
TYPO3 is an enterprise content management system, so it is thread safe—meaning two instances of the script can be executed simultaneously, and they will run in parallel without interfering with each other. Therefore, Apache can be set up with mod_fcgid
and PHP processes will be allowed to run in parallel.
Note
This setup is not recommended if you have a server with only one or two core processor.
How to do it...
1. Install components of the server:
Shell> apt-get install libapache2-mod-fcgid apache2-mpm-worker php5-cgi Shell> a2enmod actions Shell> a2enmod fcgid
2. Replace contents of
/etc/apache2/mods-available/fcgid.conf
with:<IfModule mod_fcgid.c> AddHandler fcgid-script .fcgi SocketPath /var/lib/apache2/fcgid/sock IPCConnectTimeout 60 IPCCommTimeout 256 BusyTimeout 256 ProcessLifeTime 256 </IfModule>
3. Modify site configuration, by default located in
/etc/apache2/sites-available/default
4. Add the following to the virtual host definition:
Alias /fcgi-bin/ /var/www/fcgi-bin.d/ Action php-fcgi /fcgi-bin/php-fcgi-wrapper
5. Add the following lines to the directory definition for
/var/www/:
AddHandler fcgid-script .php FCGIWrapper /usr/bin/php-cgi .php
6. While there, modify the
Options
, adding+ExecCGI
. Your final site configuration should look like this:<VirtualHost *:80> ServerAdmin webmaster@localhost Alias /fcgi-bin/ /var/www/fcgi-bin.d/ Action php-fcgi /fcgi-bin/php-fcgi-wrapper DocumentRoot /var/www/ <Directory /var/www/> AddHandler fcgid-script .php FCGIWrapper /usr/bin/php-cgi .php Options Indexes FollowSymLinks MultiViews +ExecCGI AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost>
Note
Refer to the Apache manual for descriptions of some of the options listed above, as well as other configuration options.
7. Create the executable link to PHP CGI module:
Shell> mkdir /var/www/fcgi-bin.d Shell> ln s /usr/bin/php5-cgi /var/www/fcgi-bin.d/php-fcgi-wrapper
How it works...
apache2-mpm-worker
package, downloaded in the first command line call, is designed to run several threads simultaneously. PHP CGI binary is installed in the same statement.
We then enable the fcgid
Apache module, and adjust its configuration. Most installations need to increase the timeout; otherwise, you will be looking at an Internal Server Error if the page rendering takes too long. To further complicate the diagnosis, timeouts are not recorded in logs. We increase the values of IPCConnectTimeout, IPCCommTimeout
, and BusyTimeout
, along with the ProcessLifeTime
. Depending on your configuration, you may need to increase these values further.
Now, when a request comes in to Apache, the PHP CGI process will be launched to handle it. With multiple simultaneous requests, multiple processes will be launched, and run parallel to each other, handling individual requests.
Note
If you have multiple clients using this server, they can have separate PHP processes, and not interfere with each other (for security purposes). You can find more information on configuring this set up at http://typo3.org/development/articles/using-php-with-mod-fcgid/.
See also
Creating a scalable architecture
Setting up an NFS share