Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ubuntu php development environment

#Introduction If you're a php developer on ubuntu, there comes the time where you have to install/reinstall your system. I did it already a few times and i decided to write down the steps for a typical web developer stack with php. This is for a developer machine and not for a live environment!

I hope it helps you too!

fyi @mheiniger and me started with an installer here:

#Installation stack

#Installation PHP Environment ##PHP5

sudo apt-get install php5-cli php5-common php-apc php-pear php5-xdebug php5-curl php5 php5-dev
sudo apt-get install php5-xsl
sudo apt-get install php5-intl


sudo pear channel-update PEAR
sudo pear upgrade PEAR


sudo pear channel-discover
sudo pear install phing/phing

#Install General Environment ##git

sudo apt-get install git
git config --global color.branch auto
git config --global color.diff auto
git config --global color.status auto

#Manual on how to install ssh keys on github


sudo apt-get install memcached
sudo apt-get install php5-memcache


sudo apt-get install apache2
sudo a2enmod rewrite
sudo apt-get install libapache2-mod-php5


sudo apt-get install nginx php5-fpm

#edit listen port in /etc/php5/fpm/pool.d/www.conf
listen =

sudo /etc/init.d/php5-fpm restart
sudo service nginx restart


sudo apt-get install mysql-server
sudo apt-get install php5-mysql


sudo apt-get install sqlite3 php5-sqlite

#comment in /etc/php5/conf.d/sqlite.ini


sudo apt-get install graphicsmagick libgraphicsmagick1-dev
sudo pecl install gmagick-beta

#Create file /etc/php5/conf.d/gmagick.ini and add a line


sudo apt-get install curl

#Installation PHP QA Environment ##CodeSniffer

sudo pear install PHP_CodeSniffer


#necessary if you already have installed phpunit via apt-get
sudo apt-get remove phpunit

#install newest version of phpunit
sudo pear channel-discover
sudo pear channel-discover
sudo pear channel-discover
sudo pear update-channels
sudo pear upgrade-all
sudo pear install --alldeps phpunit/PHPUnit
sudo pear install --force --alldeps phpunit/PHPUnit

#phpunit Skeleton Generator
sudo pear config-set auto_discover 1
sudo pear install

It's getting easier now to install phpunit -> (have to check that and put it into the documentation


sudo wget -O /usr/local/bin/php-cs-fixer
sudo chmod a+x /usr/local/bin/php-cs-fixer

##PHP Storm IDE

#add line to /etc/sysctl.conf
fs.inotify.max_user_watches = 524288

#apply changes
sudo sysctl -p

#Frontend Tools ##NodeJs + Grunt + Bower

# nodejs
sudo apt-get install python-software-properties
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

sudo npm install -g grunt-cli

sudo npm install -g bower

##PNG Tools for Iconizr

# PNG Tools for Iconizr
sudo apt-get install pngcrush pngquant optipng
sudo apt-get install checkinstall
cd /tmp
tar xvf optipng-0.7.4.tar.gz
cd optipng-0.7.4
sudo checkinstall



  • Change this settings in /etc/php5/cli/php.ini for for all webservers
  • Change this settings in /etc/php5/apache2/php.ini if you have installed apache2
  • Change this settings in /etc/php5/fpm/php.ini if you have installed nginx and fpm
memory_limit = 512m
display_errors = On
html_errors = On
post_max_size = 32m
upload_max_filesize = 32m
default_charset = utf8

#Debugging with XDebug on Browser and Command line

The example is made for PHPStorm IDE with Apache2 webserver. But other IDE's or webservers should work in a similar way.

  • Ubuntu 12.04
    • Edit /etc/php5/cli/conf.d/xdebug.ini
  • Ubuntu 14.04
    • with php-fpm -> sudo ln -s /etc/php5/mods-available/xdebug.ini /etc/php5/fpm/conf.d/20-xdebug.ini
    • with apache2 -> sudo ln -s /etc/php5/mods-available/xdebug.ini /etc/php5/apache2/conf.d/20-xdebug.ini
    • with cli -> sudo ln -s /etc/php5/mods-available/xdebug.ini /etc/php5/cli/conf.d/20-xdebug.ini
    • Edit /etc/php5/mods-available/xdebug.ini


#Edit xdebug.ini
xdebug.max_nesting_level = 1000

sudo service apache2 restart

#Add to /home/<your_username>/.bashrc

#reload bash settings
source ~/.bashrc

##Debugging via Firefox

  • Firefox: Click on ‘StartXDebug Session’ Symbol on bottom right
  • PHPStorm: Click on Run->Start Listen PHP Debug Connections
  • PHPStorm: Set a breakpoint and do call via firefox browser

##Debugging via Console

  • PHPStorm: Click on Run->Start Listen PHP Debug Connections
  • Set a breakpoint and run a console command

##PHPStorm Config

#for PHPUnit Code Completion add PHPUnit path under file->settings->directories
#Usually it’s stored in 

#for PHPUnit Skeleton Generator add phpunit-skelgen under file->settings->ProjectSettings->PHP->PHPUnit->SkeletonGenerator
#Usually it's stored in


#Apache2 config example (with Symfony2 framework) Assume you want to have your project in /home/username/my_webside

# Change user/group of Apache2
# edit /etc/apache2/apache2.conf
User <username>
Group <usergroup>

#Add entry to /etc/hosts www.my_webside.lo

#Create file 

#edit file (with example config)
<VirtualHost *:80>
    ServerName  www.my_webside.lo
    DocumentRoot /home/username/my_webside/web
    ErrorLog ${APACHE_LOG_DIR}/www.my_webside.lo.error.log
    CustomLog ${APACHE_LOG_DIR}/www.my_webside.lo.access.log common

#create symbolic link to enable a site
sudo ln -s /etc/apache2/sites-available/www.my_webside.lo /etc/apache2/sites-enabled/www.my_webside.lo

#restart apache
sudo /etc/init.d/apache2 restart

#Nginx config example (with Symfony2 framework) Assume you want to have your project in /home/username/my_webside

# Change user of Nginx
# edit /etc/nginx/nginx.conf
User <username>

# Change user of php5-fpm
# edit /etc/php5/fpm/pool.d/www.conf
user = <username>
group = <group of user>

#Add entry to /etc/hosts www.my_webside.lo

#Create file 

#edit file (with example config)
server {
    listen 80;
    server_name www.my_webside.lo;

    access_log  /var/log/nginx/www.my_webside.lo.log;

    location / {
        root /home/username/my_webside/web;
        index  index.html index.htm index.php app_dev.php;
        if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css)$") {
                rewrite ^(.*) /app.php$1 last;

 location ~ \.php($|/) {
    set  $script     $uri;
    set  $path_info  "";

    if ($uri ~ "^(.+\.php)(/.+)") {
      set  $script     $1;
      set  $path_info  $2;


    include fastcgi_params;
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_param  SCRIPT_FILENAME  /home/username/my_webside/web$script;
    fastcgi_param  PATH_INFO        $path_info;


#create symbolic link to enable a site
sudo ln -s /etc/nginx/sites-available/www.my_webside.lo /etc/nginx/sites-enabled/www.my_webside.lo

#restart nginx
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php5-fpm restart
Copy link

techtourist commented Feb 28, 2013

As a N00b to PHP development, I've tried a few times to get the dev environment set up correctly. Thank you for creating this great configuration list. It is well documented and easy to follow. There are some tools I'm not familiar with, so the learning curve is high. However, just getting configuration correct is probably the biggest hurdle.

If only there was a way to script the whole thing so that a dev environment could be setup quicker. ;-)

Thanks again!

Copy link

zhangjianguo commented May 13, 2014

thanks you very much!

Copy link

pradeshc commented Aug 9, 2014

A real PHP (cough) gem.

Copy link

mannuelf commented Nov 8, 2014

Thank you sir! really appreciate this.

Copy link

thenetexperts commented Mar 4, 2015

Please change the (private) github repository link for the symfony 2 coding standards to (as the other one is outdated and wont work with current phpcs versions)

Copy link

ghost commented Jul 15, 2015

any tips on installing specific php version?

Copy link

emojiijome commented Oct 5, 2015

How I wish met this manual earlier! Thanks

Copy link

Symfomany commented Jan 9, 2016

Nice. Can you write more about NodeJS conf & for GULP Grunt BrunchJS...plz

Copy link

ankurk91 commented Jan 17, 2016

Copy link

aginanjar commented May 6, 2017


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment