Kitz Forum

Computer Software => Linux => Topic started by: sheddyian on March 25, 2013, 03:38:59 PM

Title: Server Side scripting in Apache webserver on Raspberry Pi
Post by: sheddyian on March 25, 2013, 03:38:59 PM
Today, I've got my new Raspberry Pi setup - almost.

I installed the standard Raspbian Wheezy (Debian), that all went fine.

I then followed these instructions to install Apache webserver.  I chose Apache because these were the instructions I found when googling "raspberry pi webserver"  :D  Also, I've heard of Apache.
http://www.wikihow.com/Make-a-Raspberry-Pi-Web-Server (http://www.wikihow.com/Make-a-Raspberry-Pi-Web-Server)

It all went well, except at the end these bits didn't work.  Sureley there's a mistake - if Im commenting out the user pi from /etc/passwd, how can I then "add the user as a mod"?  It gave me an error indicating the user "pi" didn't exist, which of course it didn't, as the previous step instructed me to put a # in front of that users entry.

Code: [Select]
Edit the password configuration file:
sudo nano /etc/passwd

Find the line pi:x;1000:1000:Raspberry Pi User,,,:home/pi:/bin/bash and add a # sign to the beginning of it. Now save and exit the file.

Add the user pi as a mod.
sudo usermod -d /var/www pi

Now exit your SSH session, and log back in as pi, then grant mod rights to root.
sudo usermod -L root

That aside, it all seemed to work ok, and I got the test index.html when I accessed the raspberry pi's ip address from another computer web browser.  Hurrah!

Next step - try to port over (hopefully, just copy over) my GardenCam web site from the Windows XP IIS server it's currently on.  I ftp'd all the files over to /var/www, adjusted the permissions to match the example index.html file permissions, and tried the site out again on a web browser.

Big fail.

Front page loads ok, but main page only shows webcam image and minimal text.  The menus and borders on my little site are generated by server side includes. This works out of the box in Microsoft's IIS  :P

So, Googling apache server side includes leads me to this page : http://httpd.apache.org/docs/current/howto/ssi.html (http://httpd.apache.org/docs/current/howto/ssi.html) telling me how to enable SSI.

This is where I start getting really lost.

I find that I don't have/can't find an httpd.conf file, but more Googling reveals I should instead edit /etc/apache2/apache2.conf which I do.

I've added

Code: [Select]
Options +Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
XBitHack on

at the end of apache2.conf then restarted the apache service.

I then changed the file permission of all my .shtml files to a+x which I understand is a way of telling Apache to check those files for SSI scripting.

Result?

Nothing has changed - no sign of the server side includes working on my Rsapberry pi server :(

Particularly with the last bit, but, well, overall really - any idea what I did wrong?

Perhaps worringly, I also found this :

http://www.raspberrypi.org/phpBB3/viewtopic.php?t=11567&p=191855 (http://www.raspberrypi.org/phpBB3/viewtopic.php?t=11567&p=191855)

Which is the problem I'm seeing, but no answer.

Ian (confused)
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: roseway on March 26, 2013, 07:38:22 AM
I'm sorry you're not getting any response here. I use Debian Wheezy, but I know nothing about webservers unfortunately. The fact that the question has been asked but not answered on the Raspberry Pi forum doesn't bode well. :(
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: sheddyian on March 26, 2013, 09:51:55 AM
I've sort-of got it working now, more on that later!  (I'm not sure exactly which steps were important, but I did it all again following different instructions, which still failed, but then fiddled for ages and got it working)

What's your view on the first bit in my post - the instruction to comment out the "Pi" user, then do a usermod on that very same user, which by now doesn't exist because it's been commented out?  It fails, and even to my non-Linux eyes it's going to fail if I've just disabled the user.  Or am I missing something subtle?  That instruction is repeated in another guide I followed, so they're either blindly copying each other or Theres A Reason.

Ian

Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: roseway on March 26, 2013, 10:21:18 AM
What's your view on the first bit in my post - the instruction to comment out the "Pi" user, then do a usermod on that very same user, which by now doesn't exist because it's been commented out?  It fails, and even to my non-Linux eyes it's going to fail if I've just disabled the user.  Or am I missing something subtle?  That instruction is repeated in another guide I followed, so they're either blindly copying each other or Theres A Reason.


Yes, I agree with you. I suspect that there's a line missing before the usermod line:

Code: [Select]
sudo useradd pi
So the previous actions would remove the user pi, and this would recreate that user with default characteristics before making it into a mod.

WARNING: I don't really know what I'm talking about, so it's only a possible answer.

Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: sheddyian on March 26, 2013, 02:56:22 PM
Just read that there's a DOS emulator for the Raspberry Pi, so maybe I'll use that instead  :P

http://raspberry-pi.dcemu.co.uk/rpix86-v0-03-released-dos-pc-emulator-for-raspberry-pi-released-539652.html (http://raspberry-pi.dcemu.co.uk/rpix86-v0-03-released-dos-pc-emulator-for-raspberry-pi-released-539652.html)

If I could just get it running Lan Manager...

Ian
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: sheddyian on March 27, 2013, 09:48:05 AM

Well, I got SSI working in apache on the pi, and for the record, this is what I did.

Note : As I'm floundering around here, some of this may not be required!  This is what I did, and afterwards, it worked.

First, the Apache tutorial site http://httpd.apache.org/docs/2.2/howto/ssi.html (http://httpd.apache.org/docs/2.2/howto/ssi.html) tells you to add the following to the httpd.conf file. BUT THIS (or this on it's own) DOESN'T WORK

Code: [Select]
Options +Includes

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

Firstly, because for reasons unknown to me, there isn't an httpd.conf file.  Instead, there is /etc/apache2/apache2.conf

Using guidance I found on a different site, I added this different code to the end of the file :

Code: [Select]
<Directory /var/www/*>
     Options +Includes
     AddType text/html .shtml
     AddOutputFilter INCLUDES .shtml
</Directory>

This on it's own didn't work.  I then had to type the mysterious command :

Code: [Select]
a2enmod include
a solution that is described on very few sites / forums that try to answer the question "why doesn't SSI work on apache?"  :no:

After doing this (I may have then rebooted, I forget now) it all started working!

(Well, the Server Side Includes did.  Don't get me started on the photo gallery part of the site that no longer works, or the grief I had trying to get motion to work (which is what almost everyone suggests for pi webcams. 

More on that later!

Ian  :flamer:
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: roseway on March 27, 2013, 09:55:27 AM
Congratulations on your perseverance. :)
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: burakkucat on March 27, 2013, 10:14:18 PM
It certainly puts my usage of my R-Pi to shame.  :-[  (It is just used as a head-less, keyboard-less and mouse-less system that executes my harvesting code to create a log file of my modem/router's statistics.  :blush:  )
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: sheddyian on March 27, 2013, 10:33:28 PM
Well, I already have a Pi that runs RaspBMC media Centre, and that felt a bit like cheating because it doesn't take much effort to set up (and is very good - my TV remote can work it via the TV HDMI!)

So I was pleased to get a 2nd pi and have something that involved some tinkering with a purpose.

However, so far - all these conf (.ini) files, instructions that don't match reality and general confusion remind me of Windows 3.11 days!

*ducks for cover*

Ian
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: broadstairs on March 27, 2013, 10:51:47 PM
Yes but you're setting up a server... if you think Apache is complicated have you ever tried IIS?

Stuart
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: sheddyian on March 27, 2013, 11:00:46 PM
Yes but you're setting up a server... if you think Apache is complicated have you ever tried IIS?

Stuart

Yes!  ;D

My current webcam site is running on IIS!

I wrongly said earlier that Server Side Includes worked "out of the box" on IIS - I now remember that I had to enable them, but it was a couple of clicks and it all just worked.

I've plenty of gripes with IIS, but overall, it does it's thing and didn't seem so much grief to get working.

I'm interested in moving it all over to Linux on the Pi because I want to try it, and also I want to solar power the Pi - it'll use a lot less current than the computer I currently run IIS on  ;D

Ian
Title: Re: Server Side scripting in Apache webserver on Raspberry Pi
Post by: Mick on May 24, 2013, 07:10:02 PM
Usually, things in apache work with default configuration, but in case they don't, here are the principles:

Configure the necessary apache files to:

1. Point the server to the web root directory where your website file system resides.  This could be in the default apache configuration file, or it could be in a configuration file for Virtual Hosts which you will need to create for your website(s).
2. Configure the necessary apache modules.  This was your problem here, which you eventually overcame.  Again the default apache configuration file may include this, or there could be module configuration files per virtual host.  Check /etc/apache2/ directory for relevant contents.
3. Make sure that ownership and access rights are correct so that apache can access/read and if required write relevant files in the web root filesystem.  Needless to say, you have to be circumspect with this, especially if you want a secure installation not writable by all the script kiddies out there.
4. Configure apache users and passwd (using htpasswd command) to make sure that unauthenticated visitors cannot see or alter things they are not meant to.

I'm simplifying it, but in essense that's all there is to it.  Dipping into the detailed apache documentation (google for it) will explain the ins and outs of the each and every configuration variable - that's if you need to alter something from the defaults.

Ask here or PM me if you need particulars.