Lamp Server 403 Forbidden - php

Hi I just installed ubuntu alongside my Win 7 and I have been using xampp and am very familiar with it, but I just installed lamp and am using the apache2, php, and mysql from terminal and I copied a web folder over from my xampp side and it is saying that I do not have permission to access that file.
I know that on my pc I had some htaccess files but on Ubuntu I am yet to figure out how to view those. Is this a product of those .htaccess files or something else?

That happens if you install WAMP/XAMMP on system partition.

so you copied the files form windows to linux?
sounds like a classic file permissions problem.
per default the www folder is in /var/www, so you can simply set the owner of this folder to the apache user which is called www-data, run this in terminal:
sudo chown -R www-data:www-data /var/www
but now you will no longer be able to write to those files yourself, because they are owned by www-data. checkout this answer for more details and how to get write access: https://askubuntu.com/a/51337
or you make it writeable for everyone (which is a bad idea): sudo chmod -R 777 /var/www
about editing .htaccess files:
I don't use linux with a graphical user interface, but you can edit them with the terminal editor of your choice, on ubuntu you have nano installed by default:
nano /var/www/.htaccess
or if you want a more advanced editor, I suggest vim https://help.ubuntu.com/community/VimHowto
vim /var/www/.htaccess

Related

linux (ubuntu) apache www folder access issue

I'm a newbie in Linux, just installed ubuntu 14.04 and wanted to install WAMP (MAMP), I followed a youtube tutorial to install php5, apache2, mysql and phpmyadmin. Installed successfully both http://localhost and http://localhost/phpmyadmin works fine logged in successfully.
now I wanted to add some files and folders to apache www folder which is located at /var/www but cant create files or folders. I'm a Windows user where I usually keep all my PHP work in www folder.
I would like to know if there is a way to use any-other folder as www folder or how to create folders and files in that www folder. I reckon its permission issues, since being a newbie don't know how to fix that.. please help
Regards
Ubuntu 14.04 runs apache as user www-data, you can change to this user using the command in terminal (shell)
sudo su
This will make you root and have access to /var/www directory, and you will be able to create files and directories. Say you had a directory of images containing img1.jpg, img2.jpg, etc. in say /home/user1/images
as root you could
sudo su <- change to the document folder
cd /var/www <- change to the document folder
cp /home/user1/images/ . <- copy what you need to copy
chown -r www-data images/ <- give the web server read/write permission to the folder / files
which will let you do access the images via a browser via the url
http://localhost/images/img1.jpg
The reason is that apache runs under different user (given your distro most likely www-data), while /var/www belongs either to the user or root.
So if you want to allow apache to write somewhere you have to give it permissions.
Since it is not good practice to give apache full permission to your disk, usually you would have a special directory where it can upload data.
For example creating directory
/var/www/myProject/uploaded
and then giving permission to all to write there
chmod 777 /var/www/myProject/uploaded
Alternatively you can change the owner/group with chown.

phpMyAdmin "Cannot load or save configuration"

I have been trying to setup phpMyAdmin on a macbook pro running yosemite 10.10.2. I have created a config folder in phpmyadmin and have given it the permissions required:
chmod o+wr ~/Sites/phpmyadmin/config
However, when I then go onto "localhost/phpmyadmin/setup" I get an error:
Cannot load or save configuration
Please create web server writable folder config in phpMyAdmin top level
directory as described in documentation. Otherwise you will be only able to
download or display it.
(I have tried attaching an image, but can't due to my reputation points)
I have tried resetting the permissions, tried deleting and recreating the folder. Tried redownloading the phpmyadmin zip but nothing seems to work.
Could anyone kindly advise me what I am doing wrong and how I am best placed to solve this issue?
I have had similar issue on my Ubuntu 16.04. I made a research and in the end I found a resolution of the issue. Maybe my case solution will help somebody else.
Background: For security reasons I have non privileged user and group apache:apache (sudo groupadd apache | useradd -g apache apache). They are preset by directives (User apache; Group apache) in /etc/apache2/apache2.conf. This user apache:apache owns Apache2 main directory (sudo chown -R apache:apache /etc/apache2) and some other files, for example: sudo chown -R apache:apache/etc/phpmyadmin/htpasswd.setup
In this manual: http://docs.phpmyadmin.net/en/latest/setup.html - I found that...
Debian and Ubuntu have changed way how setup is enabled and disabled,
in a way that single command has to be executed for either of these.
To allow editing configuration invoke:
/usr/sbin/pma-configure
To block editing configuration invoke:
/usr/sbin/pma-secure
Note! In the content of the two files listed above we talk about /var/lib/phpmyadmin/config.inc.php instead of /etc/phpmyadmin/config/config.inc.php. It was the key.
In my case I was modified the content of these scripts (see below) and now I can use localhost/phpmyadmin/setup properly.
/usr/sbin/pma-configure:
#!/bin/sh
echo "Unsecuring phpMyAdmin installation..."
echo "Setup script can now write to the configuration file."
echo
echo "Do not forget to run /usr/sbin/pma-secure after configuring,"
echo "otherwise your installation might be at risk of attack."
sudo sudo chown -R apache:apache /var/lib/phpmyadmin/config.inc.php
chmod 0660 /var/lib/phpmyadmin/config.inc.php
/usr/sbin/pma-secure:
#!/bin/sh
echo "Securing phpMyAdmin installation..."
echo "Setup script won't be able to write configuration."
sudo sudo chown -R root:root /var/lib/phpmyadmin/config.inc.php
chmod 0640 /var/lib/phpmyadmin/config.inc.php
I was able to use phpMyAdmin in my ~/Sites directory and remove the warning by giving the config folder writable access as such:
chmod 756 ~/Sites/phpmyadmin/config
Does it work if you try setting up PHPMyAdmin in system root versus user root? On OSX that server web root should be under /Library/WebServer/Documents?
I used this guide when I set mine up, and it works fine, although I did not use Sites as my root.
http://www.dingendoen.com/osx-installs-configuration-examples/install-apache-mysql-php-on-osx-yosemite/
For local development, changing permissions worked for an OSX Sierra install:
sudo chown -R _www:_www ~/Sites/phpmyadmin

Can not access copied filesin var/www ubuntu

I'm on Ubuntu 14.10 .
I copied a subdirectory which has project files (php, html, css) from xampp/htdocs on my Windows PC into /var/www/ of my ubuntu.
However, when I access those files from browser (I can not see the directory listing), I get 402 Object not found. Hence that, I installed Apache2,mysql 5.5 and phpmyadmin and also conducted update apt-get update for the system and I granted chmod-R 777 access to /var/www.
Any idea what might be the problem?
You must put the files on /var/www/html
Then try sudo chmod -R 755 /var/www/html

Unpacking the update... Could not create directory. Wordpress

When I instal nextgen-gallery plugins. This error message appears
Downloading update from https://downloads.wordpress.org/plugin/nextgen-gallery.zip…
Unpacking the update…
Could not create directory.
How can I fix this problem ?
This is a permissions issue. Ensure the directory is writable by apache. Plugins are unpacked into the wp-content/plugins directory, so I would first attempt writing to the directory as apache:
sudo -u apache touch /path/to/wp-content/plugins/test.txt
Set permissions accordingly to correct the issue. You can read about permissions here: https://www.pluralsight.com/blog/it-ops/linux-file-permissions
You can read about the correct file permission scheme for Wordpress here: https://wordpress.org/support/article/changing-file-permissions/
#skrilled and #knutole's answer was great but I found that when attempting to fix the issue on the plugins folder, everything was ok and the answer did not work for me.
If anyone else has this issue, try looking at the upgrades folder also. This folder (from what I can see) is used as a folder to store temporary files for when WP upgrades or plugin updates are being ran.
If you simply receive the message stating 'Could not create directory' and there is no path specified, it could actually be talking about the upgrades folder.
Most likely, if you have configured it correctly, the http server associated to your wordpress site belongs to the group www-data. That's how one should configure it correctly.
Try members www-data and ps aux | grep www-data to be sure. In the latter command you should see on the last columns either nginx or apache.
In this case, you just need to set that group to the directory
sudo chgrp -R www-data <your_wordpress_root_dir>/
and then add full group permissions to such directory
sudo chmod -R g+rwx <your_wordpress_root_dir>/
Now it works perfectly :)
for nginx people
if you have php-fpm installed you have to tell it that its user and group is nginx. /etc/php-fpm.d/www.conf . find user which is assigned to apache by default and change it to nginx. also do it for group. then run this command :
sudo service php-fpm restart
also inside of your wordpress directory execute these commands
sudo chown nginx:nginx * -R
sudo usermod -a -G nginx username
change username into what your current username is.
yet you have to apply propper permissions.
run these commands inside your wordpress directory
sudo find . -type f -exec chmod 664 {} +
sudo find . -type d -exec chmod 775 {} +
If you are using vsftpd as your FTP server and have enabled passive connections, you need to add pasv_promiscuous=YES to /etc/vsftpd/vsftpd.conf.
I was having a similar issue. It started with me trying to update a plugin on a migrated WP install. I didn't get it, all my permissions were EXACTLY the same as the old server. In my situation, I started to see that not much was working properly. I couldn't install/delete plugins or themes as well as uploading media would error out. Then I found the fix via some research.
If you are still having this issue, and changing permissions DID NOT fix the problem try this:
Go in to your hosting control panel and find your hosting settings, wherever you can edit your scripting settings. In Plesk (as in my example), this would be under Websites & Domains. Click on your domain name at the bottom. On the next screen, where it says "PHP support (run as..." change the dropdown from "Apache module" over to "FastCGI application". Everything should be fixed up now!
(Re)setting the permissions via ftp didn't make a difference for me either. There is no SSH available, so I had to log in the control panel (directadmin in my case), the File Manager where I could "Reset Owner" to "File ownership reset" the /wp-contents directory.
I'm running Nginx with Wordpress. I deleted the upgrade folder in wp-content and then ran the upgrade from the wordpress GUI again. I noted the linux user for the upgrade folder created was www-data. I then did a {sudo chmod -R www-data:www-data .} Ran the upgrade again from the GUI and it worked.
Probably need to change the permissions on most of the folders so they can't be modified by www-data but I'll figure that out tomorrow.
A permission issue, make sure apache (www-data) has write permissions.
All the above is great, but I think you missed the simplest issue. Your website is using more space than it has allotted, and therefore it is broke. Wordpress makes more files as is in use. If you are on the margin of going over, a simple overnight issue where you did nothing is possible. Go to bed, everything fine. In the morning website is broke.
I own my websites so I go into the reseller part of Hostmonster or Hostgator (I have sites on both hosting platforms) and I reallocate more space and the problem goes away usually. Try that first, or look into it before messing around with permissions. If you changed a permission and the issue came up, could be permissions, otherwise, check this first.
I had the same issue when I tried to install wp plugin(s). However, I managed to solve the problem with the following command:
sudo wp plugin install [plugin name] --allow-root

PhpDocumentor ubuntu installation

I use Ubuntu 11.10, and I want install phpdocumentor. I use the tutorial How to install PhpDocumentor on Ubuntu. But:
If you navigate to http://localhost/PhpDocumentor/ (note that the URL is case sensitive) you will find the installation ready to run.
I get a 404 Page. Maybe something should be set up in virtual - hosts?
Perhaps check the file permissions on the files and directories under /var/www. Like how www-data "needs to own" the output directory where files get written by apache, it's possible the file permissions on the webpage files need to be owned also... they might not accessible due to being installed by root via sudo. So, if /var/www and the phpdocumentor files under it are not owned by www-data, try changing the ownership (sudo chown -R www-data /var/www/PhpDocumentor) and see if that solves it.
Of course, if you don't see the /var/www/PhpDocumentor directory at all, then that's the problem... the "sudo pear config-set data_dir /var/www" command earlier in the tutorial should have made sure that the installation puts the files there.

Categories