Hi I am trying the apache server out so i decided to install one on my Raspberry Pi. I then wanted to take the same (or some of) the code we had in pset7 and run on my own server.

I have a problem though. When I start the service it runs in /var/www/ and looks for my index file there.

That would be same as running apache50 start ~/workspace/pset7 instead of apache50 start ~/workspace/pset7/public

So I thought I could maybe redirect my index to /public/index.php somehow?

I made a php file and tried redirect(/public/index.php) but did not work.

Any suggestions?

2 Answers 2



This tutorial should help you to change the DocumentRoot of your website by using Apache2 Virtual Hosts.

The focus of the tutorial is on how to host more than one domain or subdomain on the same Raspberry Pi server, but it should also work just to move your DocumentRoot to something like this:

DocumentRoot /var/www/pset7/public/


The advice below should work, but since you have root on the system, there is a simpler solution: you can change Apache2's document root by editing the global configuration files under


as described in the tutorial linked above.

I'm leaving my original advice intact below, because it may help others who want to host a pset7-esque site in a shared hosting environment where they may not have access to the global Apache2 configuration.

This can be done, but you'll need to think outside the box.

You can make /var/www into your public directory. Put all the public stuff directly in there. The other stuff does not belong in your public directory, anyway. But where will you put it?

One way to handle this would be to copy the entire pset7 directory into your /opt directory (which is, by convention, a good place to install custom software which is not managed by your distro's package manager). Then:

mv /opt/pset7/public/* /var/www/

This may require sudo privilege.

If you are in a shared hosting situation and do not have access to /opt, you can achieve a similar effect by putting the pset7 directory somewhere else inside your home directory, but outside of the public_html directory.

No matter where you put them, moving these files will cause some breakage, and you'll need to edit some require() statements to look for configure.php under /opt/pset7 instead.

Outside of your public directory, everything else should be in the same relative position, so relative pathnames should not break!

Hope this helps.


I went with a change in /etc/apache2/sites-available

Works good thanks! Here is some shortcuts for future reference.

pi@raspberrypi2 /etc/apache2/sites-available $ apache2 default
Usage: apache2 [-D name] [-d directory] [-f file]
               [-C "directive"] [-c "directive"]
               [-k start|restart|graceful|graceful-stop|stop]
               [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
  -D name            : define a name for use in <IfDefine name> directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed settings (currently only vhost settings)
  -S                 : a synonym for -t -D DUMP_VHOSTS
  -t -D DUMP_MODULES : show all loaded modules
  -M                 : a synonym for -t -D DUMP_MODULES
  -t                 : run syntax check for config files
  -T                 : start without DocumentRoot(s) check
  -X                 : debug mode (only one worker, do not detach)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .