Wednesday, February 7, 2007

Setting up a PHP / MySQL development server


This is a Quick Walkthrough, or whatever of my development server install. Someone might find it useful. Sometime. I hope. This is all The Way I Like Ittm


The initial requirements for my development server this time was; MySQL, Web server, CVS, PHP 5.2 and memcached.


Install Fedora Core 6, packages and partitions as you like. I use /data and /logs partitions, as I have loads of disk and small projects. For software packages, I leave out just about everything except for firewall and emacs (I do love emacs!). Every developer gets his own user.


Log in as root.



Install MySQL:

root@dev# yum install -y mysql-server mysql-devel
(edit config in /etc/my.cnf to your needs)
root@dev# service mysql start


Dump sendmail (just don't like it) for postfix:
root@dev# yum remove sendmail
root@dev# yum install -y postfix

Install packages required for webserver (I use lighttpd, it rocks)
root@dev# yum install -y lighttpd lighttpd-fastcgi

Libraries for memcached:
root@dev# yum install -y libevent libevent-devel

Download and untar memcached and PHP memcache extension:
root@dev# wget http://www.danga.com/memcached/dist/memcached-1.2.1.tar.gz
root@dev# wget http://pecl.php.net/get/memcache-2.1.0.tgz
root@dev# tar xfz memcached-1.2.1.tar.gz
root@dev# tar xfz memcache-2.1.0.tar.gz

Build and install memcached:
root@dev# cd memcached-1.2.1/; ./configure; make install

Install compilers and libraries for PHP (I need freetype, xml & curl, you might not):
root@dev# yum install -y gcc gcc-c++ flex libjpeg libjpeg-devel \
libpng libpng-devel mysql-devel libxml2-devel \
curl-devel freetype-devel

Configure and build PHP (your configure options may vary):
root@dev# cd php-5.2.0
root@dev# ./configure --enable-fastcgi --enable-discard-path \
--enable-force-redirect --with-mysql --with-gd \
--with-curl --enable-gd-native-ttf \
--without-sqlite --with-memcache=../memcache-2.0.1 \
--enable-sockets --with-libjpeg-dir=/usr/lib \
--with-png-dir=/usr/lib --with-zlib-dir=/usr/lib
root@dev# make install

Build and install memcache PHP extension:
root@dev# yum install -y autoconf
root@dev# cd memcache-2.1.0/
root@dev# phpize
root@dev# ./configure
root@dev# make install

Add to / edit /usr/local/lib/php.ini:
extension_dir=/usr/local/lib/php/extensions/no-debug-non-zts-20060613/
extension="memcache.so"

Edit /usr/local/lighttpd/conf/lighttpd.conf to add PHP as FastCGI and user dir support.
Also make sure mod_userdir and mod_fastcgi is enabled in server.modules:

userdir.path = "public_html"

fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/local/bin/php",
"socket" => "/tmp/php.socket",
"max-procs" => 2,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "8",
"PHP_FCGI_MAX_REQUESTS" => "10000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
)))

Open firewall hole for HTTP. Edit /etc/sysconfig/iptables, and add (inbetween the other RH-Firewall-1-INPUT rules):
-A RH-Firewall-1-INPUT -p tcp --dport 80 -j ACCEPT
root@dev# service iptables restart


Then, Fire Up The Webserver!
root@dev# service lighttpd start


Problems? Back-track, read logs and use strace if you need to.

Installing CVS is a cake:
root@dev# yum install -y cvs

For setting up repositories and such, I recommend the CVS Book, just Google it.

1 comment:

  1. With an excellent team of 120+ experienced PHP developers in India , CATT Ltd has successfully completed numerous PHP solutions like E-Commerce shopping carts with content management system, CRM Solutions, Community tools Web Calendars, Chat software and Discussion forum etc.

    ReplyDelete