setting up a local php/mysql server for web development

Wednesday, 18 November 2009 5:07 pm by noel
posted in tech | tags: , , , ,

for php development i use a local php/mysql web server to make dev work a bit faster. these are the steps we followed for a workstation running linux.

download xampp from apache friends. the version available was 1.7.2.

extract the downloaded archive with:

sudo tar xvfz xampp-linux-1.7.2.tar.gz -C /opt

note: if you have xampp already installed, the above command will overwrite it. careful.

xampp is now installed in /opt/lampp

to start xampp:

sudo /opt/lampp/lampp start

you should see something like this:

Starting XAMPP for Linux 1.7.2...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.

which means the server is ready. i don’t need an ftp server for dev work so i decided to stop proftpd:

sudo /opt/lampp/lampp stopftp

note: issuing the above command will deactivate the proftpd server permanently–it will not start when you start xampp. see the command cheatsheet somewhere below to find out how to reactivate it.

to test our setup fire up your favorite browser and type:

http://localhost

you should see something like this:

xamppyou’ll be able to see the status of the installed components, the status of the security of the system, links to documentation and most importantly, detailed information about the server system via phpinfo() as well as database administration panels–phpmyadmin and phpsqliteadmin.

at this point, we have an apache webserver running with php and mysql support.

to stop xampp:

sudo /opt/lampp/lampp stop

other available parameters for /opt/lampp/lampp
start starts xampp
stop stops xampp
restart Stops and starts XAMPP.
startapache Starts only the Apache.
startssl Starts the Apache SSL support. This command activates the SSL support permanently, e.g. if you restarts XAMPP in the future SSL will stay activated.
startmysql Starts only the MySQL database.
startftp Starts the ProFTPD server. Via FTP you can upload files for your web server (user “nobody”, password “lampp”). This command activates the ProFTPD permanently, e.g. if you restarts XAMPP in the future FTP will stay activated.
stopapache Stops the Apache.
stopssl Stops the Apache SSL support. This command deactivates the SSL support permanently, e.g. if you restarts XAMPP in the future SSL will stay deactivated.
stopmysql Stops the MySQL database.
stopftp Stops the ProFTPD server. This command deactivates the ProFTPD permanently, e.g. if you restarts XAMPP in the future FTP will stay deactivated.
security Starts a small security check program.

and finally, to uninstall xampp:

sudo rm -rf /opt/lampp

warning: this type of server setup is not secure and is not designed for production systems. this server is meant to be part of a web development system accessible only within our intranet which is protected by a dedicated linux-based firewall. don’t be stupid and connect this system directly to the internet.

setting up xdebug

xampp does not come with xdebug so we have to install it separately.

first, install the build-essential package to be used in building xdebug from source:

sudo apt-get update
sudo apt-get install build-essential autoconf

next, we download the development package for the xampp version we are using. in this case its version 1.7.2

sudo tar xvfz xampp-linux-devel-1.7.2.tar.gz -C /opt

then we get to build xdebug:

wget http://xdebug.org/files/xdebug-2.0.5.tgz
tar xzf xdebug-2.0.5.tgz
cd xdebug-2.0.5/
/opt/lampp/bin/phpize
./configure --with-php-config=/opt/lampp/bin/php-config
make
sudo make install

in the last part of the output, you will see something like:

Installing shared extensions: /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/

take note of the directory where the shared extensions are installed. we will need that later.

now, create a subdirectory under /opt/lampp/tmp folder to hold the files generated by xdebug:

sudo mkdir /opt/lampp/tmp/xdebug
sudo chmod a+rwx -R /opt/lampp/tmp/xdebug

configuring xdebug

for xdebug to work with php we have to edit our php.ini file (/opt/lamp/etc/php.ini)

look for a line with “implicit flush” and set it to look like:

implicit flush = On

then add the following lines at the end:

;xDebug Configuration starts

zend_extension = /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so

xdebug.profiler_output_dir = "/tmp/xdebug/"
xdebug.profiler_enable = On
xdebug.remote_enable=On
xdebug.remote_host="localhost"
xdebug.remote_port=10000
xdebug.remote_handler="dbgp"

;xDebug Configuration ends

please note that the path of the zend_extension is the same one we noted earlier.

to check if xdebug is talking to php fire up the browser and go to http://localhost. you should be able to see the following somewhere in the page:

zend-xdebug

and somewhere near the bottom:

xdebug listed in phpinfo()

setting up virtual hosts in apache

virtual host is hosting several websites in one machine which is cool when you’re a developer. it certainly make things much easier and simpler than setting up a server for each website.

please make a backup of the files you’re going to edit.

sudo gedit /opt/lampp/etc/extra/httpd-vhosts.conf

in /opt/lampp/etc/extra/httpd-vhosts.conf create a virtualhost entry for each server that you’re setting up. it is important that the first virtualhost entry is setup for localhost only. the rest can be for your servers.

<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   DocumentRoot /opt/lampp/htdocs
   ServerName localhost
   ServerAlias localhost
   ErrorLog logs/localhost-error_log
   CustomLog logs/localhost-access_log common
</VirtualHost>
<VirtualHost *:80>
   ServerAdmin webmaster@client1
   DocumentRoot /home/headlessspider/Public/client1
   ServerName client1
   ServerAlias client1
   ErrorLog logs/client1-error_log
   CustomLog logs/client1-access_log common
</VirtualHost>
 

in httpd.conf

sudo gedit /opt/lamp/etc/httpd.conf

look for the like containing “httpd-vhosts” and uncomment it–erase the “#” at the start of the line.

in your hosts file

sudo gedit /etc/hosts

edit the line containing 127.0.0.1  localhost and add the name of the additional server so the line would look like:

127.0.0.1   localhost   client1

restart xampp

sudo /opt/lampp/lampp restart

and you should be ready to go.

links / sources:
apache friends / xampp
joomla documentation

related posts (maybe)

leave a reply