Ubuntu: Install Apache, PHP, MySQL, SASS, Bower and PhpStorm for local development

Whenever I need to set up a Linux machine or VM for local PHP development I either recall what I need to do from memory or cobble together what I need from the web, years ago it was very simple, Apache, MySQL and PHP, that is no longer the case. These days a simple setup could be Apache, MySQL, PHP, Git, Node, Bower, Ruby and SASS. Rather than have to recall from memory again I decided to document it when I installed Ubuntu on my laptop.

After the steps below the following will be installed and configured.

  • Apache, two sites, one for a Bootstrap HTML site, the other for a site using Zend Framework 1
  • MySQL
  • PHP
  • Git
  • Bower, via Node
  • SASS, via Ruby
  • And just for good measure PhpStorm

Apache

We need to install Apache and configure two websites, one will be a simple PHP website and the other will be include rewrites for Zend Framework 1. The sites are going to be created in /var/www/html but we will create symbolic links in our Documents folder that point to the directories.

Install Apache

$ sudo apt-get install apache2

Configure Apache

Create directories for sites and set permissions, replace site1 and site2 with whatever names you want to use for your sites, in my case dlayer and site.

$ sudo mkdir –p /var/www/html/site1
$ sudo mkdir –p /var/www/html/site2
$ sudo chown –R $USER:$USER /var/www/html/site1
$ sudo chown –R $USER:$USER /var/www/html/site2
$ sudo chown -R 755 /var/www/html

Create conf files for the new sites, as above replace site1 and site2 with whatever you used previously.

$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/site1.conf
$ sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/site2.conf

Edit the conf files

$ sudo gedit /etc/apache2/sites-available/site1.conf

You need to set ServerName and update DocumentRoot, in my case for site1 which is a Zend Framework site I have the below.

DocumentRoot /var/www/html/dlayer/public
ServerName dlayer.dev

Because this site is a Zend Framework base website we need to add in the rewrite rules, the below needs to be added, I add it just before the closing VirtualHost tag.

<Location />
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} -s [OR]
   RewriteCond %{REQUEST_FILENAME} -l [OR]
   RewriteCond %{REQUEST_FILENAME} -d
   RewriteRule ^.*$ - [NC,L]
   RewriteRule ^.*$ /index.php [NC,L]
</Location>

Set the ServerName and update the DocumentRoot for the second site, my second site is a simple Bootstrap based site, the settings are as below.

$ sudo gedit /etc/apache2/sites-available/site1.conf
DocumentRoot /var/www/html/site
ServerName site.dev

We can now enable the sites and disable the default site

$ sudo a2dissite 000-default.conf
$ sudo a2ensite site1.conf
$ sudo a2ensite site2.conf

Enable the rewrite module and restart Apache

$ sudo a2enmod rewrite
$ sudo service apache2 restart

We can update our host files so we can reach the sites

$ sudo gedit /etc/hosts

Add the ServerNames you defined in the conf files, in my case I added the below

127.0.0.1    dlayer.dev
127.0.0.1    site.dev

Create the symbolic links to each of the sites, you can the point your IDE or editor at you projects folder rather than /var/www/html/…., replace site1 and site2 with whatever directory names you created in the first step and Site1 and Site2 with whatever you want to directory names to be in your projects directory.

$ sudo ln –s /var/www/html/site1 ~/Documents/Projects/Site1
$ sudo ln –s /var/www/html/site2 ~/Documents/Projects/Site2

MySQL

Install MySQL and MySQL Workbench, if you don’t want to use MySQL workbench simply doesn’t include it in the install command

$ sudo apt-get install mysql-server mysql-workbench

Follow all the prompts, make sure to set a password for the root user, if you have problems copying a password from your password manager into the password field just press return at the prompts setting the password to nothing and update the password afterwards following the below steps.

$ mysql –u root –p
$ use mysql;
$ UPDATE user SET Password=PASSWORD('PASSWORD you want to use') WHERE User='root';
$ flush privileges;
$ quit;

PHP

Install PHP, we are also going to include the GD library and the MySQL PDO driver.

$ sudo apt-get install php5 libapache2-mod-php5 php5-gd php5-mysql

Git

Install Git and set your name and email address

$ sudo apt-get install git
$ git config --global user.name "Your Name"
$ git config --global user.email "Your email"

If you need to generate a SSH key for GitHub check their website or execute the below.

$ ssh-keygen –t rsa –b 4096 –C "Your Email"
$ ssh-add ~/.ssh/id_rsa

To add the key to your account do the below

$ sudo apt-get install xclip
$ xclip -sel clip < ~/.ssh/id_rsa.pub
$ copy the contents of the clipboard to the relevant section in your GitHub profile settings

Bower

Install Bower

$ sudo apt-get install npm
$ sudo npm install –g bower
If the above doesn't work enter the below and try again
$ sudo ln –s /usr/bin/nodejs /usr/bin/node

SASS

Install SASS

$ sudo apt-get install ruby
$ gem install sass

PhpStorm

On my Linux machines I use PhpStorm, I have used PHPed on my Windows machines for the last 12 years but can see myself moving to PhpStorm on both platforms if only for consistency.

Download PhpStorm and unpack

$ tar –xvf [package name]

Move it install /opt and execute the shell script

$ sudo mv [Directory to move] /opt
$ cd /opt/[PhpStorm directory/bin
$ ./phpstorm.sh

You should now have a functional development server and IDE, checkout your sites into your Project directories and start coding,

Dlayer – Open Source

As of the 10th August Dlayer is now an Open Source project, I’ve been thinking through my options for a long time and it just made sense, below is an extract from the new Dlayer website with my two core reasons.

Development began in 2008, up until August 2015 Dlayer was a closed project that I worked on single handled, I took the decision to Open Source Dlayer for the reasons listed below:

I want Dlayer to succeed, to do that it needs to be out there, an app that never ships is no good to anyone.

I want to build up a community around Dlayer and now that I have a solid base in place I can let the community have a say in where the app goes next, I obviously have my own plans but would love to hear from others.

I’m still in the early stages of officially releasing Dlayer as an Open Source project, Dlayer was both an app and a website, I need to separate the two, I’m almost there with the new web site, once that is ready I can start on stripping the redundant parts out of Dlayer.

ZF1 Lib updates

I’ve updated my ZF1 lib site.

  • Added a simple pager view helper.
  • Updated the image resizer and image cropper classes including new examples.
  • Added a simple HTML table view helper.
  • Added a Bootstrap badge view helper.
  • Updated the Bootstrap nav view helper, one fix, one new feature.
  • Added a Bootstrap progress bar view helper.

GitHub profile and new sample site

I’ve been working on one of my public GitHub repos since Monday, I’ve still lots to do but there are a few worthwhile updates so I though I would mention them here.

  • I’ve renamed the repo, now much more obvious it is a collection of Zend framework 1 view helpers, action helpers and utility classes.
  • I’ve updated the design of the included sample site, now a simple Bootstrap based site.
  • I’ve added a Bootstrap glyphicon view helper
  • I’ve added a Bootstrap label view helper
  • I’ve added a Bootstrap nav component view helper
  • The sample site is available online at zf1.deanblackborough.com

There is still lots of work to do, I’m hoping to be done by Sunday but we will see.

  • The original view helper and utility classes haven’t been updated
  • I need to put in place a system to ensure I work on the site more often then twice a year
  • I’ve additional view helpers, action helpers and utility classes to add.
  • Need to create a ZF2 version of site.

Languishing repo

I’m going to take a short break from Dlayer on the 6th July to update my Zend repo on GitHub, I’m hoping it will be less than a week.

I will be adding a couple of extra utility classes, sorting out several issues with the current classes and adding a few bootstrap based view helpers.

A sub domain will be added to this site to host the example site.

My main project reaches milestone two

This post was originally posted on G3D Development, I’m cross posting it here because it is just as much a personal post as it is a work related post, I’m proud to have reached milestone two, Dlayer has been a big part of my life for seven years.

Original post:

I started Dlayer in 2008, so much has changed in the last seven years, the internet as a whole, mobile apps and devices, web browsers and my life. I have been married for four years and now have a two year old running around the house causing mayhem, two things that I never expected to happen seven years ago.

There are however two things that have remained constant, the first being my determination to complete the Dlayer alpha and the second being the milestones I set to track the development of Dlayer.

I set five major milestones for Dlayer in 2008, I needed five markers by which I could measure my progress, seven years is a long time, an eternity. On the 26th May 2015 at 12:08 with release v0.75 the second milestone was reached.

It has not taken seven years to get to this point, if you check the ‘History’ page on Dlayer.com or G3D Development you will be able to see that development on the current version didn’t start until 2010. Five years is still a long time but as I have written before, I’m working on this project in my own time at my own cost, under those terms finding development time can be very difficult, especially with a young child.

It will not take two years to hit the next milestone, that I can guarantee, the tasks for the third milestone are all in my short term development plan and according to my planning tool it should be reached within the next four or five iterations assuming my design is solid, obviously I am not going to give a specific timeframe here, anytime you set a date…well, you know what happens.

Listed below are the five major milestones for Dlayer, I don’t know what is going to happen once milestone five is reached, I can only hope, I do however have a suspicion that before anything else, my wife will order me to take a break.

1st Milestone (1st Feb 2014): Modules communicating.

There are many modules, or designers in Dlayer, v0.12 was the first time that more than two of the designers were communicating with each other. A content page is based upon a template created in the Template designer and forms can be imported from the Form builder into the Content manager as content items.

2nd Milestone (May 26th 2015): Images

Although it is possible to create a very nice looking focused web site that does not use any images it is rare, in my opinion, images are a necessity on the web. With v0.75 images became a reality, the basics of an Image library are in place and images can be inserted as simple content items in the Content manager.

3rd Milestone: Dynamic content (Form builder and Simple widgets)

Data, data, data…..this will be the point at which parts of Dlayer consume user data, a major stepping stone to milestone five.

4th Milestone: Simple web site

Dlayer isn’t very capable if it can’t easily link pages together to create a web site.

5th Milestone: Complex widgets

Almost anything is possible with complex widgets.

Imminent return to contracting

I’ve taken the majority of the last two years off work to help my wife raise our new son and also work on my own project, Dlayer.com.

Dlayer is not yet ready for promotion but it has improved massively between July 2013 and today, I would have loved to get more done in the time I had but how does the Lennon quote go, “Life is what happens while you are making other plans”.

When CodeSpaces went out of business, like a lot of other people, I lost some stuff, in my case it was just the SVN history for Dlayer but it was still data that I valued and because of the loss I can only look back at Dlayer’s near past.

When I return to work I am going to add a sub domain to Dlayer.com showing  the before and now, mainly for my own purposes but if interested people can see how much it has evolved over time whilst still being very recognisable as Dlayer.

At the moment I am not sure how far back I can go, hopefully two or three years, I have a year of history on GitHub and I made manual backups occasionally by doing an SVN export.

I always enjoy going back to contracting, meeting new people, picking up new ideas, tackling a new problem and generally just working with peers, always something new to learn and you never know where it will come from.