<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jairo Salazar</title>
    <description>The latest articles on DEV Community by Jairo Salazar (@jsv1280).</description>
    <link>https://dev.to/jsv1280</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F372506%2F64457a01-d699-41a4-a9a2-d9970cbea4e8.jpg</url>
      <title>DEV Community: Jairo Salazar</title>
      <link>https://dev.to/jsv1280</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jsv1280"/>
    <language>en</language>
    <item>
      <title>Configuring Symfony 2.7 App with Apache 2.4 HTTP Server on Ubuntu 20.04</title>
      <dc:creator>Jairo Salazar</dc:creator>
      <pubDate>Mon, 08 Nov 2021 04:48:53 +0000</pubDate>
      <link>https://dev.to/jsv1280/configuring-symfony-27-app-with-apache-24-http-server-on-ubuntu-2004-35b1</link>
      <guid>https://dev.to/jsv1280/configuring-symfony-27-app-with-apache-24-http-server-on-ubuntu-2004-35b1</guid>
      <description>&lt;p&gt;Normally, when we are configuring legacy applications is difficult to find accurate documentation about the used tools &lt;em&gt;(Dependencies, Libraries, Environment)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Currently, &lt;a href="https://symfony.com/releases" rel="noopener noreferrer"&gt;Symfony's version&lt;/a&gt; is &lt;strong&gt;5.3.10&lt;/strong&gt; thus actual documentation points out towards these newer versions from the framework even though previous documentation is still accessible &lt;em&gt;since version 2.7&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsymfony.com%2Fimages%2Fopengraph%2Fsymfony.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsymfony.com%2Fimages%2Fopengraph%2Fsymfony.png" alt="Symfony Logo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Avoid looking for hundred sites and freaking out whether any solutions work or work partially, in this post we are going a step to step to configure a Symfony 2.7 app in Apache 2.4 HTTP Server running in Ubuntu 20.04.&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Configure 000-default.conf
&lt;/h2&gt;

&lt;p&gt;I don't recommend editing &lt;code&gt;etc/apache2/apache2.conf&lt;/code&gt; because it is the main configuration file of Apache so if you broke that file probably your Apache will not work.&lt;/p&gt;

&lt;p&gt;Add the next code in &lt;code&gt;etc/apache2/sites-available/000-default.conf&lt;/code&gt; inside the block &lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;/code&gt; or create your own configuration file in &lt;code&gt;etc/apache2/sites-available&lt;/code&gt; if you do the last one remember run the script &lt;code&gt;a2ensite YOUR_CONFIGURATION_FILE.conf&lt;/code&gt; for Apache recognize it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;DocumentRoot /var/www/html/YOUR_PROJECT_NAME/web
&lt;span class="nt"&gt;&amp;lt;Directory&lt;/span&gt; &lt;span class="err"&gt;/var/www/html/YOUR_PROJECT_NAME/web&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      AllowOverride All
      Require all granted
      Allow from All
&lt;span class="nt"&gt;&amp;lt;/Directory&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href="https://httpd.apache.org/docs/2.4/mod/core.html#documentroot" rel="noopener noreferrer"&gt;DocumentRoot&lt;/a&gt;:&lt;/strong&gt; Apache will serve files located here&lt;br&gt;
&lt;strong&gt;&lt;a href="https://httpd.apache.org/docs/2.4/mod/core.html#directory" rel="noopener noreferrer"&gt;Directory&lt;/a&gt;:&lt;/strong&gt; Group of files where we are applying Apache rules&lt;br&gt;
&lt;strong&gt;&lt;a href="https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride" rel="noopener noreferrer"&gt;AllowOverride All&lt;/a&gt;:&lt;/strong&gt; Allow configuration from .htaccess&lt;br&gt;
&lt;strong&gt;&lt;a href="https://httpd.apache.org/docs/2.4/mod/mod_authz_core.html#require" rel="noopener noreferrer"&gt;Require all granted&lt;/a&gt;:&lt;/strong&gt; Access is allowed unconditionally.&lt;br&gt;
&lt;strong&gt;&lt;a href="https://httpd.apache.org/docs/2.4/mod/mod_access_compat.html#allow" rel="noopener noreferrer"&gt;Allow from All&lt;/a&gt;:&lt;/strong&gt; All hosts can access the server.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Finally, report Apache about that change and reload it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;service apache2 reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The previous configuration aimed to configure with mod_php/PHP-CGI if you want to configure with PHP-FPM, I recommend &lt;a href="https://symfony.com/doc/2.7/setup/web_server_configuration.html" rel="noopener noreferrer"&gt;visiting the official documentation or if you want to validate the Apache configuration for yourself&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Check &lt;code&gt;/var/log/apache2/error.log&lt;/code&gt; if something wrong happens&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2) File permission in &lt;code&gt;app/cache&lt;/code&gt; and &lt;code&gt;app/logs&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;app/cache&lt;/code&gt; and &lt;code&gt;app/logs&lt;/code&gt; folders must be accessed by web-server user &lt;code&gt;www-data&lt;/code&gt; &lt;em&gt;(This is the default username, keep in mind if your web server has a different username or group name you should replace it with the corresponding name)&lt;/em&gt; to Symfony Applications work as expected. I highly recommended changing the default group of the project's folder to &lt;code&gt;www-data&lt;/code&gt; &lt;em&gt;even &lt;code&gt;/var/www/&lt;/code&gt; to avoid relating this folder with the root user&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  a) Firstly, we change the group of &lt;code&gt;/var/www/&lt;/code&gt; and its children recursively
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo chown -R :www-data /var/www
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  b) Add your user Linux account to &lt;code&gt;www-data&lt;/code&gt; group.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo usermod -a -G www-data YOUR_USER
exit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to exit your current session or reload your terminal to save changes&lt;/p&gt;

&lt;h3&gt;
  
  
  c) Change folder's permission &lt;code&gt;app&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Sometimes &lt;code&gt;www-data&lt;/code&gt; must create logs and cache folders itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 775 -R app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can create manually the folders and specifically add the permissions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod 775 -R app/cache
chmod 775 -R app/logs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://symfony.com/doc/2.7/setup/file_permissions.html" rel="noopener noreferrer"&gt;Official Symfony Documentation approach this topic as well&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a table to let you know the possible combination when you are defining file permission in a Unix environment&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;r = Read&lt;br&gt;
w = Write&lt;br&gt;
x = Execute&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Permissions&lt;/th&gt;
&lt;th&gt;Owner&lt;/th&gt;
&lt;th&gt;Group&lt;/th&gt;
&lt;th&gt;Others&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;r&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;r&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;r&lt;/td&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;r&lt;/td&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This configuration is oriented to &lt;strong&gt;development environment&lt;/strong&gt; and you could start coding as fast as possible, if you need a production environment keep in mind Symfony recommendations and links that I had previously shown you and be careful exposing &lt;em&gt;ONLY&lt;/em&gt; your &lt;code&gt;web&lt;/code&gt; folder.&lt;/p&gt;

&lt;p&gt;I hope this could be very helpful to you, This is my first article written in English and oriented to developers. I expect your feedback or it is something wrong let me know to make the corresponding corrections. &lt;/p&gt;

</description>
      <category>symfony</category>
      <category>apache</category>
      <category>linux</category>
      <category>php</category>
    </item>
  </channel>
</rss>
