What do you need?
Before you can start creating your own environment there are some things you should know. When you are a front-end developer it is more likely you need a WAMP installation on a Windows machine, because you need Internet Explorer as it’s still the most used browser. When your work is mainly on the backend I recomment to install a Linux distribution on your machine and create a LAMP server instead.
It’s not really necessary but i can recommend to let your environment match your live server as much possible. Therefore you need to find out what your live server is running on. In most cases the configuration is a Linux system with Apache2, PHP 5+ and MySQL 5+. When you create your development environment on Windows I can recommend to use WampServer, because it’s possible to run different versions of PHP and MySQL. It has a nice use interface that helps you to install or configure your WAMP installation, so that concludes the Windows part for now.
How to create a LAMP installation on Ubuntu
When you have a Linux based system, it is a bit harder to create you own development environment. First you can use the synaptic package manager and find and install the packages you need or you can use a terminal and use the following commands:
sudo su
apt-get install apache2
echo 'ServerName localhost' >> /etc/apache2/conf.d/fqdn
apt-get install php5 libapache2-mod-php5
apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
apt-get install phpmyadmin
/etc/init.d/apache2 reload
exit
# change the owner of the location for your localhost
# sudo chown [OWNER]:[GROUP] /var/www/ -R
Configuration
Before you can start your development you should change the PHP configuration. On your WampServer you can use the GUI when you have a LAMP server installed, the configuration is located in /etc/php5/apache2/php.ini. You can modify the configuration to match your live server with one exception. On your live server the error_reporting and display_errors are probably set off. These settings need to change before you can start developing so you can debug your applications. Change these settings as follows:
sudo nano /etc/php5/apache2/php.ini
error_reporting = E_ALL | E_STRICT
display_errors = On
Virtual hosts
When you have installed Apache2 there is a default site called localhost (127.0.0.1) configured that can be visited with any browser on your computer. When you will create multiple websites it can be handy to configure more sites. When you use WampServer new sites can be added by using the GUI. On a LAMP server the sites can be added by using the a2ensite command and removed by a2dissite. These virtual hosts will look like the one described below:
ServerName your_site.dev
DocumentRoot /var/www/path_to_your_site
Options -Indexes FollowSymLinks -MultiViews
AllowOverride All
ErrorLog /var/log/apache2/error.log
You can create a virtual host by adding a file with the name of the site in /etc/apache2/sites-available and adding it by a2ensite [SITE]. Change DocumentRoot and the Directory directive to the path of the development of your new site, add it and reload apache afterwards.
sudo a2ensite your_site.dev
sudo /etc/init.d/apache2 reload
After creating a new virtual host you have to add it in the hosts file that your browser uses. On a Windows operating system this file is located in c:\WINDOWS\system32\drivers\etc\, to change this file in Ubuntu you, just use the following line: sudo nano /etc/hosts. In the hosts file there is a line that starts with 127.0.0.1 localhost, to make your fresh created site available in the browser add the site name after localhost separated by any whitespace.
That is all, now you can start developing your own sites.
Comments
One response to “Howto setup a development environment”
The article is very valuable for php developers.