jueves, 29 de diciembre de 2011

Configuring Mac Lion for Symfony2 Development

Contents

When I first started with Symfony 1.4.x in Snow Leopard I installed XAMPP and it worked fine.
I recently discovered that Lion OsX comes with Apache and PHP installed [1] , so all I'm missing is MySQL and phpMyAdmin and I'm set.

1 Setting up Apache

1.1 Turning Web Sharing On

  1. Open System Preferences
  2. Click on Sharing on Internet & Wireless.
  3. Turn On Web Sharing

1.2 Activate the PHP Module on Apache

  1. Open Terminal

  2. Type:

    sudo mate /private/etc/apache2/httpd.conf

  3. Search for php5_module and uncomment it (eliminate the #).
    The content will look like this:

LoadModule alias_module libexec/apache2/mod_alias.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

#Apple specific modules
LoadModule apple_userdir_module libexec/apache2/mod_userdir_apple.so
  1. Save the file.

  2. Now you must restart Apache, on Terminal type:

    sudo apachectl restart

1.3 Testing Apache Configuration

Open a Web browsert and type inth address bar http://localhost.

You should get a page that reads:

It works!

1.4 Setting the Time Zone on php.ini

All the following operations require sudo

  1. Copy the file /etc/php.ini.default to /etc/php.ini

  2. Open the /etc/php.ini and set the correct time zone.
    My timezone is Panama.

    date.timezone = AMERICA/PANAMA

1.5 Testing the PHP works with PHP

  1. Open Terminal and type:

    cd /Library/WebServer/Documents/

  2. Type:

    sudo touch test.php

  3. Type:

    sudo mate test.php

  4. On Textmate add the following code

<?php phpinfo(); ?>
  1. Save the file.

Open a Web browsert and type inth address bar http://localhost/test.php.

2 Installing and Configuring MySQL

2.1 Installing MySQL Community Server 5.5.19

  1. Download the Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive from Download MySQL Community Server.
  2. Double click on the mysql-5.5.19-osx10.6-x86_64.dmg file to open and mount the dmg.
  3. Double click on the mysql-5.5.19-osx10.6-x86_64.pkg file.
  4. Follow the installer and accept all the default values. It will ask you for your master
    password.

Warning

/usr/local/mysql is only symlink to /usr/local/mysql-5.5.19-osx10.6-x86_64 which means when you upgrade to new
version symlink will be changed to point to new version but won’t be deleting the older version. However you
need to copy your data directory to new location to make sure your existing databases are intact post upgrade [2].

2.2 Installing the Startup Scritps

You can startup mysql by going to Terminal and typing “/usr/local/mysql/bin/mysqld_safe &”.
We are going to install the startup scrips so we'll be able to start/stop mysql from
System Preferences.

  1. Double click on MySQLStartupItem.pkg and follow on screen instructions.
  2. Double click MySQL.prefPane which will add MySQL to OS X System Preferences.
  3. Select Install for all users of this computer.
  4. Select Automatically Start MySQL Server on Startup

2.3 Installing Sequel Pro

I was going to install phpMyAdmin but read an article that mentioned Sequel Pro [3] so I decided to try it out.

  1. Download Sequel Pro 0.9.9.1 from http://www.sequelpro.com/download/
  2. Double click on Sequel_Pro_0.9.9.1.dmg to open it.
  3. Drag and drop the Sequel Pro icon to your Applications folder.
  4. Double click the Sequel Pro icon.
  5. For Host type 127.0.0.1
  6. For Username type root.
  7. For Password leave blank.

2.4 Configure mysql.sock

Now we need to create a symlink for PHP to be able to access the mysql.sock. Trouble is if you try it you’ll get an error because /var/mysql doesn’t exist [4].

  1. From terminal, run:

    sudo find / -name mysql.sock -print

    The installer installed the sock in /private/tmp/mysql.sock

  2. Run

    sudo mkdir /var/mysql

  3. Run

    sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock

3 Creating a Quick Symfony2 Project to Test Configuration

3.1 Installing Symfony2

  1. Download Symfony2 on zip format.

  2. Unzip the file Symfony_Standard_Vendors_2.0.8.zip to your working directory.

  3. Rename the symfony directory to lion_test

  4. Open a Terminal and move to the lion_test directory.
    Run:

    php ./app/console --version

    Symfony version 2.0.8 - app/dev/debug

3.2 Creating a Bundle

On terminal run php ./app/console generate:bundle name the Bundle namespace LionTest/PeopleBundle.
Accept all defaults values except Do you want to generate the whole directory structure answer yes.

3.3 Generating Doctrine Entities

On terminal run php ./app/console gen:doctrine:entity. Create an entity with the Shortcut name
LionTestPeopleBundle:People. Use the following data for the columns

ColumnTypeSize
last_namestring80
first_namestring80
date_of_birthdate
dob_fuzzynessinteger

Accept values for defaul except on Do you want to generate an empty repository class answer yes.

3.4 Connecting to the Database

3.4.1 Connection Parameters

Open /lion_test/app/config/parameters.ini and change the database to people.

[parameters]
database_driver = pdo_mysql
database_host = localhost
database_port =
database_name = people
database_user = root
database_password =

3.4.2 Generating CRUD Controllers and Templates

On terminal run php ./app/console doctrine:generate:crud create a the crud forms for
LionTestPeopleBundle:People create the write actions.

3.5 Configuring Apache to access your Symfony2 Site

Since the purpose of this entry is configure your Mac for Symfon2 development
I'm not going to bother the creation of a virtual directory con Apache that points
to your development folder.

So I'm simply going to copy my lion_test to /Library/WebServer/Documents/.
The run the following commands inside the directory

sudo chmod -R app/logs
sudo chmod -R app/cache

Now run http://localhost/lion_test/web/app_dev.php/people/ and you should access
the People List page.


Enjoy!!

[1]Install Apache and PHP on Mac OS X Lion (No XAMPP required) http://www.youtube.com/watch?v=iIZ1gfDjjL0

[2]Installation of MySQL server on Mac OS X Lion http://www.djangoapp.com/blog/2011/07/24/installation-of-mysql-server-on-mac-os-x-lion/

[3]Getting MySQL work on OSX 10.7 Lion http://stackoverflow.com/questions/6317614/getting-mysql-work-on-osx-10-7-lion

[4]How to install MySQL 5.5 on Mac OS X 10.7 Lion http://blog.salientdigital.com/2011/09/08/how-to-install-mysql-5-5-on-mac-os-x-10-7-lion/

sábado, 24 de diciembre de 2011

Installing restructuredText Bundle for TextMate

I recently discovered restructuredText and got TextMate some time ago but haven't been able to play
with it. I'm trying to blog with it. So I looked up if there were any Bundles for TextMate (not that I'm that clear on what a bundle is).

Install Docutils

Download Docutils 0.8.1 .

On Terminal run:

sudo setup.py install

You will get a an output like this:

running install
running build
running build_py
running build_scripts
running build_data
running install_lib
running install_scripts
changing mode of /usr/local/bin/rst2html.py to 755
changing mode of /usr/local/bin/rst2latex.py to 755
changing mode of /usr/local/bin/rst2man.py to 755
changing mode of /usr/local/bin/rst2odt.py to 755
changing mode of /usr/local/bin/rst2odt_prepstyles.py to 755
changing mode of /usr/local/bin/rst2pseudoxml.py to 755
changing mode of /usr/local/bin/rst2s5.py to 755
changing mode of /usr/local/bin/rst2xetex.py to 755
changing mode of /usr/local/bin/rst2xml.py to 755
changing mode of /usr/local/bin/rstpep2html.py to 755
running install_data
running install_egg_info
Removing /Library/Python/2.7/site-packages/docutils-0.8.1-py2.7.egg-info
Writing /Library/Python/2.7/site-packages/docutils-0.8.1-py2.7.egg-info

Install reStructuredText TextMate Bundle

Download the bundle in zip format from https://github.com/textmate/restructuredtext.tmbundle.

Unzip the file to a temporary location. In my case ~/Downloads/textmate-restructuredtext.tmbundle-edfe62e.
Edit the folder name from textmate-restructuredtext.tmbundle-edfe62e to textmate-restructuredtext.tmbundle using
Finder. The icon for the folder should change.

Open Terminal. Type the following commands:


mkdir -p ~/Library/ApplicationSupport/TextMate/Bundles


cp -r ~/Downloads/textmate-restructuredtext.tmbundle ~/Library/ApplicationSupport/TextMate/Bundles


Configure Environment Variables

I tried creating the variables using export but for some reason it didn't work. After doing some research
it seems there are several ways to declare environment list (using launchctl, using environment.plit and using export).
None of these methods worked for me on Lion, while trying to declare the TM_RST2HTML.

I kept getting the following error:

Couldn't find rst2html.py
You can either set the TM_RST2HTML variable to the full path of your docutils (docutils.sourceforge.net) installation (e.g. /Library/Frameworks/Python.framework/Versions/2.4/bin/rst2html.py or set the PATH variable to include the path of the docutils converters.
Locations searched:
/Applications/TextMate.app/Contents/SharedSupport/Support/bin/CocoaDialog.app/Contents/MacOS
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local2/bin
/Applications/TextMate.app/Contents/SharedSupport/Support/bin

What finally worked for me was opening TextMate and going to TextMate\Preferences on Advanced on Shell Variable
added to the PATH variable /usr/local/bin.