Master-Zone Blog Technical Notes

15Aug/100

PHP with Apache MPM Worker

I didn't know if this is going to work or not, but I wanted at least to try Apache MPM Worker with PHP. I started with a minimal Centos5.4 installation, installed gcc and the rest of the family, download apache2.2.16 and php-5.2.14, started the compilation and building.

Installing GCC and the rest of the family...
# yum install gcc.i386 automake17.noarch libtool.i386 m4.i386 autoconf.noarch zlib-devel.i386 openssl-devel.i386

Download and build apache2.2.16
# cd /usr/src && wget http://www.alliedquotes.com/mirrors/apache/httpd/httpd-2.2.16.tar.gz && tar xzvf httpd-2.2.16.tar.gz && cd httpd-2.2.16
# ./configure --enable-layout=CustomApache --with-mpm=worker --enable-modules='ssl deflate' --enable-mods-shared='headers rewrite' && make && make install

This is my config.layout...

<layout CustomApache>
prefix:
exec_prefix: ${prefix}/usr
bindir: ${exec_prefix}/bin
sbindir: ${exec_prefix}/sbin
libdir: ${exec_prefix}/lib/apache2/lib
libexecdir: ${exec_prefix}/lib/apache2/modules
mandir: ${exec_prefix}/share/man
sysconfdir: ${prefix}/etc/apache2
datadir: ${exec_prefix}/share/apache2
iconsdir: ${datadir}/icons
htdocsdir: ${prefix}/var/www
manualdir: ${htdocsdir}/manual
cgidir: ${prefix}/var/www/cgi-bin
includedir: ${exec_prefix}/include/apache2
localstatedir: ${prefix}/var/run
runtimedir: ${prefix}/var/run
logfiledir: ${prefix}/var/log/apache2
proxycachedir: ${prefix}/var/cache/apache2/proxy
infodir: ${exec_prefix}/share/info
installbuilddir: ${prefix}/etc/apache2/build
errordir: ${datadir}/error
</layout>

Configuring apache...

(I like to write my apache config file from scratch, so I started with a very minimal config file, minimal just to get apache up and running)

# mv /etc/apache2/httpd.conf /etc/apache2/httpd.conf.orig && vi /etc/apache2/httpd.conf

This is my httpd.conf

Listen 80
LoadModule headers_module /usr/lib/apache2/modules/mod_headers.so
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
user apache
DocumentRoot "/var/www"
ErrorLog "/var/log/apache2/error_log"

Starting apache...
# apachectl -k start

Issuing `ps xa | grep httpd` will tell you if apache is running or not.

Now it was time to compile php, I installed dev packages before compiling php...
# yum install libxml2.i386 libxml2-devel.i386 bzip2.i386 bzip2-devel.i386 bzip2-libs.i386 curl-devel.i386 curl.i386 gettext.i386 gettext-devel.i386 libc-client-devel.i386 gd-devel.i386 libmcrypt.i386 libmcrypt-devel.i386 mysql.i386 mysql-server.i386 mysql-bench.i386 mysql-devel.i386 readline-devel.i386 libtool.i386 libtool-ltdl.i386 libtool-ltdl-devel.i386

Download and build php-5.2.14...
# cd /usr/src && wget wget http://www.php.net/get/php-5.2.14.tar.gz/from/de.php.net/mirror && tar xzvf php-5.2.14.tar.gz && cd php-5.2.14
# ./configure --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib/php/modules --datadir=/usr/share/php --sysconfdir=/etc/php --with-apxs2=/usr/sbin/apxs --with-openssl --with-zlib --with-bz2 --with-curl --with-gd --with-gettext --with-imap --enable-mbstring --with-mcrypt --with-mysql --with-readline --enable-sockets --enable-soap --with-kerberos --with-imap-ssl && make && make install

Now, edit httpd.conf and add
# vi /etc/apache2/httpd.conf

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
<ifmodule dir_module>
DirectoryIndex index.php index.html
</ifmodule>
<ifmodule mime_module>
AddType application/x-httpd-php .php
</ifmodule>

And restart apache
# apachectl -k restart

VN:F [1.7.5_995]
Rating: 0.0/10 (0 votes cast)
Filed under: Linux, PHP No Comments
25Sep/092

XML using PHP

This article helps those relatively new to using XML with PHP to write a short and uncomplicated XML file using the DOM in a PHP environment.

1. Create a new XML DOMDocument

$dom = new DomDocument('1.0', 'UTF-8');

Each XML document must have 1 and only 1 root element.

2. Create root node

$root = $dom->createElement('bookmarks');
$root = $dom->appendChild($root);

3. Create child node

$user = $dom->createElement('username', $userArray['Username']);
$root->appendChild($user);

4. Output XML

$xml_string = $dom->saveXML();
echo $xml_string;

Download

VN:F [1.7.5_995]
Rating: 0.0/10 (0 votes cast)
Tagged as: , 2 Comments