How I setup my work computer

Frustrated programmer

Few weeks ago I was getting fed up with how my computer was set up. Sometimes it’s just the time … time to wipe it clean and give it a clean slate.

But that can cause problems. I have so many configurations on my computer, due to the fact that I’m a developer. PHP, Apache, Mysql, Drush, Composer, Drupal Console, XDebug …. The list is endless. And my biggest problems are: I ALWAYS FORGET HOW TO DO IT! :-D 

Well … sort of. Of course I know how to Google, and that’s what I did the last time. But then I got into big problems. For some reasons PHPStorm didn’t catch the XDebug notifications, so I couldn’t debug. And that’s a huge problem for me. I just can’t work if I can’t use my debugger.

So I wiped my computer clean again, to get a fresh start (I did try hours and hours of Googling to figure out how to enable it, without luck). And luckily I found an old text document with tldr; notes from when I was setting my computer up four years ago. I upgraded it, wrote this blog post and I’m now sharing it with you. Because if I have a hard time remembering it all, most likely some other people could be in the same situation.

And even if nobody reads this blog post but me … I still have a good documentation for myself :D

Step one: Homebrew, Apache, PHP, XDebug and MySQL

I use Homebrew to manage my packages for PHP. It’s just so much easier. And recommended anyway.

First though, we need to install XCode. You can get XCode from the App store (  Install it as normally. EDIT: Now you can skip this step! Just install the Command Line Tools below

Next step is to install the command line tools:

xcode-select –install
… and agree to the license: sudo xcodebuild -license

Next is to get Homebrew, with this command: ruby -e "$(curl -fsSL" 


After that we start with Apache. Now this was a headache and a half. I had to read many different blogs, git repos and StackOverflow postings in order to get this configuration going like I wanted. For the most of it I followed this blog ( but it has dated from the time of writing, so below is my rendering of it, with some additions, mostly regarding vhosts. Base of the vhosts setup I found here ( , but again, I had to do my own version of it to work. EDIT: This does not work for Mojave! Google away
So here we go:
Stop the Apache that ships with MacOSX and stop it from restarting
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null

Install Apache:
brew install httpd24 --with-privileged-ports --with-http2

Make it so Apache launches on boot:
sudo cp -v /usr/local/Cellar/httpd/2.4.29_1/homebrew.mxcl.httpd.plist  /Library/LaunchDaemons/
sudo chown -v root:wheel /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
sudo chmod -v 644 /Library/LaunchDaemons/homebrew.mxcl.httpd.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd.plist


We used to have to tap into the PHP kegs, but we don't anymore. PHP is now part of Homebrew. When I wrote this blog last year, PHP 7.1 was stable and 7.2 still had some issues. Now 7.2 is stable, 7.3 too, but I had difficulty in installing XDebug for 7.3, therefor I have 7.2.

Install PHP
brew install php@7.2

Set the timezone  (/usr/local/etc/php/7.2/php.ini) 
In my case:  
date.timezone = Atlantic/Reykjavik

EDIT: These lines are used for Apache, which I haven't installed yet!

Edit httpd.conf (/usr/local/etc/httpd/httpd.conf)  
Add index.php to DirectoryIndex index.html

Add this below that:
<FilesMatch \.php$>
    SetHandler application/x-httpd-php

My install wanted my server to run on ports 8080 and 8443. To change that, I changed the line:
listen 8080 
to listen 80

And in the file /usr/local/etc/httpd/extra/httpd-ssl.conf
listen 8443
to 443
Virtual hosts
The next headache was to get the virtual hosts to work and accept the config. The secret there was the last line in the <Directory> config, namely Require all granted, which came in Apache 2.4

Edit /usr/local/etc/httpd/httpd.conf

Find this and uncomment, and add the following lines afterwards
# Virtual hosts
# Include /private/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot /usr/local/var/www/

Include /usr/local/etc/httpd/vhosts/*.conf

Create the folder /etc/apache2/vhosts and create one vhost file in there (like

<VirtualHost *:80>
    ServerName mysite.local
    DocumentRoot /Users/drupalviking/workspace/
    ErrorLog /Users/drupalviking/logs/error.log

    <Directory /Users/drupalviking/workspace/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted

    # RewriteEngine   on

Create the folders /Users/YOURUSERNAME/logs and /Users/YOURUSERNAME/workspace (I store all my sites under ~/workspace, you can of course change to whatever you want)

Create an index.php under workspace/ and put something like this in:
<h1>My hard work works!!!!!</h1>
<p><?php echo date('d.m.Y'); ?></p>

Save and restart apache with sudo apachectl restart 

Edit /etc/hosts to add 

And finally check if isn’t showing the headline and the date.
I always add PHP to my profile, to make it globally accessible:
cd ~
nano .profile
export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH" 
alias ll="ls -al

The last line is for me, a shortcut to “list-long” command. It’s a nifty one.


Next step is to install xdebug. Xdebug is essential for all developers, to be able to stop the run of your program midway, inspect the variables and step through the code to find errors (I personally write error-free code, but sometimes I have to debug other people’s code ;-) )

pecl install xdebug

When xdebug is installed, we need to add some configuration to php:
nano /usr/local/etc/php/7.1/conf.d/ext-xdebug.ini  

and add these lines to the file:
xdebug.remote_host = 
xdebug.remote_enable = 1 
xdebug.remote_port = 9000 
xdebug.remote_handler = dbgp 
xdebug.remote_mode = req 
xdebug.idekey = PHPSTORM 

EDIT: Didn't work now :-( 

Finally, for this round, I install APC (Alternative PHP Cache) for good PHP measures.
brew install php71-apcu


As a Drupal developer, MySQL is a huge part of my development, so I need to have that. I start by downloading it from here: 
After installation and a restart (NOTE: After installation, MySQL will give you a temp password, store that well, you will need that after restart), the next thing I do is to add MySQL to my profile path variable, by editing .profile and adding /usr/local/mysql/bin to my path variable.

Next I start mysql:  mysql -u root -p (and supply my password when asked).

We’ll have to reset the root password:  SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPassword');

And then also add those two parameters. I run them because I often have huge database dumps, and they prevent the MySQL has gone away error that sometimes appears.
SET GLOBAL wait_timeout = 6000; 
SET GLOBAL max_allowed_packet=256*1024*1024; 

That should take care of MySQL

Step two: PHPStorm

I use PHPStorm when I’m developing. Because using IDE is a smart move. For so many reasons. I’m not getting into the vim/sublime is better debate, if you use those tools, fine. I use IDE for the ease of writing code. And debug. And lint. And more.

Go ahead, get PHPStorm and install it. After it’s been installed, you need to set some default settings for the PHP interpreter to work.

Go to Preferences -> Languages & Frameworks -> PHP
Set the language level to 7.1
Pick the correct interpreter. If everything is correctly set up, you should see the PHP version and the Xdebug version in the window.
Afterwards, when you have opened a project in PHPStorm, in the top right corner are some settings. One of them is an empty box with an arrow down inside. Select that and then select Edit configurations.

To the left is a + sign, press it and select PHP Built-in Web Server
You need to configure the port to something above 1024, like 8080. Set the document root to your project’s root, and then Fix the interpreter (I set the code standards to 7.1 as well as choosing 7.1 for my interpreter. Then I press OK

Now you can “run” your project (completely without Apache!!!!!). Just go to localhost:8080 and voila! 

For debugging purposes, click on the telephone handset icon in the top-right corner to change it to green, and then PHPStorm is listening for debugging sessions!

In Chrome, you’ll need this extention ( to work with PHPStorm and XDebug, to trigger the breakpoints with the browser.

Step three: Extra packages

There is tons of other stuff that I install on my fresh install of MacOSX. You can of course pick and choose, but those are the ones I install.


brew install node 


npm install -g bower  


curl -sS | php 
sudo mv composer.phar /usr/local/bin/composer 
chmod u+x /usr/local/bin/composer  


composer global require drush/drush:8.x (for version 8, which works with D7 as well as D8)
Add composer's bin directory to the system path by placing export PATH="$HOME/.composer/vendor/bin:$PATH" into your ~/.profile (Mac OS users) or into your ~/.bashrc (Linux users).

Drupal Console 

curl -L -o drupal.phar 
mv drupal.phar /usr/local/bin/drupal 
chmod +x /usr/local/bin/drupal 


I’m actually having second thoughts if I need compass. I will skip it for a while and come back to it.
sudo gem update --system 
sudo gem install compass


Wed, 03/07/2018 - 05:42

Ok, here is a strange fact. After a while (I have absolutely no idea when), when you restart your computer, MySQL throws on another temp password to root, if you have changed it to empty.

I first thought it had to do with Aquia Dev Desktop (I had installed it in previous install and when I un-installed it again, MySQL all of a sudden required password), but on my new, fresh install I got it just now. 

So first of all, I think it's better to have password for root, even if you are only working locally.  But if that fails, and all of a sudden you'll have a password protected root access that you don't have the password for, use these directions to reset the password:

  • Restart your computer into safe mode (Restart and press-and-hold the shift key while re-booting)
  • Open terminal and enter:  
    • sudo mysqld_safe --skip-grant-tables
    • mysql -u root
    • ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
    • exit
    • Reboot

That should do it

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.