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
- Open System Preferences
- Click on Sharing on Internet & Wireless.
- Turn On Web Sharing
1.2 Activate the PHP Module on Apache
Open Terminal
Type:
sudo mate /private/etc/apache2/httpd.conf
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
Save the file.
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
Copy the file /etc/php.ini.default to /etc/php.ini
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
Open Terminal and type:
cd /Library/WebServer/Documents/
Type:
sudo touch test.php
Type:
sudo mate test.php
On Textmate add the following code
<?php phpinfo(); ?>
- 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
- Download the Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive from Download MySQL Community Server.
- Double click on the mysql-5.5.19-osx10.6-x86_64.dmg file to open and mount the dmg.
- Double click on the mysql-5.5.19-osx10.6-x86_64.pkg file.
- 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.
- Double click on MySQLStartupItem.pkg and follow on screen instructions.
- Double click MySQL.prefPane which will add MySQL to OS X System Preferences.
- Select Install for all users of this computer.
- 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.
- Download Sequel Pro 0.9.9.1 from http://www.sequelpro.com/download/
- Double click on Sequel_Pro_0.9.9.1.dmg to open it.
- Drag and drop the Sequel Pro icon to your Applications folder.
- Double click the Sequel Pro icon.
- For Host type 127.0.0.1
- For Username type root.
- 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].
From terminal, run:
sudo find / -name mysql.sock -print
The installer installed the sock in /private/tmp/mysql.sock
Run
sudo mkdir /var/mysql
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
Download Symfony2 on zip format.
Unzip the file Symfony_Standard_Vendors_2.0.8.zip to your working directory.
Rename the symfony directory to lion_test
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
Column | Type | Size |
---|---|---|
last_name | string | 80 |
first_name | string | 80 |
date_of_birth | date | |
dob_fuzzyness | integer |
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/ |
No hay comentarios:
Publicar un comentario