Mostrando entradas con la etiqueta Mac. Mostrar todas las entradas
Mostrando entradas con la etiqueta Mac. Mostrar todas las entradas

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.

domingo, 21 de noviembre de 2010

Extracting modified files from a Subversion Project

Sometimes you work on a project but don´t want to commit the changes but also want to take the changes with you to another computer.
Here´s a little trick for linux and Mac. On a terminal move to your versioned project directory and type
svn status | grep ^[AM\?] | awk  '{print $2}' | zip ../backup_`date +"%Y%m%d_%H%M"` -@

This will zip all added (A), modified (M) and new (?) files to a file named backup_20101117.zip with the directory structure
To unzip it:
tar xvf /path/to/zip/backup_20101117.zip -C /path/to/project

If you´re using Windows…. Be afraid, be very afraid. Nah just kidding you can install Cygwin (http://www.cygwin.com ) and use this trick.

sábado, 12 de junio de 2010

Integrando Maven con Eclipse en Mac OSX

Instalando Maven


  1. Baje Maven 2.2.1 del sitio de Maven en formato zip

  2. Descomprimalo en cualquier directorio (/Users/luisberrocal/Downloads por ejemplo).

  3. Mueva el directorio apache-maven-2.2.1 al directorio /usr/share

  4. sudo mv apache-maven-2.2.1 /usr/share

  5. Corre el siguiente commando:
    mvn -version
    Apache Maven 2.2.0 (r788681; 2009-06-26 08:04:01-0500)
    Java version: 1.6.0_20
    Java home: /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
    Default locale: en_US, platform encoding: MacRoman
    OS name: "mac os x" version: "10.6.3" arch: "x86_64" Family: "mac"
  6. "
  7. Cree un archivo ~/.bash_profile y coloque el siguiente contenido:
    export M2_HOME=/usr/share/apache-maven-2.2.1
    export M2=$M2_HOME/bin
    export JAVA_HOME=/Library/Java/Home/
    export PATH=$PATH:$M2

  8. Abra una sesión nueva de Terminal y corra el siguiente comando para verificar que las variables están incializadas
    echo $JAVA_HOME

Instalando el plugin M2


Los pasos del sitio del plugin M2 son bastante claros y no vale la pena repetirlos, inclusive tienen un video.

Con esto estamos listos para utilizar Maven.

domingo, 14 de marzo de 2010

Configurar Symfony con XAMPP en Mac

La configuracion del servidor web mostrada en la sección Web Server Configuration requiere algunos adiciones para que funcione.

Estoy usando Symfony 1.4.3 con XAMPP for Mac OS X 1.7.2a corriendo sobre Snow Leopard.

Configuración de Apache


Cuando seguí las instrucciones de la sección Web Server Configuration Apache inciaba y los segundos se apagaba solo. Al verificar el error_log encontré:

[Sun Mar 14 08:09:31 2010] [emerg] (13)Permission denied: couldn't grab the accept mutex
[Sun Mar 14 08:09:31 2010] [emerg] (13)Permission denied: couldn't grab the accept mutex
[Sun Mar 14 08:09:32 2010] [alert] Child 329 returned a Fatal error... Apache is exiting!

La solución que funcionó para mi fue agregar "AcceptMutex flock" en el httpd.conf.
Mi configuración quedó así:
AcceptMutex flock
# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080

# This is the configuration for your project
Listen 127.0.0.1:8080

<VirtualHost 127.0.0.1:8080>
DocumentRoot "/Users/tg/NetBeansProjects/sfRemates/web"
DirectoryIndex index.php
<Directory "/Users/tg/NetBeansProjects/sfRemates/web">
AllowOverride All
Allow from All
</Directory>

Alias /sf /Users/tg/Documents/symfony-1.4.3/data/web/sf
<Directory "/Users/tg/Documents/symfony-1.4.3/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

Con esto logré que Apache arrancara.

Problemas con Permisos


Luego de lograr correr Apache y tener la aplicación creada. Empece a obtener el siguiente error al conectarme a http://127.0.0.1:8080 :

Warning: require_once(/Users/luisberrocal/Documents/symfony-1.4.3/lib/autoload/sfCoreAutoload.class.php) [function.require-once]: failed to open stream: Permission denied in /Users/luisberrocal/NetBeansProjects/sfRemates/config/ProjectConfiguration.class.php on line 3

Fatal error: require_once() [function.require]: Failed opening required '/Users/luisberrocal/Documents/symfony-1.4.3/lib/autoload/sfCoreAutoload.class.php' (include_path='.:/Applications/xampp/xamppfiles/lib/php:/Applications/xampp/xamppfiles/lib/php/pear:/Applications/xampp/xamppfiles/Smarty-2.6.26/libs') in /Users/luisberrocal/NetBeansProjects/sfRemates/config/ProjectConfiguration.class.php on line 3

Despues de investigar mucho y hacer varios cambios en los permisos opte por instalar Symfony desde Pear. Originalmente lo había instalado en /Users/luisberrocal/Documents/symfony-1.4.3 a partir de un zip.

A continución los pasos que me funcionaron, los puntos 3 a 5 son para usuarios de Netbeans, si no esta utilizando Netbeans salte al punto 6:

1. Corra pear channel-discover pear.symfony-project.com
2. Corra pear install symfony/symfony-1.4.3
3. En Netbeans 6.8 abra la ventana Options desde el menu Neatbeans\Preferences.
4. Seleccion la pestaña PHP y luego la pestaña Symfony.
5. Cambie la ubicación del Symfony script a /usr/bin/symfony.
6. Genere un proyecto.

Tuve que editar el httpd.conf para lograr que los gráficos se vieran:

Alias /sf /usr/lib/php/data/symfony/web/sf
<Directory "/usr/lib/php/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>