Install apache and php for http research

I need a super clean apache and forward all PHP requests to a independent php-cgi process which host by a specific port

1. Install Apache

Mac

In ubuntu, no need to build apache from source, just “sudo apt-get install apache2”

git clone https://github.com/apache/apr.git
cd apr
./buildconf
./configure --prefix=/Users/peter/Downloads/apr-install
make -j
make install
git clone https://github.com/apache/httpd.git
cd httpd
./configure --prefix=/Users/peter/Downloads/apache-install --with-apr=/Users/peter/Downloads/apr-install
make -j
make install

Linux

git clone https://github.com/apache/httpd.git
cd httpd
./buildconf
./configure --prefix=/home/peter/Downloads/apache-install
make -j
make install

2. Install PHP

Mac

git clone https://github.com/php/php-src.git
./buildconf
./configure --prefix=/Users/peter/Downloads/php-install --with-openssl --with-iconv=$(brew --prefix libiconv) --with-zlib --with-mysqli
make -j
make install

Linux

git clone https://github.com/php/php-src.git
./buildconf
./configure --with-openssl --with-mysqli --with-zlib --prefix=/home/peter/Downloads/php-install
make -j
make install

if you meet this error “configure: error: re2c 1.0.3 or newer is required to generate PHP lexers.”, do “sudo apt-get install re2c”

3. Setup Apache

  1. sudo apt-get install apache2
  2. sudo a2enmod proxy_http
  3. edit “/etc/apache2/mods-available/proxy.load”, add “LoadModule proxy_fcgi_module /usr/lib/apache2/modules/mod_proxy_fcgi.so”
  4. edit “/etc/apache2/sites-enabled/000-default.conf”, add these
  5. edit “/home/peter/Downloads/apache-install/conf/httpd.conf”
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

<Files ~ "\.(php|phtml)$">
    SetHandler "proxy:fcgi://127.0.0.1:1992//./"
    ProxyFCGIBackendType GENERIC
</Files>
  1. Enable these
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

4. Run

/home/peter/Downloads/php-install/bin/php-cgi -b 1992

5. If you see this WordPress error, add this to debug

ob_flush();
ob_start();
var_dump($error);
$message = __( '3. There has been a critical error on this website.<pre>'.ob_get_flush().'</pre>');

6. Memory exhausted

add “memory_limit = 1020M” to php.ini

7. If you see this Phpmyadmin error, do this

Edit /Users/peter/Downloads/php-install/lib/php.ini, add “output_buffering = 100M”

If you see this error, do these

Edit /Users/peter/Downloads/php-install/lib/php.ini, add “mysqli.default_socket = /var/run/mysqld/mysqld.sock”

If you see “Getting error mysqli::real_connect(): (HY000/2002): No such file or directory”, do these

Change localhost to 127.0.0.1 in config.inc.php

$cfg['Servers'][$i]['host'] = '127.0.0.1';

Use tcpdump to capture fast-cgi packages

sudo tcpdump -i any -nn -Xx port 1992    <-- dump hex
sudo tcpdump -i any -nn -A port 1992    <-- dump ascii

Using wireshark to capture fastcgi

tcp.port eq 1992 and tcp.len>100

Leave a Reply

Your email address will not be published. Required fields are marked *