10 tools for PHP developers in Ubuntu 14.04

real_programmers
To convert your Ubuntu 14.04 into a powerhouse for software development for PHP, you need to install some developer tools from the rich set of available software packages. I have made a top 10 of my favorite developer tools.

1) Install Eclipse 3.8 as a complete IDE

Altough everybody I know prefers the JetBrains IDE’s, I am still a sucker for free (as in speech) software. I think Eclipse and the various distributions of Eclipse you can download are just as good, when properly configured.

sudo apt-get install eclipse

2) Install Geany 1.23 as a lightweight IDE

I also often find myself using a lightweight IDE. After using way too much “gedit” I have recently (re)discovered “Geany” and I feel it is perfect. With the following commands you install it with a good set of plugins.

sudo apt-get install geany geany-plugins

You can find some Geany color schemes on Github that are worth installing as well.

wget https://github.com/downloads/codebrainz/geany-themes/geany-themes-1.22.2.tar.bz2
tar -xvf geany-themes-1.22.2.tar.bz2
mkdir -p ~/.config/geany/colorschemes/
cp geany-themes-1.22.2/colorschemes/* ~/.config/geany/colorschemes/
rm -Rf geany-themes-1.22.2 geany-themes-1.22.2.tar.bz2

3) Install MariaDB 5.5

MariaDB is the replacement for MySQL now that Oracle has acquired it. This is comparable to the replacement of OpenOffice with LibreOffice after Oracle got their hands on it.

sudo apt-get install mariadb-server

4) Install PostgreSQL 9.3

PostgreSQL may be the most powerful database around.

With PostgreSQL 9.2, query results can be returned as JSON data types. Combined with the new PL/V8 Javascript and PL/Coffee database programming extensions, and the optional HStore key-value store, users can now utilize PostgreSQL like a “NoSQL” document database, while retaining PostgreSQL’s reliability, flexibility and performance. (source)

I feel you should always consider using it before choosing any “NoSQL” or “documents-based” database.

sudo apt-get install postgresql pgadmin3

Do not forget to set the root (postgres) password.

sudo -u postgres psql postgres
ALTER USER postgres WITH PASSWORD '<password>';
\q

5) Install Apache 2.4 + PHP 5.5 + modules

Install Apache and the default method (mod_php) to serve the new PHP 5.5.

sudo apt-get install apache2 libapache2-mod-php5

Install PHP 5 support for MariaDB and PostgreSQL.

sudo apt-get install php5-mysql php5-pgsql

Some PHP packages for Symfony development.

sudo apt-get install php5-intl php5-sqlite

PHP packages for cURL and XDebug.

sudo apt-get install php5-curl php5-xdebug

Optional PHP packages for creating images (GD), doing geolocalization on IP address (GeoIP), encryption and Redis/Memcache caches.

sudo apt-get install php5-gd php5-geoip php5-mcrypt php5-redis php5-memcache php5-memcached

Now enable mod_rewrite and restart Apache to make sure everything is loaded.

sudo a2enmod rewrite
sudo service apache2 restart

6) Install Adminer 4

PhpMyAdmin is a very popular web-based database management tool. Adminer is a drop in replacement that beats it on almost all points. You can install the latest version of Adminer using:

sudo mkdir /usr/share/adminer
sudo wget -O /usr/share/adminer/latest.php "http://www.adminer.org/latest.php"
sudo ln -s /usr/share/adminer/latest.php /usr/share/adminer/adminer.php
echo "Alias /adminer.php /usr/share/adminer/adminer.php" | sudo tee /etc/apache2/conf-available/adminer.conf
sudo a2enconf adminer
sudo service apache2 reload

Now go here to run it: http://localhost/adminer.php

In the future you can easily update Adminer using:

sudo wget -O /usr/share/adminer/latest.php "http://www.adminer.org/latest.php"

7) Install Git

Install the Git source code versioning system:

sudo apt-get install git

Check out this great Git cheat sheet.

8) Install some compilers and build tools

With the following commands you get most common compilers and build tools.

sudo apt-get install gcc build-essential libc6-dev autoconf automake

9) Install the Microsoft fonts

There are always people that rely on the standard Microsoft fonts (like Arial). Although this is bad practice and HTML5 allows you to embed fonts, still it may solve some problems to just install these:

sudo apt-get install ttf-mscorefonts-installer

10) Upgrade your Office experience

A developer also needs to read or write some documentation or specifications. Libreoffice Writer is IMHO better than the real thing (Microsoft Word).

sudo apt-get purge gnumeric abiword
sudo apt-get install libreoffice

Feedback?

Did we miss some really important package? Let us know in the comments.

Share

Eclipse as Symfony2 IDE

In this post I will explain how to turn Eclipse in a full-featured IDE for Symfony2. The other popular MVC framework (Zend) has Zend Studio as an full-featured IDE. Zend Studio is based on Eclipse and we will show in this post how you can turn a standard Eclipse into a full-featured IDE for Symfony2. First you need to install Eclipse. It can be installed from the standard repositories in Ubuntu 12.04. A simple “sudo apt-get install eclipse” will do. Although everybody says you need Oracle Java to run Eclipse with PDT, I have no problems running it under OpenJDK. If you download the latest Eclipse from the download page, choose the “Classic” distribution.

After installing and starting Eclipse, you should install the MarketPlace. Newer distributions of Eclipse come with MarketPlace installed. You can find “Eclipse MarketPlace” under the “Help” menu. This is a software manager for Eclipse that is fast and easy to use. If you do not have it, install it by going to: “Help” > “Install new software” > “All available sites” > type “marketplace” > “Select All” > “Next” > “Finish”.

Now that MarketPlace is installed we can “shop” for some nice additions to Eclipse to make it a full featured Symfony2 IDE. The following packages should be acquired:

  • “EGit” and/or “Subversive” for Git and SVN support
  • “AnyEdit Tools” for proper whitespace handling and tab conversions
  • “PTI – PHP Tool Integration” for support of
    • CodeSniffer
    • PHP Copy Paste Detector
    • PHP Depend
    • PHPUnit
  • “Symfony Plugin” for supports of the Symfony 2.1 composer and twig templates
  • “DBViewer” plugin for database setup and queries from within Eclipse

Now you also need to install the CodeSniffer standards:

sudo apt-get install php-codesniffer
cd /usr/share/php/PHP/CodeSniffer/Standards
sudo git clone git://github.com/opensky/Symfony2-coding-standard.git Symfony2
sudo nano Symfony2/ruleset.xml

Remove the last 3 rules that start with “<rule ref=”Symfony2.Commenting” and end with “</rule>”, because somehow those dont work.

You will also have to configure some of the tools from within Eclipse before they work:

  • Subversive: After restart Choose the SVNKit version that matches the output of “svn –version” (e.g. choose SVNKit 1.3.8 for SVN 1.6.18).
  • PHP executable: Add a PHP executable for path “/usr/bin/php” choose “CLI” and “XDebug”. NB: if this fails remove the “/tmp/zend_debug/” directory if it exists.
  • PHP Tools: All pages need to point to the added PHP executable and the internal PEAR library. You also need to set the Symfony2 code style: Go to “Window” > “Preferences” > “PHP” > “Code Style” > “Formatter (PDT Tools)” and choose as “Active profile”: “Symfony [built-in]”.
  • PHP CodeSniffer: You need to set Tab width to “4” and you should add and select the Symfony2 CodeSniffer Standard (path “/usr/share/php/PHP/CodeSniffer/Standards/Symfony2”).
  • DBViewer: You need to add the path to the file “/usr/share/java/mysql-connector-java.jar” which can be installed using “sudo apt-get install libmysql-java”

NB: If you run into “The currently displayed page contains invalid values.” when trying to configure the PHP executable, you might want to run “sudo chmod -R 777 /tmp/zend_debug/”.

That’s it, enjoy your full-featured Symfony2 IDE!

Share

Free PHP IDE with PDT for Eclipse

Eclipse is an integrated development environment (IDE) with an extensible plug-in system. Most people know it as a tool to develop Java applications, but if you install plug-ins you can use it to do PHP development. There are a lot of Eclipse based IDE’s (source: wikipedia). Three IDE’s that are based on Eclipse you might know are:

Now I hear you think: “I like to develop my PHP code in gedit“. Well that is a very good choice and so is “using vim for PHP“. And if you download and install Eclipse you might get disappointed by the (lack of) features it offers out of the box. I have to admit that you either need proper instructions and/or an (un)healthy dose of perseverance to get to satisfying results.

But once you have gone that extra mile and seen how stable and fast it is (when run under Linux) I doubt you ever want to go back. At least to me the step-by-step debugger (from PDT and Xdebug) and version control support from either subversive (SVN based on SVNKit) or Egit (for GIT) are indispensable.

Without further ado, here are the instructions for a perfect Eclipse installation on Linux (tested on Ubuntu 12.04):

$ sudo apt-get install lamp-server^
- Enter a new mysql root password (twice)
$ sudo apt-get install php-pear
$ sudo pecl install xdebug
$ nano /etc/php5/apache2/conf.d/xdebug.ini
  NB: Insert the following text:
  zend_extension=/usr/lib/php5/20090626/xdebug.so
  xdebug.remote_enable=1
  xdebug.remote_handler=dbgp
  xdebug.remote_mode=req
  xdebug.remote_host=127.0.0.1
  xdebug.remote_port=9000
$ sudo service apache2 restart
$ sudo apt-get install git
$ sudo chown -R `whoami`:`whoami` /var/www
  NB: whoami should be surrounded by backticks
$ cd /var/www
$ nano test.php
  NB: Enter the following text:
  <?php
  $test = 'test';
  echo $test;
$ nano .gitignore
  NB: Insert the following text:
  .buildpath
  .project
  .settings
$ git init .
$ git add .
$ sudo apt-get install eclipse
  NB: 245 MB will be downloaded and it uses 418 MB of diskspace
- Start Applications > Development > Eclipse
- When asked for workspace settings click "do not ask this again"
- Close the "Welcome" page
- Click Help > Install new Software
- Choose "Work with": --All Available Sites--
- Enter in "type filter text": PHP
- Wait..
- Select: PHP Development Tools (PDT)
- Click Next
- Click Next
- Click I Accept
- Click Finish
- Wait..
- Click "Restart Now"
- Close the "Welcome" page
- Click Help > Install new Software
- Choose "Work with": --All Available Sites--
- Enter in "type filter text": egit
- Wait..
- Select: Eclipse EGit
- Click Next
- Click Next
- Click I Accept
- Click Finish
- Wait..
- Click "Restart Now"
- Close the "Welcome" page
- Click File > New > Project
- Choose: PHP > PHP Project
- Click Next
- Enter "Project name": "test"
- Choose "Create project from existing sources"
- Enter Directory: "/var/www"
- Click "Finish"
- When asked to change perspective choose "Yes"
- Choose Window > Preferences
- Choose: General > Web Browser
- Select: "Use external web browser"
- Choose: PHP > Debug
- Choose "PHP Debugger": "XDebug"
- Unselect "Break at first line"
- Click Ok
- Open the PHP file "test.php" from your project
- Doubleclick linenumber 2 to put a breakpoint (blue dot)
- Choose Run > Debug
- Change "Launch URL" from "http://localhost/test/test.php" to "http://127.0.0.1/test.php"
  NB: 127.0.0.1 works, localhost does not work!
- When asked to change perspective choose "Yes"
  NB: Once you are in the debug perspective a browser opens,
      you can inspect variables and step-by-step execute.
- Choose Window > Open Perspective > PHP
- Right-click your project
- Choose Team > Share Project
- Select Git
- Click Next
- Select "Use or create repository in parent folder of project"
- Click Finish
- Right-click your test.php file
- Choose Team > Commit
- Enter your username and email address and click Ok
- Type a commit message
- Click Commit
  NB: You have commited to a local repository,
      how to push git commits remote is beyond this tutorial.
- Close Eclipse

If you feel Eclipse does not start quick enough, you might try these optimizations. I noticed some speed improvements after applying them, but note that your mileage may vary.

Share