Access forbidden in /web directory Symfony2 project - apache

I'm working on a Symfony2 project at local server without any virtual hosting or something else. After I run the command php app/console assets:install --symlink, clear the cache and refresh the page none styles or javascript or images are loaded. Inspecting the source code and trying to access any of those assets I get this error:
You don't have permission to access
/cmplatform/web/bundles/clanmovilcommon/css/bootstrap.min.css on this
server.
What I need to change in my /etc/httpd/conf/httpd.conf to fix that problem? It's related to .htaccess problem or what?

This error is due to the user that you are currently logged in as not having correct to write to the /cmplatform/web directory. Or you have not got the root path set correctly in your apache.conf.
Can you confirm other pages / assets are being served correctly.
Take a look at who owns the directory and either adjust the write permissions or add your user / web server to own the directory or into the group.
This is quite a common issue - and care needs to be taken to ensure that write permissions for web, cache and log directories are set correctly to allow command line and web server (e.g. apache / nginx) users.
See http://symfony.com/doc/current/book/installation.html - permissions for some tips about fixing this.

Related

How to disable the download of files in an Apache2 webserver?

I took over a website which I'm supposed to admin and somebody brought to my attention that certain Indexes and Files are available, which shouldn't be. I will be using dummy names.
You were able to access example.com/intern before, but I changed a line in /etc/apache2/apache2.conf according to this https://stackoverflow.com/a/31445273 . This worked partly, as I get a 403-Forbidden when I now navigate to example.com/intern and that's basically what I want.
However the directory intern governs a file called file.php.bak aswell as file.php. When I navigate to example.com/intern/file.php I get a white website. I am however not sure, if you are able to access file.php in another way, because the site does load and I don't get a 403 like before. What is way worse and the reason I am struggling with this is: If I go to example.com/intern/file.php.bak then my Browser (Firefox) offers me to download file.php.bak, which I can read in plaintext. I want all files in intern to not be accessible via the website, but I have no idea how to do this. Can anybody help?
Things I've tried:
Removing the Indexes from the apache2.conf file like mentioned above. It only puts the 403 on the directory itself and not recursively for all the files in it.
Writing a .htaccess file as described here: https://fedingo.com/how-to-prevent-direct-file-download-in-apache-server/ and putting it in intern with the same result as in 1)
Putting an empty index.html file in the intern directory. This leads to no more 403 in example.com/intern, but the download on example.com/intern/file.php.bak is still possible. I've also tried index.php with the same result.
File System:
The application runs from /var/www/application which is also the folder for the /var/www/application/index.php I want to use. The /var/www/application/intern directory is also there. While it isn't browsable anymore, the files in it still are accessible. /var/www/application/intern/file.php can be navigated to via example.com/intern/file.php, but it seems like it can't be downloaded or read as it results in a white page. /var/www/application/intern/file.php.bak can however be downloaded via example.com/intern/file.php.bak.
Let's say Apache document root is set to DocumentRoot "/folder_one/folder_two"
Placing files in a folder_one will prevent people browsing your apache server and requesting the files directly.
Place index file in folder_two and include some code such as PHP to tell apache to include whatever files you want from folder_one.
In this manor Apache will still be able to serve whatever files you want from folder_one and people will not be able to request the files directly as the are located in a directory above the Apache document root.

Symfony2 cache directory permissions

Sorry, I'm new to Symfony.
I think I've tried everything here. I'm trying to install a Symfony v2.8 application on a new machine. When I'm trying to access the application I'm getting exceptions stating lack of permissions to access either cache or logs directory. Cache and logs directories are writeable though - mask 777 set for both.
Also there seems to be a process that creates entries in the cache directory as it fills in with files. The problem seems to be that the web server can't access them - but why?
getfacl for both cache and logs directories returns this:
# owner: apache
# group: apache
user::rwx
user:apache:rwx
group::rwx
mask::rwx
other::rwx
default:user::rwx
default:user:apache:rwx
default:group::rwx
default:mask::rwx
default:other::rwx
Any suggestions would be greatly appreciated. Thanks!
Check that you logs and cache are being put in the correct location. Symfony has "two" major development environments (dev and prod). They (env) write logs and caches in two separate folders. Check the getCacheDir() and getLogDir() methods in the app/AppKernel.php.

After uploading MVC website to the folder httpdocs from FIlezilla and browsing it the showing Internal Server error

I am getting 500 Internal server.I have uploaded files to the server using Filezila .and when i am browsing it.Its showing internal server error.
Whats is the permission of your files and directory's which you have uploaded in your account. Also check your .htaccess file code.
There may be several reasons , let me list few which i think might be the reason.
1) Check the folder and file permissions on the hosting . Folder permission should be 755 and the file permission should be 644 by default to work on
2) If there is any .htaccess file try to remove that file and check again reloading (Note : if you are using cPanel try selecting show hidden files in file manager to view the .htaccess file )
3) whether your db is been properly configured in the configuration file of your MVC site ( however if it is the reason the page will will throw some db connectivity error . just in case if it is i am asking you to check )
If that helps, update me . If not, Kindly post the error log which can be taken in cPanel or if you are using different solution ask your hosting provider on how to view error log.
The best and universal approach if you have root access on the server would be to look for more information in the web server log:
/usr/local/apache/logs/error_log
If you do not have root access, you can check the Error log in cPanel -> Errors, it will provide you with more details on what the problem is.

Install Symfony on remote server

I'm trying to evaluate Symfony 2 (2.1.7). I'm installing it following the download instructions on an EC2 instance that is already running PHP 5.3.20 on Apache.
I'm stuck on the second step of the README.md: "Access the config.php script from a browser". The readme assumes a local installation and provides a sample URL to the localhost: http://localhost/path/to/symfony/app/web/config.php.
Since I'm on a remote server, I try to access the config.php file using the relevant URL: http://mysite.com/Symfony/app/check.php, which returns this message:
Forbidden
You don't have permission to access /Symfony/app/check.php on this server.
I tried to apply the answer from How do I access to symfony config.php remotely? by adding what PHP reports back as my REMOTE_ADDR, but that doesn't change the message.
What do I do now?
In symfony, the web folder is supposed to be your webroot. So, if you want to access \project\web\config.php, you should point your browser to http://www.example.com/config.php.
If that doesnt work, apache is probably configured incorrectly. make sure it it is pointed at your web directory, not your project directory.
edit As you mention in your question, you will also need to edit the config.php file to allow remote access. You can comment those lines out, or add your IP to the whitelist.
edit2 Many webhosts don't allow you to specify your webroot. In that situation, you can put the Symfony files in a different directory and create a symlink between the Symfony web directory and your webroot.

Prevent access to files from Apache without .htaccess

(LAMP server configuration)
As a workaround for another problem, I need PHP to be able to access local files, but prevent these files from being served over http by Apache.
Normally, I would just use .htaccess to accomplish this, however due to institutional restrictions, I cannot. I also can't touch php.ini, although I can use php_ini_set within php.
As a creative solution, I thought that if php executes as its own linux user (not as apache) I could use normal chown's and chmod's to accomplish this.
Again, the goal is simply to have a directory of files that apache will not display, but php can access.
I'm open to any suggestions.
Put the files outside of your web accessible root (DocumentRoot), but keep them accessible via PHP.
Suggestion:
/sites
/sites/my.site.com
/sites/my.site.com/data // <-- data goes here
/sites/my.site.com/web // <-- web root is here
Here's a thought. Set the permissions on the files to be inaccessible to even the owner, then when PHP needs them, chmod() then, read them, then chmod() them back to inaccessible.