{"id":28851,"date":"2024-04-28T01:03:27","date_gmt":"2024-04-28T00:03:27","guid":{"rendered":"https:\/\/nelkodev.com\/blog\/comienza-tu-proyecto-con-symfony-guia-de-configuracion-inicial\/"},"modified":"2024-06-03T18:40:51","modified_gmt":"2024-06-03T17:40:51","slug":"comienza-tu-proyecto-con-symfony-guia-de-configuracion-inicial","status":"publish","type":"post","link":"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/","title":{"rendered":"Start your Project with Symfony: Initial Configuration Guide"},"content":{"rendered":"<p>Symfony is one of the most popular frameworks for developing web applications in PHP. It offers a robust structure, an active community and agile development. In this article I will guide you step by step to set up your Symfony project from scratch, ensuring that you can start your development efficiently and effectively.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ffffff;color:#ffffff\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ffffff;color:#ffffff\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#%C2%BFPor_que_elegir_Symfony\" >Why choose Symfony?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Requisitos_Previos\" >Previous requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Crear_un_Proyecto_Symfony\" >Create a Symfony Project<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Configuracion_de_Entorno\" >Environment Configuration<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Variables_de_Entorno\" >Environment Variables<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Configuracion_de_Servidor_Web\" >Web Server Configuration<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Estructura_del_Proyecto\" >Project Structure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Primeros_Pasos_con_el_Controlador\" >Getting Started with the Controller<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/nelkodev.com\/en\/php\/start-your-project-with-symfony-initial-setup-guide\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"%C2%BFPor_que_elegir_Symfony\"><\/span>Why choose Symfony?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before we dive into the initial setup, it&#039;s essential to understand the benefits of using Symfony. This framework stands out for its flexibility, adaptability and the extensive functionalities it offers, which facilitates the maintenance and scalability of applications. Additionally, Symfony is known for its security, which is vital for any web application today.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Requisitos_Previos\"><\/span>Previous requirements<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To start a project with Symfony, you need to meet some basic requirements:<\/p>\n<ul>\n<li><strong>PHP<\/strong>: Version 7.2.5 or higher.<\/li>\n<li><strong>composer<\/strong>: You must have Composer installed, which is the dependency manager for PHP.<\/li>\n<li><strong>Symfony CLI<\/strong>: The Symfony command line simplifies the creation and management of your projects.<\/li>\n<\/ul>\n<p>You can install Composer and Symfony CLI with the following command lines:<\/p>\n<pre><code class=\"&quot;language-bash&quot;\"># Install Composer php -r &quot;copy(&#039;https:\/\/getcomposer.org\/installer&#039;, &#039;composer-setup.php&#039;);&quot; php composer-setup.php php -r &quot;unlink(&#039;composer-setup.php&#039;);&quot; mv composer.phar \/usr\/local\/bin\/composer # Install Symfony CLI wget https:\/\/get.symfony.com\/cli\/installer -O - | bash export PATH=&quot;$HOME\/.symfony5\/bin:$PATH&quot;<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Crear_un_Proyecto_Symfony\"><\/span>Create a Symfony Project<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once you have the prerequisites, the next step is to create a new project. This can be easily done using the command provided by Symfony CLI:<\/p>\n<pre><code class=\"&quot;language-bash&quot;\">symfony new my_symfony_project --full<\/code><\/pre>\n<p>This command creates a new project called <code>my_symfony_project<\/code> with all the necessary dependencies. The option <code>--full<\/code> installs all features by default, including components for a complete web application like Doctrine, Twig, Symfony WebServer, etc.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Configuracion_de_Entorno\"><\/span>Environment Configuration<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>When working with Symfony, it is important to configure the development environment properly. This includes:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Variables_de_Entorno\"><\/span>Environment Variables<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Symfony uses environment variables to configure the application in different environments (development, production, etc.). These variables are defined in the file <code>.env<\/code> at the root of your project. Here you can configure the database, SMTP servers, API keys, etc.<\/p>\n<p>A common example is database configuration:<\/p>\n<pre><code class=\"&quot;language-plaintext&quot;\"># .env DATABASE_URL=&quot;mysql:\/\/db_user:db_password@127.0.0.1:3306\/db_name&quot;<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Configuracion_de_Servidor_Web\"><\/span>Web Server Configuration<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>You can use Symfony&#039;s built-in web server for development. To start the server, simply run the following command in the terminal:<\/p>\n<pre><code class=\"&quot;language-bash&quot;\">symfony server:start<\/code><\/pre>\n<p>This command will set up a local server on <code>http:\/\/127.0.0.1:8000<\/code> where you can see your project.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Estructura_del_Proyecto\"><\/span>Project Structure<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Understanding Symfony&#039;s directory structure will help you better organize your code and manage your files efficiently. Some of the most important directories are:<\/p>\n<ul>\n<li><strong>src\/<\/strong>: Contains the PHP files of your application (controllers, services, etc.).<\/li>\n<li><strong>templates\/<\/strong>: Stores Twig template files.<\/li>\n<li><strong>config\/<\/strong>: Contains all configuration files.<\/li>\n<li><strong>public\/<\/strong>: Public root directory with the <code>index.php<\/code> and assets.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Primeros_Pasos_con_el_Controlador\"><\/span>Getting Started with the Controller<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To generate your first page, you can create a controller. Symfony makes this easy with its console. Run the following command:<\/p>\n<pre><code class=\"&quot;language-bash&quot;\">php bin\/console make:controller HomeController<\/code><\/pre>\n<p>This command creates a new controller called <code>HomeController<\/code> with an action <code>index()<\/code> which you can modify to render your first view.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You have configured your Symfony environment and are ready to start developing robust and scalable applications. Remember, Symfony is powerful thanks to its community and extensive documentation, which you can explore to delve deeper into specific details and advanced capabilities of the framework. If you have any questions or need additional assistance, please do not hesitate to <a href=\"https:\/\/nelkodev.com\/en\/contact\/\">contact me<\/a>.<\/p>\n<p>Continue to explore and learn as you progress in your Symfony project, and always make sure to keep best practices and security as your top priorities. Happy coding!<\/p>","protected":false},"excerpt":{"rendered":"<p>Symfony is one of the most popular frameworks for developing web applications in PHP. It offers a robust structure, an active community, and agile development. In this article, I will guide you step-by-step through setting up your Symfony project from scratch, ensuring that you can begin your development efficiently and effectively. Why [\u2026]<\/p>","protected":false},"author":1,"featured_media":28852,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2206,420],"tags":[205,1978,90,572,358,635,15,627,401,583],"class_list":["post-28851","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-blog","tag-blog","tag-comienza","tag-con","tag-configuracion","tag-guia","tag-inicial","tag-php","tag-proyecto","tag-proyectos","tag-symfony"],"_links":{"self":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/28851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/comments?post=28851"}],"version-history":[{"count":0,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/posts\/28851\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media\/28852"}],"wp:attachment":[{"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/media?parent=28851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/categories?post=28851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nelkodev.com\/en\/wp-json\/wp\/v2\/tags?post=28851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}