Backend Development 24 min read

How to Build a High‑Performance LAMP Stack with FastCGI, ApacheBench, and XCache

This guide walks through deploying a LAMP architecture with static‑dynamic separation, compiling PHP with FastCGI, configuring Apache proxy to PHP‑FPM, performing load testing using ApacheBench, installing XCache for PHP acceleration, and finally setting up a Discuz BBS forum, providing step‑by‑step commands and performance metrics.

Efficient Ops
Efficient Ops
Efficient Ops
How to Build a High‑Performance LAMP Stack with FastCGI, ApacheBench, and XCache

LAMP static/dynamic separation concept

When building a high‑efficiency web architecture, separating static and dynamic requests is essential. LAMP (Linux, Apache, MySQL, PHP) is a mature enterprise web stack; LNMP replaces Apache with Nginx. PHP can run in CGI, Apache module, or FastCGI mode, with FastCGI offering superior performance because PHP runs as an independent process managed by php‑fpm.

LAMP installation and configuration

1. Environment preparation

The environment includes an existing Apache and MySQL server on CentOS 7. Images illustrate the server layout.

2. Deploy PHP server

Compile and install PHP 5.6 with required extensions and FastCGI support:

<code># Install PHP and dependencies
[root@php ~]# tar zxf libmcrypt-2.5.7.tar.gz -C /usr/src
[root@php ~]# tar zxf php-5.6.27.tar.gz -C /usr/src
[root@php ~]# yum -y install libxml2-devel openssl-devel bzip2-devel
[root@php libmcrypt-2.5.7]# ./configure --prefix=/usr/local/libmcrypt && make && make install
[root@php php-5.6.27]# ./configure --prefix=/usr/local/php5.6 \
    --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd \
    --with-openssl --enable-fpm --enable-sockets --enable-sysvshm \
    --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir \
    --with-zlib --with-libxml-dir=/usr --enable-xml --with-mhash \
    --with-mcrypt=/usr/local/libmcrypt --with-config-file-path=/etc \
    --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts && make && make install</code>

Key compile options:

--prefix sets installation directory.

--with-mysql, --with-pdo-mysql, --with-mysqli enable MySQL connectivity.

--enable-fpm enables php‑fpm.

--enable-sockets, --enable-sysvshm, --enable-mbstring add socket, shared memory, and multibyte string support.

--with-freetype-dir, --with-jpeg-dir, --with-png-dir allow dynamic image generation.

--with-zlib adds compression support.

--with-libxml-dir enables XML parsing.

--with-mhash and --with-mcrypt add hashing and encryption libraries.

Configure php‑fpm and start the service:

<code># Adjust php.ini and init script
[root@php php-5.6.27]# cp php.ini-production /etc/php.ini
[root@php php-5.6.27]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@php php-5.6.27]# chmod +x /etc/init.d/php-fpm
[root@php php-5.6.27]# chkconfig --add php-fpm
[root@php php-5.6.27]# chkconfig php-fpm on
# Edit php‑fpm config (example values)
[root@php php-5.6.27]# cp /usr/local/php5.6/etc/php-fpm.conf.default /usr/local/php5.6/etc/php-fpm.conf
[root@php php-5.6.27]# vim /usr/local/php5.6/etc/php-fpm.conf
listen = 192.168.20.5:9000
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
# Start services and open firewall port
[root@php ~]# systemctl start php-fpm
[root@php ~]# firewall-cmd --permanent --add-port=9000/tcp
[root@php ~]# firewall-cmd --reload</code>

3. Configure Apache server

Edit

httpd.conf

to load proxy modules and enable PHP handling:

<code># Enable proxy modules
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
Include conf/extra/httpd-vhosts.conf
# Add PHP MIME types
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule></code>

Virtual host configuration (replace IP and paths as needed):

<code>&lt;VirtualHost *:80&gt;
    ServerAdmin [email protected]
    DocumentRoot "/var/www/html"
    ServerName www.test.com
    ErrorLog "logs/test-error_log"
    CustomLog "logs/test-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://192.168.20.5:9000/var/www/html/$1
    &lt;Directory "/var/www/html"&gt;
        Options FollowSymLinks
        AllowOverride None
        Require all granted
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;</code>

Ensure the document root matches the

DocumentRoot

path.

4. Test LAMP environment

<code># Create test pages
[root@php ~]# cat > /var/www/html/index.php <<'EOF'
<?php phpinfo(); ?>
EOF
[root@php ~]# cat > /var/www/html/test.php <<'EOF'
<?php
$link = mysqli_connect('192.168.20.6','lvjz','pwd@123');
if($link) echo "Database connection successful!"; else echo "Connection failed";
mysqli_close($link);
?>
EOF</code>

5. Add MySQL user for remote access

<code># On MySQL server
[root@localhost src]# mysql -uroot -p
mysql> create database bbs;
mysql> grant all on bbs.* to [email protected] identified by 'pwd@123';</code>

Access

http://www.test.com

and

http://www.test.com/test.php

to verify Apache, PHP, and MySQL work together.

Web site stress testing

Load testing reveals performance bottlenecks. Common tools include

ab

,

http_load

,

webbench

, and

siege

. This guide uses ApacheBench (

ab

).

1. ab principle

ab

creates multiple concurrent threads to simulate many users requesting a URL, measuring throughput, latency, and error rates.

2. Install ab

<code># If Apache is installed from source
/usr/local/httpd-2.4.23/bin/ab
# If installed via yum
/usr/bin/ab
# Or install the tools package
yum -y install httpd-tools</code>

3. Run a basic test

<code># Test a static page with 500 concurrent users, 1000 total requests
ab -c 500 -n 1000 127.0.0.1/index.html</code>

Sample output shows requests per second, time per request, and transfer rate.

4. Important performance metrics

Requests per second – throughput under a given concurrency.

Concurrency level – number of simultaneous users.

Time per request – average time a single user waits.

Transfer rate – data transferred per second.

Deploy PHP acceleration with XCache

1. Install XCache

<code># Extract source and build
[root@php ~]# tar zxf xcache-3.2.0.tar.gz -C /usr/src
[root@php ~]# cd /usr/src/xcache-3.2.0
[root@php xcache-3.2.0]# /usr/local/php5.6/bin/phpize
[root@php xcache-3.2.0]# ./configure --enable-xcache --enable-xcache-coverager \
    --enable-xcache-optimizer --with-php-config=/usr/local/php5.6/bin/php-config && make && make install
# Note the installed extension path, e.g.
/usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/</code>

2. Create cache file and set permissions

<code># Create cache directory and give write permission
[root@php ~]# touch /tmp/xcache
[root@php ~]# chmod 777 /tmp/xcache</code>

3. Deploy XCache admin interface

<code># Copy admin web files
[root@php xcache-3.2.0]# cp -r htdocs/ /var/www/html/xcache</code>

4. Configure PHP to load XCache

<code># Edit php.ini
[xcache-common]
extension = /usr/local/php5.6/lib/php/extensions/no-debug-zts-20131226/xcache.so
[xcache.admin]
xcache.admin.enable_auth = Off
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 60M
xcache.count = 1
xcache.slots = 8K
xcache.ttl = 0
xcache.gc_interval = 0
xcache.var_size = 64M
xcache.var_count = 1
xcache.var_slots = 8K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/tmp/xcache"
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = On</code>

Restart php‑fpm and mount the web root via NFS if needed.

Deploy a Discuz BBS forum

1. Upload and extract source

<code># On PHP server
[root@php ~]# unzip Discuz_7.0.0_FULL_SC_UTF8.zip
[root@php Discuz_7.0.0_FULL_SC_UTF8]# cp -r upload/ /var/www/html/bbs
[root@php ~]# chmod -R 777 /var/www/html/bbs</code>

2. Adjust PHP configuration

<code># Enable short tags
[root@php ~]# vim /etc/php.ini
short_open_tag = On</code>

Restart php‑fpm, then access

http://www.test.com/bbs/install

to complete the web installer.

All steps above provide a complete LAMP deployment with FastCGI, performance testing, PHP caching, and a functional BBS application.

PHPApacheXCachePerformanceTestingFastCGILAMPBBS
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.