diff --git a/book/installation.rst b/book/installation.rst index d83cf153ea7..f065473ec3f 100644 --- a/book/installation.rst +++ b/book/installation.rst @@ -5,218 +5,205 @@ Installing and Configuring Symfony ================================== The goal of this chapter is to get you up and running with a working application -built on top of Symfony. Fortunately, Symfony offers "distributions", which -are functional Symfony "starter" projects that you can download and begin -developing in immediately. +built on top of Symfony. In order to simplify the process of creating new +applications, Symfony provides an installer that must be installed before +creating the first application. -.. tip:: +Installing the Symfony Installer +-------------------------------- - If you're looking for instructions on how best to create a new project - and store it via source control, see `Using Source Control`_. +Using the Symfony Installer is the only recommended way to create new Symfony +applications. This installer is a PHP application that has to be installed +only once and then it can create any number of Symfony applications. -.. _installing-a-symfony2-distribution: +.. note:: -Installing a Symfony Distribution ---------------------------------- + The installer requires PHP 5.4 or higher. If you still use the legacy + PHP 5.3 version, you cannot use the Symfony Installer. Read the + :ref:`book-creating-applications-without-the-installer` section to learn how + to proceed. -.. tip:: +Depending on your operating system, the installer must be installed in different +ways. - First, check that you have installed and configured a Web server (such - as Apache) with PHP. For more information on Symfony requirements, see the - :doc:`requirements reference `. +Linux and Mac OS X Systems +~~~~~~~~~~~~~~~~~~~~~~~~~~ -Symfony packages "distributions", which are fully-functional applications -that include the Symfony core libraries, a selection of useful bundles, a -sensible directory structure and some default configuration. When you download -a Symfony distribution, you're downloading a functional application skeleton -that can be used immediately to begin developing your application. +Open your command console and execute the following three commands: + +.. code-block:: bash -Start by visiting the Symfony download page at `http://symfony.com/download`_. -On this page, you'll see the *Symfony Standard Edition*, which is the main -Symfony distribution. There are 2 ways to get your project started: + $ curl -LsS http://symfony.com/installer > symfony.phar + $ sudo mv symfony.phar /usr/local/bin/symfony + $ chmod a+x /usr/local/bin/symfony -Option 1) Composer -~~~~~~~~~~~~~~~~~~ +This will create a global ``symfony`` command in your system that will be used +to create new Symfony applications. -`Composer`_ is a dependency management library for PHP, which you can use -to download the Symfony Standard Edition. +Windows Systems +~~~~~~~~~~~~~~~ -Start by `downloading Composer`_ anywhere onto your local computer. If you -have curl installed, it's as easy as: +Open your command console and execute the following command: .. code-block:: bash - $ curl -s https://getcomposer.org/installer | php + c:\> php -r "readfile('http://symfony.com/installer');" > symfony.phar -.. note:: +Then, move the downloaded ``symfony.phar`` file to your projects directory and +execute it as follows: + +.. code-block:: bash + + c:\> move symfony.phar c:\projects + c:\projects\> php symfony.phar - If your computer is not ready to use Composer, you'll see some recommendations - when running this command. Follow those recommendations to get Composer - working properly. +Creating the Symfony Application +-------------------------------- -Composer is an executable PHAR file, which you can use to download the Standard -Distribution: +Once the Symfony Installer is ready, create your first Symfony application with +the ``new`` command: .. code-block:: bash - $ php composer.phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony '2.3.*' + # Linux, Mac OS X + $ symfony new my_project_name -.. tip:: + # Windows + c:\> cd projects/ + c:\projects\> php symfony.phar new my_project_name - To download the vendor files faster, add the ``--prefer-dist`` option at - the end of any Composer command. +This command creates a new directory called ``my_project_name`` that contains a +fresh new project based on the most recent stable Symfony version available. In +addition, the installer checks if your system meets the technical requirements +to execute Symfony applications. If not, you'll see the list of changes needed +to meet those requirements. .. tip:: - Add the ``-vvv`` flag to see everything that Composer is doing - this is - especially useful on a slow connection where it may seem that nothing is - happening. + For security reasons, all Symfony versions are digitally signed before + distributing them. If you want to verify the integrity of any Symfony + version, follow the steps `explained in this post`_. -This command may take several minutes to run as Composer downloads the Standard -Distribution along with all of the vendor libraries that it needs. When it finishes, -you should have a directory that looks something like this: +Basing your Project on a Specific Symfony Version +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. code-block:: text - - path/to/webroot/ <- your web server directory (sometimes named htdocs or public) - Symfony/ <- the new directory - app/ - cache/ - config/ - logs/ - src/ - ... - vendor/ - ... - web/ - app.php - ... - -Option 2) Download an Archive -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You can also download an archive of the Standard Edition. Here, you'll -need to make two choices: - -* Download either a ``.tgz`` or ``.zip`` archive - both are equivalent, download - whatever you're more comfortable using; - -* Download the distribution with or without vendors. If you're planning on - using more third-party libraries or bundles and managing them via Composer, - you should probably download "without vendors". - -Download one of the archives somewhere under your local web server's root -directory and unpack it. From a UNIX command line, this can be done with -one of the following commands (replacing ``###`` with your actual filename): +If your project needs to be based on a specific Symfony version, pass the version +number as the second argument of the ``new`` command: .. code-block:: bash - # for .tgz file - $ tar zxvf Symfony_Standard_Vendors_2.3.###.tgz + # Linux, Mac OS X + $ symfony new my_project_name 2.3.23 - # for a .zip file - $ unzip Symfony_Standard_Vendors_2.3.###.zip + # Windows + c:\projects\> php symfony.phar new my_project_name 2.3.23 -If you've downloaded "without vendors", you'll definitely need to read the -next section. +Read the `Symfony Release process`_ to better understand why there are several +Symfony versions and which one to use for your projects. -.. note:: +.. _book-creating-applications-without-the-installer: - You can easily override the default directory structure. See - :doc:`/cookbook/configuration/override_dir_structure` for more - information. +Creating Symfony Applications without the Installer +--------------------------------------------------- -All public files and the front controller that handles incoming requests in -a Symfony application live in the ``Symfony/web/`` directory. So, assuming -you unpacked the archive into your web server's or virtual host's document root, -your application's URLs will start with ``http://localhost/Symfony/web/``. +If you still use PHP 5.3, or if you can't execute the installer for any reason, +you can create Symfony applications using the alternative installation method +based con `Composer`_. -.. note:: +Composer is the dependency manager used by modern PHP applications and it can +also be used to create new applications based on the Symfony framework. If you +don't have installed it globally, start by reading the next section. - The following examples assume you don't touch the document root settings - so all URLs start with ``http://localhost/Symfony/web/`` +Installing Composer Globally +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. _installation-updating-vendors: +On Linux and Mac OS X, execute the following two commands to install Composer +globally: -Updating Vendors -~~~~~~~~~~~~~~~~ +.. code-block:: bash -At this point, you've downloaded a fully-functional Symfony project in which -you'll start to develop your own application. A Symfony project depends on -a number of external libraries. These are downloaded into the ``vendor/`` directory -of your project via a library called `Composer`_. + $ curl -sS https://getcomposer.org/installer | php + $ sudo mv composer.phar /usr/local/bin/composer -Depending on how you downloaded Symfony, you may or may not need to update -your vendors right now. But, updating your vendors is always safe, and guarantees -that you have all the vendor libraries you need. +On Windows Systems, download the executable Composer installer that you can find +on the `Composer download page`_ and follow the steps. -Step 1: Get `Composer`_ (The great new PHP packaging system) +Creating a Symfony Application with Composer +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. code-block:: bash +Once Composer is installed on your computer, execute the ``create-project`` +command to create a new Symfony application based on its latest stable version: - $ curl -s http://getcomposer.org/installer | php +.. code-block:: bash -Make sure you download ``composer.phar`` in the same folder where -the ``composer.json`` file is located (this is your Symfony project -root by default). + $ composer create-project symfony/framework-standard-edition my_project_name -Step 2: Install vendors +If you need to base your application on a specific Symfony version, provide that +version as the second argument of the ``create-project`` command: .. code-block:: bash - $ php composer.phar install + $ composer create-project symfony/framework-standard-edition my_project_name '2.3.*' -This command downloads all of the necessary vendor libraries - including -Symfony itself - into the ``vendor/`` directory. +.. tip:: -.. note:: + If your Internet connection is slow, you may think that Composer is not + doing anything. If that's your case, add the ``-vvv`` flag to the previous + command to display a detailed output of everything that Composer is doing. - If you don't have ``curl`` installed, you can also just download the ``installer`` - file manually at http://getcomposer.org/installer. Place this file into your - project and then run: +Running the Symfony Application +------------------------------- - .. code-block:: bash +Symfony leverages the internal web server provided by PHP to run applications +while developing them. Therefore, running a Symfony application is a matter of +browsing the project directory and executing this command: - $ php installer - $ php composer.phar install +.. code-block:: bash -.. tip:: + $ cd my_project_name/ + $ php app/console server:run - When running ``php composer.phar install`` or ``php composer.phar update``, - Composer will execute post install/update commands to clear the cache - and install assets. By default, the assets will be copied into your ``web`` - directory. +Then, open your browser and access the ``http://localhost:8000`` URL to see the +Welcome page of Symfony: - Instead of copying your Symfony assets, you can create symlinks if - your operating system supports it. To create symlinks, add an entry - in the ``extra`` node of your composer.json file with the key - ``symfony-assets-install`` and the value ``symlink``: +.. image:: /images/quick_tour/welcome.png + :align: center + :alt: Symfony Welcome Page + +Instead of the Welcome Page, you may see a blank page or an error page. +This is caused by a directory permission misconfiguration. There are several +possible solutions depending on your operating system. All of them are +explained in the :ref:`Setting up Permissions ` +section. - .. code-block:: json +.. note:: - "extra": { - "symfony-app-dir": "app", - "symfony-web-dir": "web", - "symfony-assets-install": "symlink" - } + PHP's internal web server is available in PHP 5.4 or higher versions. If you + still use the legacy PHP 5.3 version, you'll have to configure a *virtual host* + in your web server. - When passing ``relative`` instead of ``symlink`` to symfony-assets-install, - the command will generate relative symlinks. +The ``server:run`` command is only suitable while developing the application. In +order to run Symfony applications on production servers, you'll have to configure +your `Apache`_ or `Nginx`_ web server as explained in +:doc:`/cookbook/configuration/web_server_configuration`. -Configuration and Setup -~~~~~~~~~~~~~~~~~~~~~~~ +When you are finished working on your Symfony application, you can stop the +server with the ``server:stop`` command: + +.. code-block:: bash -At this point, all of the needed third-party libraries now live in the ``vendor/`` -directory. You also have a default application setup in ``app/`` and some -sample code inside the ``src/`` directory. + $ php app/console server:stop -Symfony comes with a visual server configuration tester to help make sure -your Web server and PHP are configured to use Symfony. Use the following URL -to check your configuration: +Checking Symfony Application Configuration and Setup +---------------------------------------------------- + +Symfony applications come with a visual server configuration tester to show if +your environment is ready to use Symfony. Access the following URL to check your +configuration: .. code-block:: text - http://localhost/config.php + http://localhost:8000/config.php If there are any issues, correct them now before moving on. @@ -224,13 +211,21 @@ If there are any issues, correct them now before moving on. .. sidebar:: Setting up Permissions - One common issue is that the ``app/cache`` and ``app/logs`` directories - must be writable both by the web server and the command line user. On - a UNIX system, if your web server user is different from your command - line user, you can run the following commands just once in your project - to ensure that permissions will be setup properly. + 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. On a UNIX system, if your web server user is different + from your command line user, you can try one of the following solutions. + + **1. Use the same user for the CLI and the web server** + + In development environments, it is a common practice to use the same UNIX + user for the CLI and the web server because it avoids any of these permissions + issues when setting up new projects. This can be done by editing your web server + configuration (e.g. commonly httpd.conf or apache2.conf for Apache) and setting + its user to be the same as your CLI user (e.g. for Apache, update the ``User`` + and ``Group`` values). - **1. Using ACL on a system that supports chmod +a** + **2. Using ACL on a system that supports chmod +a** Many systems allow you to use the ``chmod +a`` command. Try this first, and if you get an error - try the next method. This uses a command to @@ -246,7 +241,7 @@ If there are any issues, correct them now before moving on. $ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs - **2. Using ACL on a system that does not support chmod +a** + **3. Using ACL on a system that does not support chmod +a** Some systems don't support ``chmod +a``, but do support another utility called ``setfacl``. You may need to `enable ACL support`_ on your partition @@ -256,19 +251,18 @@ If there are any issues, correct them now before moving on. .. code-block:: bash - $ 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 + $ 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 If this doesn't work, try adding ``-n`` option. - **3. Without using ACL** + **4. Without using ACL** - If you don't have access to changing the ACL of the directories, you will - need to change the umask so that the cache and log directories will - be group-writable or world-writable (depending if the web server user - and the command line user are in the same group or not). To achieve - this, put the following line at the beginning of the ``app/console``, + If none of the previous methods work for you, change the umask so that the + cache and log directories will be group-writable or world-writable (depending + if the web server user and the command line user are in the same group or not). + To achieve this, put the following line at the beginning of the ``app/console``, ``web/app.php`` and ``web/app_dev.php`` files:: umask(0002); // This will let the permissions be 0775 @@ -280,37 +274,83 @@ If there are any issues, correct them now before moving on. Note that using the ACL is recommended when you have access to them on your server because changing the umask is not thread-safe. - **4. Use the same user for the CLI and the web server** +.. _installation-updating-vendors: - In development environments, it is a common practice to use the same unix - user for the CLI and the web server because it avoids any of these permissions - issues when setting up new projects. This can be done by editing your web server - configuration (e.g. commonly httpd.conf or apache2.conf for Apache) and setting - its user to be the same as your CLI user (e.g. for Apache, update the User - and Group values). +Updating Symfony Applications +----------------------------- -When everything is fine, click on "Go to the Welcome page" to request your -first "real" Symfony webpage: +At this point, you've create a fully-functional Symfony application in which +you'll start to develop your own project. A Symfony application depends on +a number of external libraries. These are downloaded into the ``vendor/`` directory +and they are managed exclusively by Composer. -.. code-block:: text +Updating those third-party libraries frequently is a good practice to prevent bugs +and security vulnerabilities. Execute the ``update`` Composer command to update +them all at once: - http://localhost/app_dev.php/ +.. code-block:: bash -Symfony should welcome and congratulate you for your hard work so far! + $ cd my_project_name/ + $ composer update -.. image:: /images/quick_tour/welcome.png +Depending on the complexity of your project, this update process can take up to +several minutes to complete. -.. tip:: +.. _installing-a-symfony2-distribution: + +Installing a Symfony Distribution +--------------------------------- + +Symfony project packages "distributions", which are fully-functional applications +that include the Symfony core libraries, a selection of useful bundles, a +sensible directory structure and some default configuration. In fact, when you +created a Symfony application in the previous sections, you actually downloaded the +default distribution provided by Symfony, which is called *Symfony Standard Edition*. + +The *Symfony Standard Edition* is by far the most popular distribution and it's +also the best choice for developers starting with Symfony. However, the Symfony +Community has published other popular distributions that you may use in your +applications: + +* The `Symfony CMF Standard Edition`_ is the best distribution to get started + with the `Symfony CMF`_ project, which is a project that makes it easier for + developers to add CMS functionality to applications built with the Symfony + framework. +* The `Symfony REST Edition`_ shows how to build an application that provides a + RESTful API using the FOSRestBundle and several other related bundles. + +Using Source Control +-------------------- + +If you're using a version control system like `Git`_, you can safely commit all +your project's code. The reason is that Symfony applications already contain a +``.gitignore`` file specially prepared for Symfony. + +For specific instructions on how best to setup your project to be stored +in Git, see :doc:`/cookbook/workflow/new_project_git`. + +Checking out a Versioned Symfony Application +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +When using Composer to manage application's dependencies, it's recommended to +ignore the entire ``vendor/`` directory before committing its code to the +repository. This means that when checking out a Symfony application from a Git +repository, there will be no ``vendor/`` directory and the application won't +work out-of-the-box. - To get nice and short urls you should point the document root of your - webserver or virtual host to the ``Symfony/web/`` directory. Though - this is not required for development it is recommended at the time your - application goes into production as all system and configuration files - become inaccessible to clients then. For information on configuring - your specific web server document root, read - :doc:`/cookbook/configuration/web_server_configuration` - or consult the official documentation of your webserver: - `Apache`_ | `Nginx`_ . +In order to make it work, check out the Symfony application and then execute the +``install`` Composer command to download and install all the dependencies required +by the application: + +.. code-block:: bash + + $ cd my_project_name/ + $ composer install + +How does Composer know which specific dependencies to install? Because 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. Beginning Development --------------------- @@ -332,40 +372,15 @@ a wide variety of articles about solving specific problems with Symfony. If you want to remove the sample code from your distribution, take a look at this cookbook article: ":doc:`/cookbook/bundles/remove`" -Using Source Control --------------------- - -If you're using a version control system like ``Git`` or ``Subversion``, you -can setup your version control system and begin committing your project to -it as normal. The Symfony Standard Edition *is* the starting point for your -new project. - -For specific instructions on how best to setup your project to be stored -in Git, see :doc:`/cookbook/workflow/new_project_git`. - -Ignoring the ``vendor/`` Directory -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -If you've downloaded the archive *without vendors*, you can safely ignore -the entire ``vendor/`` directory and not commit it to source control. With -``Git``, this is done by creating and adding the following to a ``.gitignore`` -file: - -.. code-block:: text - - /vendor/ - -Now, the vendor directory won't be committed to source control. This is fine -(actually, it's great!) because when someone else clones or checks out the -project, they can simply run the ``php composer.phar install`` script to -install all the necessary project dependencies. - -.. _`enable ACL support`: https://help.ubuntu.com/community/FilePermissionsACLs -.. _`http://symfony.com/download`: http://symfony.com/download -.. _`Git`: http://git-scm.com/ -.. _`GitHub Bootcamp`: http://help.github.com/set-up-git-redirect +.. _`Symfony Release process`: http://symfony.com/doc/current/contributing/community/releases.html +.. _`explained in this post`: http://fabien.potencier.org.nyud.net/article/73/signing-project-releases .. _`Composer`: http://getcomposer.org/ -.. _`downloading Composer`: http://getcomposer.org/download/ +.. _`Composer download page`: https://getcomposer.org/download/ .. _`Apache`: http://httpd.apache.org/docs/current/mod/core.html#documentroot .. _`Nginx`: http://wiki.nginx.org/Symfony -.. _`Symfony Installation Page`: http://symfony.com/download +.. _`enable ACL support`: https://help.ubuntu.com/community/FilePermissionsACLs +.. _`Symfony CMF Standard Edition`: https://github.com/symfony-cmf/symfony-cmf-standard +.. _`Symfony CMF`: http://cmf.symfony.com/ +.. _`Symfony REST Edition`: https://github.com/gimler/symfony-rest-edition +.. _`FOSRestBundle`: https://github.com/FriendsOfSymfony/FOSRestBundle +.. _`Git`: http://git-scm.com/ diff --git a/book/page_creation.rst b/book/page_creation.rst index 085f98e9cc6..67915f6e639 100644 --- a/book/page_creation.rst +++ b/book/page_creation.rst @@ -489,13 +489,16 @@ Though entirely flexible, by default, each Symfony :term:`application` has the same basic and recommended directory structure: * ``app/``: This directory contains the application configuration; - * ``src/``: All the project PHP code is stored under this directory; - * ``vendor/``: Any vendor libraries are placed here by convention; - * ``web/``: This is the web root directory and contains any publicly accessible files; +.. seealso:: + + You can easily override the default directory structure. See + :doc:`/cookbook/configuration/override_dir_structure` for more + information. + .. _the-web-directory: The Web Directory