Francesco Arreghini
Francesco Arreghini

Reputation: 99

how configure symfony on my VPS

I created a symfony project in my local PC with xampp and I created a git repository.It start correctly so i tryed to move it to my VPS. I clone my repository in my VPS but i see that now I can see all file and folder to my public project. I have left read and other permission to app and src and other file but i think is not normal that i can see all file .. if I share(open port) my xampp local it don't happen. There is some configuration or other that I need to do when I clone my symfony project??

My configuration /etc/apache2/apache.conf

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

In /etc/apache2/sites-avaiables/rasp.conf I follow the symfony guide

 DocumentRoot /var/www/html/conticasa/web
<Directory /var/www/html/conticasa/web>
    # enable the .htaccess rewrites
    AllowOverride All
    Require all granted
</Directory>

ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined

I enabled rasp.conf file and disabled the default file. Unfortunately is happened . I see always all my folder

i try to

Upvotes: 1

Views: 295

Answers (1)

dbrumann
dbrumann

Reputation: 17166

It sounds like a mix of problems.

First of all your web server has a so called document root. That is the folder the web server will look into when you go to your website.

So for example you have your project in /var/www/myapp so below myapp/ you have src/, vendor/, web/ and so on. Let's also assume the web server document root is set to the very same folder. Now when you visit your website you will be able to see all folders instead of the site you built.

The solution to this is to point your web server's document root to the web/-folder inside myapp/, so in our example /var/www/myapp/web (with Symfony 4 the web/-folder was renamed to public/, so just replace it with that).

The second problem are some security settings in your web server to make sure when someone visits your website they don't have access to sensitive data. It is quite common to use .htaccess file to control access inside your application, but nowadays it is best practices to configure this inside your web server. When you use Apache 2 you will likely find the configuration for your site in /etc/apache2/sites-enabled/* (it might vary based on what Linux system your VPS is running). Inside you should see a configuration where you can replace the existing settings with something this:

DocumentRoot /var/www/myapp/web
<Directory /var/www/project/web>
    AllowOverride None
    Order Allow,Deny
    Allow from All

    FallbackResource /app.php
</Directory>

This says, whenever tries to access something that does not exist, e.g. one of your routes like www.example.com/blog/post/123, it will fall back to Symfony's front controller app.php and route this request through your application, making it display your blog post with the id 123.

Symfony has a documentation page that helps you with a good default configuration for Apache and nginx (another popular web server software): https://symfony.com/doc/3.4/setup/web_server_configuration.html

Also, feel free to open a follow up question if you have trouble making these settings work for you and be sure to add the config file to the question to make it easier for us to help you out with the specific things you have to change.

Upvotes: 3

Related Questions