Symfony 3 on MAMP with Mercurial VCS and Eclipse IDE - part 1

I use MAMP+Mercurial+Eclipse as PHP development environment on Mac OS X. These are instructions for this environment adapted from https://symfony.com/doc/current/book/installation.html

  • As the Symfony 3 installer uses the default system php command, we will first make sure that it takes the one from MAMP we want, in this case PHP version 5.6.7. For this we will create an alias which for convenience you’ll probably want to add to .bashrc: 
alias php=/Applications/MAMP/bin/php/php5.6.7/bin/php

  • Check the PHP version you are using with: 
php --version
  • you may also check the php.ini file being used in case some change is required
php --ini

  • As admin user:
sudo curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony

  • As your regular user:
symfony new symfony_test_01
  • app is installed on user’s home page. You may want to move it to some other folder

mv /Users/MyUser/symfony_test_01 /Users/MyUser/Workspace/

  • run it

cd /Users/MyUser/Workspace/symfony_test_01
php bin/console server:run

you should get this:

 [OK] Server running on http://127.0.0.1:8000                                                                                                                                                                                             

// Quit the server with CONTROL-C.
  • Point the browser to the URL shown by the last command and verify it works

With this we've verified it works with the PHP's built-in server.
For a number of reasons I prefer to setup an Apache virtual host instead of using it, even if this requires more work.
  • For that we create a virtual host configuration file for Apache. This file may contain something like this:
########## symfony_test_01.loc

<VirtualHost *:8888>
DocumentRoot "/Users/MyUser/Workspace/symfony_test_01/web"
ServerName symfony_test_01.loc
ErrorLog "/Users/MyUser/Workspace/symfony_test_01/var/logs/apache-error_log"
CustomLog "/Users/MyUser/Workspace/symfony_test_01/var/logs/apache-access_log" common
<Directory "/Users/MyUser/Workspace/symfony_test_01/web">
DirectoryIndex app.php
</Directory>
</VirtualHost>
  • We save this file as apache_vhost.conf
  • Now we make a Apache-MAMP to load this file. For that you can do something like:
echo "Include /Users/MyUser/Workspace/symfony_test_01/apache_vhost.conf" >> /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf 
Note that I included a fake domain name "symfony_test_01.loc". This is to allow several projects to run on the same server (localhost)
  • So for this domain name to work we'll add it to /etc/hosts. As admin:
sudo sh -c "echo '127.0.0.1 symfony_test_01.loc' >> /etc/hosts"
  • Start MAMP
  • Now we verify it works by pointing the browser to the URL
http://symfony_test_01.loc:8888
  • Then check if there's some configuration issue worth fixing:
http://symfony_test_01.loc:8888/config.php
  • Managing components in Symfony is easier with the composer package manager, so here's how to install it if you don't have it
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer about
  • Update packages that may have newer versions
composer update
  • Yet another check
php bin/console security:check
Now we will try with a demo app that implements a list or articles (= a barebones blog without comments)
cd /Users/MyUser/Workspace
symfony demo
mv symfony_demo symfony_demo_01
  • and repeat some of the previous steps top make it work