This page is a quick howto to setting up a PHP/MySQL development environment using Debian Unstable. This may be the same as easyPHP that is available for the other OS-like program and a little lighter (but with fewer features) and better integrated with Debian than XAMMP.
While describing a file, a + at the beginning of a line means add this line and a - means remove this line.
Start by installing apache, php and mysql and prevent them from starting on boot.
# aptitude install apache2 libapache2-mod-php5 mysql-server php5-mysql
# update-rc.d -f mysql remove # update-rc.d -f apache remove
But there is a problem with those lines : when an new apache or mysql packages comes out, the upgrade script recreate the script so that both services run at startup. To really prevent them from starting, recreate the symlinks so that they are stopped at every runlevel.
# update-rc.d apache stop 0 1 2 3 4 5 6 . # update-rc.d mysql stop 0 1 2 3 4 5 6 .
Here is a basic script to start and stop the development environment.
#! /bin/sh
# lamp-dev script, used to start/stop the LAMP development environment.
#
set -e
DESC="LAMP development environment"
DAEMONS="apache mysql"
case "$1" in
start)
echo "Starting $DESC..."
;;
stop)
echo "Stopping $DESC..."
;;
restart)
echo "Restarting $DESC..."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 1
;;
esac
for daemon in $DAEMONS
do
/etc/init.d/$daemon $1
done
exit 0
But it would be nice to avoid being root to start our servers. sudo exists for this purpose. Edit the /etc/sudoers file using the command 1) :
# visudo
And add the following lines to the file :
+ User_Alias WEB_DEVELOPPERS = niol + Cmnd_Alias LAMP_DEV = /usr/local/bin/lamp-dev + WEB_DEVELOPPERS ALL = NOPASSWD: LAMP_DEV
That's it. Now you should be able to start and stop your LAMP development environment with the following commands.
$ sudo lamp-dev start Starting LAMP development environment... Starting web server: apache. Starting MySQL database server: mysqld. Checking for crashed MySQL tables in the background. $ sudo lamp-dev stop Stopping LAMP development environment... Stopping web server: apache. Stopping MySQL database server: mysqld.
You may now restrict apache2 to listen only on the local interface. For this purpose, change the /etc/apache/ports file.
- Listen 80 + Listen 127.0.0.1:80
Debian makes it not handy to change the DocumentRoot directive (to change the root directory of your server), so prefer symlinks. And the AllowOverride directive of the Directory [your_doc_root] section to be able to use .htaccess files.
/usr/share/doc/mysql-server/README.Debian says very interesting things. You need to change the mysql root password. Debian provides a script to do this :
# mysqladmin -u root password 'your-unbreakable-password'
For ease of use, I recommand phpmyadmin.
# aptitude install phpmyadmin
To avoid breaking stuff, I recommand to create a least privileged account to use mysql with php. phpmyadmin makes this easy.
When you code, it's easier to have all error displayed. I also like notices to be displayed. So I changed /etc/php4/apache2/php.ini :
- error_reporting = E_ALL & ~E_NOTICE + error_reporting = E_ALL
This is not a production server, so you do not need much logging. You may edit /etc/logrotate.d/apache :
- rotate 52 + rotate 1
One week should be enough to debug your scripts… You may also edit /etc/logrotate.d/mysql and change the same line.
$EDITOR environment variable to know which editor to use