Following these instructions will get you a Debian based PHP/MySQL development server set-up with the ability to have multiple developer sandboxes that are accessible from a remote machine on the local network, using Samba.
Time needed < 1hr
Install operating system
If you are following these instructions verbatim then build your machine from a Debian netinst CD. Get networking going and make sure your /etc/apt.d/sources points to a local mirror. FYI I’ve set the server to use DHCP and told my DHCP server to assign it a fixed lease, in this case (192.168.2.110).
install some absolute basics:
apt-get install bzip2 ssh vim
apt-get -y --force-yes apache2 apache2-utils apache2-threaded-dev
I always compile PHP and MySQL from source so I can get whatever is new. As this is a very basic debian install I need a few things before I can start compiling:
apt-get -y --force-yes install gcc g++ make autoconf automake
First Install a MySQL dependency:
apt-get install libncurses5-dev
Get the source:
cd && mkdir -p build/src && cd build/src
tar -zxvf src/mysql-5.0.27.tar.gz
Configure and build:
CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors \
-fno-exceptions -fno-rtti" ./configure \
--prefix=/usr/local/mysql --enable-assembler \
make && make install
Make it start on boot up automatically:
cp support-files/mysql.server /etc/init.d/mysqld
chmod 0755 /etc/init.d/mysqld
update-rc.d mysqld start 75 2 3 4 5 .
Do some simple configuration:
useradd -g mysql mysql
cp support-files/my-medium.cnf /etc/my.cnf
chown -R mysql .
chgrp -R mysql .
chown -R root .
chown -R mysql var
This server is only for development so I turn off binary logging to save building up massive log files. In /etc/my.conf comment out this line so it look like:
Compile and install PHP
First install some PHP dependencies:
apt-get install -y --force-yes flex libssl0.9.7 openssl libcurl3-dev libjpeg62-dev libgd2-xpm-dev libxml2-dev libmysqlclient15-dev
get the source:
tar -jxvf src/php-5.2.1.tar.bz2
Configure and build:
./configure --with-layout=GNU --with-pear=/usr/share/php --enable-track-vars \
--enable-force-cgi-redirect --with-openssl=shared,/usr --with-zlib \
--with-exec-dir=/usr/lib/php/libexec --prefix=/usr --with-apxs2=/usr/bin/apxs2 \
--with-regex=php --with-config-file-path=/etc/php --with-curl=shared,/usr \
--with-gd --with-zlib-dir=/usr --with-jpeg-dir=shared,/usr \
--with-png-dir=shared,/usr --with-mysql=/usr --with-mysql-sock=/tmp/mysql.sock
Normally we’d ‘make install’ now, but this will break as httpd.conf is blank these days with the Apache 2 package. To trick the PHP installer that things are OK we’re going to add a dummy LoadModule line to httpd.conf. (I appreciate that this is a bit of a hack and slightly magic but as it’s a dev server for PHP then I can live with it)
cd /etc/apache2(the first line break is important)
#LoadModule foo_module /usr/lib/apache2/modules/foo.so" > /etc/apache2/httpd.conf
Now we can carry on:
..and copy the standard php.ini to the right place:
mkdir /etc/php && cp php.ini-dist /etc/php/php.ini
Then we configure Apache a bit more to make PHP work:
echo "AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps" > /etc/apache2/conf.d/php
Check it’s working:
echo "<?php phpinfo(); ?>" > /var/www/phpinfo.php
On the phpinfo screen (got to in my case by going to http://192.168.2.110/phpinfo.php) I check to see whether php.ini has been picked up, that MySQL is there plus other modules I normally have compiled in. Hmm I notice Curl is not loaded….
A quick check of /usr/lib/php/20060613-zts shows me that curl.so is there so I change extension_dir as follows:
extension_dir = "/usr/lib/php/20060613-zts"
and add the line:
Whilst I’m there, make sure we get to see errors and warnings:
error_reporting = E_ALL
Restart Apache and Curl is loaded now.
Ok so we now have a working web server but we need to be able to easily write files to the document root AND we want multiple developer sandboxes.
apt-get -y --force-yes install samba
Now configure it by editing /etc/samba/smb.conf, I add:
comment = Home Directory
browseable = no
read only = no
writeable = yes
available = yes
Add a samba user, making the user name & password the same as the system user name (and ideally the same as the host user name) this makes connecting to the shares from the host a piece of cake as one does not need to specify a user name/password then. For the record it is possible to make Samba’s and the system password automatically update when either is changed but I’ve never got it to work and it’s not really a big deal to change a few passwords now and again, so the following suffices:
smbpasswd -a bealers
If you are on Windows to check that it worked open up Windows explorer and enter \\192.168.2.110 into the address bar; you should see your home directory. Assuming that you can write to it then you can map a drive and your job is nearly done. The final job is to configure Apache to work from your home directory. I simply chrgp my home dir to www-data (the Apache user) and create a new virtual host container:
chgrp /home/bealers www-data
mkdir ~bealers/www && chown bealers.bealers www
echo "<VirtualHost *>
Options FollowSymLinks Indexes MultiViews
CustomLog /var/log/apache2/bealers.access.log combined
</VirtualHost>" > /etc/apache2/sites-available/dev.bealers
ln -s ../sites-available/dev.bealers
Assuming that you’ve internal DNS (or a horribly long hosts file) make sure that dev.bealers resolves to 192.168.2.110. Now popping http://dev.bealers into my browser gives me an (empty) directory listing for /home/bealers/www/, which is right.
You can now either develop direct to the dev server or copy and paste the files over when you need to.
In summary: onto a very basic Debian we installed Apache as a Debian package and MySQL/PHP were compiled from source; that gave us our web-server. As we want to easily save our changes and view them immediately without having to faff with FTP or SSH we write directly to the web root of our own sandbox on the server, to facilitate this we use Samba (although there are other options such as NFS).
This page is updated when something notably changes. Last update April 07 when Etch became stable.