This is a simplified version based on my experience of building a symfony project.
Pre-requirement:
- PHP 5.4 or higher
- Apache or other web server
- Composer
Installing the Symfony Installer
# Linux, Mac OS X
$ sudo curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
$ sudo chmod a+x /usr/local/bin/symfony
# Windows
c:\> php -r "readfile('http://symfony.com/installer');" > symfony
c:\> move symfony c:\projects
c:\projects\> php symfony
c:\projects\> php symfony
Create a Symfony application
# Linux, Mac OS X
$ symfony new my_project_name
# Windows
c:\> cd projects/
c:\projects\> php symfony new my_project_name
Setting up Permissions
One common issue when installing Symfony is that the
app/cache
and
app/logs
directories must be writable both by the web server and the
command line user.
$ rm -rf app/cache/*
$ rm -rf app/logs/*
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo chmod +a "$HTTPDUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
$ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
For system doesn't support 'chmod +a':
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
For system doesn't support 'chmod +a':
$ HTTPDUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d\ -f1`
$ sudo setfacl -R -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
$ sudo setfacl -dR -m u:"$HTTPDUSER":rwX -m u:`whoami`:rwX app/cache app/logs
Running the Symfony Application
$ cd my_project_name/
$ php app/console server:run
To view it in your browser, input: http://localhost:8000.
Symfony provides a command to check whether your project's dependencies contain any known security vulnerability:
$ php app/console security:check
Checking out a versioned Symfony Application
$ cd my_project_name/
$ composer install
$ composer install
How does Composer know which specific dependencies to install?
When a Symfony application is committed to a repository, the composer.json and composer.lock files are also committed. These files tell Composer which dependencies (and which specific versions) to install for the application.Updating Symfony Applications
- sudo composer self-update
- cd project-path
- sudo composer update
Before you begin, Create a Bundle.
A bundle is nothing more than a directory that houses everything related to a specific feature, including PHP classes, configuration, and even stylesheets and JavaScript files$ php app/console generate:bundle --namespace=Acme/DemoBundle --format=yml
Creating a new page in Symfony is a simple two-step process:
- Create a route: A route defines the URL (e.g.
/about
) to your page and specifies a controller (which is a PHP function) that Symfony should execute when the URL of an incoming request matches the route path; - Create a controller: A controller is a PHP function that takes the incoming
request and transforms it into the Symfony
Response
object that's returned to the user.
No comments:
Post a Comment