403 Access denied on My Single Page - http-status-code-403

I have looked at the various questions related to my question but haven't found any working answers
I have created a website,
All other directories are working perfectly.
But when I access this page: http://www.pakdostana.paks.pk/private-chat it says
403 access denied
All other pages are working,
My file permissions are 644 and I also try changing them to 755 and 777 but the error is same.
And I am using my own routing system.
Updated
I have an update when I directly access the folder with this URL: http://www.pakdostana.paks.pk/Chat/Private-Chat.php it works, but not with PHP routing system what can be error any guess!
Can anyone help me!
Best regards

It's not only the files permissions. You need permissions for the folder containing these files. The recommended permissions are 664 for files and 775 for folders.
As you don't specify which http server you are using nor the OS, I'm going to put an example Apache on linux.
cd /var/www/
sudo chgrp -R www-data html
find . -type f -exec chmod 664 {} \;
find . -type d -exec chmod 775 {} \;
What this does is:
Put you on the parent directory of default Apache's base path.
Change group ownership recursively for www-data and to html directory.
Find all files recursively and change permission to 664 (you may need to execute this with sudo).
Find all directories recursively and change permission to 775 (you may need tho execute this with sudo).
Hope this helps.

I want to tell everyone, every time I use Word Chat it says 403 access denied but when I removed this word it is working perfectly.
I don't know what was the error with this word

Related

When to use -type d-exec chmod 750 / 640 in docker

I've started to work with Docker for local development moving from installing everything on my mac to containers. Looking through a number of projects I regularly see the following shell commands, particularly
find /www -type d -exec chmod 750 {} \; \
find /www -type f -exec chmod 640 {} \;
Firstly, what are they trying to achieve, secondly what do the commands actually mean and lastly why/ when would you want or need to use this?
I recently duplicated and modified another project and found pulling these commands out seemed to make no difference (fair enough it was no longer based on the same base container.... but still).
Any glimmer of enlightenment would be greatly appreciated.
EDITS:
That handy link in the comments below to explain shell tells us:
What: find all the folders in /www and execute the chmod command, changing the permissions to 750
- still unsure of 750, and more importantly why you would do this.
The commands sets all files and directories to be readable and writable by the owner, and readable by the group but the files can not be executed by anyone.
You might want to read up on unix permissions in a bit more detail first.
find /www -type f -exec chmod 640 {} \;
Find all files under /www and set the user to have read, write access (6) and the group to have read access (4). Other users have no access (0).
find /www -type d -exec chmod 750 {} \;
Find all directories under /www and set the user to have read, write and execute permissions (7) and the group to have read and execute permissions (5) to those directories. Other users have no permissions (0).
The \; after each find terminates the -exec command and must be escaped when run in a shell so it is not interpreted as a regular ; which is the end of the shell command. This can also be achieved with a + which is easier to read as it doesn't need to be escaped and more efficient. The efficiency can cause differences in output, if you are relying on the stdout/stderr somewhere else.
Execute permissions on a directory mean that a user can change into the directory and access the files inside. As a directory can't be executed in the sense of a executable file, the execute bit was overloaded to mean something else.
The link Cyrus posted to explainshell.com is an excellent tool as well.

Access forbidden to website after scp transfer

I used scp2 to tranfer a folder from windows to ubuntu.
I executed the scp2 process as part of a gulp execution.
My project was successfuly transfered to the server but when I tried to navigate to the site from the browser I encountered a 403 Forbidden message.
The problem is that the scp2 process didn't grant permissions to the newly created folder and files.
When I execute the following lines on the server it's work fine:
find ProjFolder -type d -exec chmod 755 {} \;
find ProjFolder -type f -exec chmod 644 {} \;
My question is: how can I transfer my project from my local machine to the server without the need to repeatedly write the permission orders?
To preserve permissions try to use rsync, it has a lot more benefits besides keeping ownership, permissions and incremental copies:
rsync -av source 192.0.2.1:/dest/ination
EDIT [according to comments]:
This works well for transferring between 2 Linux systems but doesn't seem to work for Windows -> Linux transfer. Apparently PuTTY seems to work best for transfers involving Windows on one side and Linux on another

How do I change permissions for a folder and its subfolders/files? [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 months ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
How do I change the permissions of a folder and all its subfolders and files?
This only applies to the /opt/lampp/htdocs folder, not its contents:
chmod 775 /opt/lampp/htdocs
How do I set chmod 755 for all of the /opt/lampp/htdocs folder's current contents, as well as automatically in the future for new folders/files created under it?
The other answers are correct, in that chmod -R 755 will set these permissions to all files and subfolders in the tree. But why on earth would you want to? It might make sense for the directories, but why set the execute bit on all the files?
I suspect what you really want to do is set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:
To change all the directories to 755 (drwxr-xr-x):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
Some splainin': (thanks #tobbez)
chmod 755 {} specifies the command that will be executed by find for each directory
chmod 644 {} specifies the command that will be executed by find for each file
{} is replaced by the path
; the semicolon tells find that this is the end of the command it's supposed to execute
\; the semicolon is escaped, otherwise it would be interpreted by the shell instead of find
Check the -R option
chmod -R <permissionsettings> <dirname>
In the future, you can save a lot of time by checking the man page first:
man <command name>
So in this case:
man chmod
If you want to set permissions on all files to a+r, and all directories to a+x, and do that recursively through the complete subdirectory tree, use:
chmod -R a+rX *
The X (that is capital X, not small x!) is ignored for files (unless they are executable for someone already) but is used for directories.
You can use -R with chmod for recursive traversal of all files and subfolders.
You might need sudo as it depends on LAMP being installed by the current user or another one:
sudo chmod -R 755 /opt/lampp/htdocs
The correct recursive command is:
sudo chmod -R 755 /opt/lampp/htdocs
-R: change every sub folder including the current folder
To set to all subfolders (recursively) use -R
chmod 755 /folder -R
chmod 755 -R /opt/lampp/htdocs will recursively set the permissions. There's no way to set the permissions for files automatically in only this directory that are created after you set the permissions, but you could change your system-wide default file permissions with by setting umask 022.
You might want to consider this answer given by nik on Super User and use "one chmod" for all files/folders like this:
chmod 755 $(find /path/to/base/dir -type d)
chmod 644 $(find /path/to/base/dir -type f)
Here's another way to set directories to 775 and files to 664.
find /opt/lampp/htdocs \
\( -type f -exec chmod ug+rw,o+r {} \; \) , \
\( -type d -exec chmod ug+rwxs,o+rx {} \; \)
It may look long, but it's pretty cool for three reasons:
Scans through the file system only once rather than twice.
Provides better control over how files are handled vs. how directories are handled. This is useful when working with special modes such as the sticky bit, which you probably want to apply to directories but not files.
Uses a technique straight out of the man pages (see below).
Note that I have not confirmed the performance difference (if any) between this solution and that of simply using two find commands (as in Peter Mortensen's solution). However, seeing a similar example in the manual is encouraging.
Example from man find page:
find / \
\( -perm -4000 -fprintf /root/suid.txt %#m %u %p\n \) , \
\( -size +100M -fprintf /root/big.txt %-10s %p\n \)
Traverse the filesystem just once, listing setuid files and direct‐
tories into /root/suid.txt and large files into /root/big.txt.
Use:
sudo chmod 755 -R /whatever/your/directory/is
However, be careful with that. It can really hurt you if you change the permissions of the wrong files/folders.
chmod -R 755 directory_name works, but how would you keep new files to 755 also? The file's permissions becomes the default permission.
For Mac OS X 10.7 (Lion), it is:
chmod -R 755 /directory
And yes, as all other say, be careful when doing this.
For anyone still struggling with permission issues, navigate up one directory level cd .. from the root directory of your project, add yourself (user) to the directory and give permission to edit everything inside (tested on macOS).
To do that you would run this command (preferred):
sudo chown -R username: foldername .*
Note: for currently unsaved changes, one might need to restart the code editor first to be able to save without being asked for a password.
Also, please remember you can press Tab to see the options while typing the username and folder to make it easier for yourself.
Or simply:
sudo chmod -R 755 foldername
but as mentioned above, you need to be careful with the second method.
There are two answers to finding files and applying chmod to them.
The first one is find the file and apply chmod as it finds (as suggested by #WombleGoneBad).
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
The second solution is to generate a list of all files with the find command and supply this list to the chmod command (as suggested by #lamgesh).
chmod 755 $(find /path/to/base/dir -type d)
Both of these versions work nicely as long as the number of files returned by the find command is small. The second solution looks great to the eye and is more readable than the first one. If there are a large number of files, the second solution returns an error: Argument list too long.
So my suggestion is
Use chmod -R 755 /opt/lampp/htdocs if you want to change the permissions of all files and directories at once.
Use find /opt/lampp/htdocs -type d -exec chmod 755 {} \; if the number of files you are using is very large. The -type x option searches for a specific type of file only, where d is used for finding the directory, f for file and l for link.
Use chmod 755 $(find /path/to/base/dir -type d) otherwise
Better to use the first one in any situation
You want to make sure that appropriate files and directories are chmod-ed/permissions for those are appropriate. For all directories you want
find /opt/lampp/htdocs -type d -exec chmod 711 {} \;
And for all the images, JavaScript, CSS, HTML...well, you shouldn't execute them. So use
chmod 644 img/* js/* html/*
But for all the logic code (for instance PHP code), you should set permissions such that the user can't see that code:
chmod 600 file
I think Adam was asking how to change the umask value for all processes that are trying to operate on the /opt/lampp/htdocs directory.
The user file-creation mode mask (umask) is used to determine the file permissions for newly created files. It can be used to control the default file permissions for new files.
so if you will use some kind of FTP program to upload files into /opt/lampp/htdocs you need to configure your FTP server to use the umask you want.
If files / directories need be created, for example, by PHP, you need to modify the PHP code:
<?php
umask(0022);
// Other code
?>
If you will create new files / folders from your Bash session, you can set umask value in your shell profile ~/.bashrc file.
Or you can set up a umask in /etc/bashrc or /etc/profile file for all users.
Add the following to the file:
umask 022
Sample umask Values and File Creation Permissions
If umask value set to User permission Group permission Others permission
000 all all all
007 all all none
027 all read / execute none
And to change permissions for already created files, you can use find.
You can change permissions by using the following command:
sudo chmod go+rwx /opt/lampp/htdocs
Use:
sudo chmod -R a=-x,u=rwX,g=,o= folder
Owner rw, others no access, and directory with rwx. This will clear the existing 'x' on files.
The symbolic chmod calculation is explained in Chmod 744.
It's very simple.
In Terminal, go to the file manager. Example: sudo nemo. Go to /opt/, and then click Properties → Permission. And then Other. Finally, change to create and delete and file access to read and write and click on button Apply... And it works.

Apache and linux file permissions can't browse file or directories

I just copied my magento site over to a local server running CentOS 5.4. The browser said it can't locate the location of the stylesheets. The stylesheets are within /skin/frontend/my_new_interface/design2/css. I tried to view in the browser and I can't view any of the files within the css directory. I verified a million times that I'm typing in the correct location. I can view files within /skin/frontend/my_new_interface/design2. Can't browse directories within browser however.
I typed in ls -l css
and get:
-rwxr-xr-x 1 apache apache
listed for all the files
I tried chmod -R 755 and the directories
I changed the apache conf Options Indexes
But still when I browse the directories I get Forbidden. However, in another fresh installation of magento in the same www dir, I am able to browse directories. As far as I can tell both installations have same ownership and permissions.
I also tried
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
which was recommended in the magento wiki
I've just run out of ideas.
You'll need to add Options +Indexes to your httpd.conf or in a .htaccess file in the css/ folder to view the folder contents through the browser. This is bad ju-ju though. Do you really need to switch this on, or can you keep doing it through the ssh session?
On the CSS file note, can you type pwd when in the CSS directory? That'll help us confirm you've got the correct location. Do you get "Forbidden" when you try to view the CSS file directory, or just when you try to view the directory contents?
The file permission were set up correctly. I figured out that the .htaccess had a rewrite rule set for the css directory that was causing the problem. I inherited this site and am still not aware of all the little modifications done throughout.

What are the permissions I need?

My folder at:
/usr/local/www/.ext_env_vars
has a bunch of files in it that my app needs to read. The user is 'webapp'
So, I changed the perms like so:
chmod -R 400 .ext_env_vars
chown -R webapp.webapp .ext_env_vars
The application can't read these. However, when I chmod 777, they are read by the app. So, it isn't that I have a path problem. Seems to be permissions only.
So, what would I have to do to the permissions to make webapp be able to read those files in the .ext_env_vars folder?
Thanks
Eric
A directory needs to be "executable" to access it. Try:
chmod 500 .ext_env_vars

Resources