Raspberry Pi webserver, can anyone help?

Permabanned
Joined
21 Sep 2013
Posts
1,336
My boyfriend is rubbish so can someone help me please.

I have a new pi, 32GB SD Card class 10. Installed 2013-09-25-wheezy-raspbian. On the config page I expanded the file system, overclocked, enabled ssh

The I went onto do -

Code:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2

I'm able to see the welcome page via local ip (192.168.1.3)

It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

I'm also able to see this externally as have setup port 80 and ssh via port 22 on my router with a dns.

My issue is trying to log into the pi using Winscp I'm able to log in but can not change anything as I get error code 3. Does anyone have any advice or have I missed a step? Google is confusing me a little. I did this all once but I've lost my notes and the boyfriend is not helping me.

Thanks
 
WinSCP error code 3 is a permission denied error

http://winscp.net/eng/docs/sftp_codes

when you say you are unable to change anything I'm assuming you mean you are unable to change the web pages file (otherwise why would you mention all that)

I'll take a guess at where you problem lies.

You are logging into the pi (through) winSCP as the default 'pi' user.
This user wont have permission to edit/add/delete files in /var/www/ which is where the webserver gets its files.
You should copy the files you want to add to the pi to /home/pi. Then move them into /var/www using the sudo command, if you using the pi via the graphical interface then I'm not entirely sure how you move files with elevated privileges (I only ever use the command line).
 
Apache uses the 'www-data' group so make sure the group has been setup correctly (use Putty or similar) -
Code:
cat /etc/group
If not then add the group -
Code:
sudo groupadd www-data

And then you want to add 'pi' user to the group -
Code:
sudo gpasswd -a pi www-data
and change directory own and assign correct permissions -
Code:
chown www-data:www-data /var/www
chmod 775 /var/www

This should get you going. However, there's a fair few tutorials around on setting up various web-servers under Raspbian (and hundreds if you search around Debian and web-servers) - so have a good read of a few.

Also depending on what you're planning to do with it, it might be worth looking at one of lighter (and generally offer better performance over Apache) web-servers like Nginx - it's no more harder to setup than Apache tbh.
 
Apache uses the 'www-data' group so make sure the group has been setup correctly (use Putty or similar) -
Code:
cat /etc/group
If not then add the group -
Code:
sudo groupadd www-data

And then you want to add 'pi' user to the group -
Code:
sudo gpasswd -a pi www-data
and change directory own and assign correct permissions -
Code:
chown www-data:www-data /var/www
chmod 775 /var/www

This should get you going. However, there's a fair few tutorials around on setting up various web-servers under Raspbian (and hundreds if you search around Debian and web-servers) - so have a good read of a few.

Also depending on what you're planning to do with it, it might be worth looking at one of lighter (and generally offer better performance over Apache) web-servers like Nginx - it's no more harder to setup than Apache tbh.

I tried and i'm lost

Code:
login as: pi
[email protected]'s password:
Linux raspberrypi 3.6.11+ #538 PREEMPT Fri Aug 30 20:42:08 BST 2013 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Oct 22 12:35:30 2013 from peteslimbook-pc
pi@raspberrypi ~ $ cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:pi
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:pi
fax:x:21:
voice:x:22:
cdrom:x:24:pi
floppy:x:25:
tape:x:26:
sudo:x:27:pi
audio:x:29:pi
dip:x:30:
www-data:x:33:pi
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:
video:x:44:pi
sasl:x:45:
plugdev:x:46:pi
staff:x:50:
games:x:60:pi
users:x:100:pi
nogroup:x:65534:
libuuid:x:101:
crontab:x:102:
pi:x:1000:
ssh:x:103:
ntp:x:104:
netdev:x:105:pi
input:x:999:pi
messagebus:x:106:
lpadmin:x:107:
fuse:x:108:
lightdm:x:109:
indiecity:x:1001:root
spi:x:1002:pi
gpio:x:1003:pi
ssl-cert:x:110:

Code:
pi@raspberrypi ~ $ sudo gpasswd -a pi www-data
Adding user pi to group www-data
pi@raspberrypi ~ $ chown www-data:www-data /var/www
chown: changing ownership of `/var/www': Operation not permitted
pi@raspberrypi ~ $ chmod 775 /var/www
chmod: changing permissions of `/var/www': Operation not permitted
 
Code:
pi@raspberrypi ~ $ sudo gpasswd -a pi www-data
Adding user pi to group www-data
pi@raspberrypi ~ $ chown www-data:www-data /var/www
chown: changing ownership of `/var/www': Operation not permitted
pi@raspberrypi ~ $ chmod 775 /var/www
chmod: changing permissions of `/var/www': Operation not permitted

I know you got it working but I thought I would explain why you were having problems and why what that video did isn't the best.

The chown and chmod commands failed because pi (you) doesn't own the file, you can't change the ownership and permissions of files you don't already own. Otherwise you could just change every file to be owned by you and gain access to any protected file you like.

What you needed to do was use the sudo command to run those commands, like in the video. sudo allows you to run commands as the privileged user. Which users are allowed to use the sudo command itself can be configured. The OS release you are using comes with the user pi configured to be allowed to use the sudo command.

The video changed the ownership on the /var/www directory to be owned by pi, while this works it isn't the proper approach.

visibleman had the right approach with adding you to a group and allowing the group to edit the files under /var/www . One slight addition I would add is that after the chmod 755 /var/www command you should run

Code:
sudo chmod g+s /var/www

What this does is make it so that any new files that are created in that directory retain the same owner and group permissions (www-data) so that you as the pi user can still edit them.

You can read more about the g+s stuff here

http://stackoverflow.com/questions/...chmod-gs-on-a-file-or-directory/191058#191058
 
Back
Top Bottom