# Installing Apache within a jail



## bsduni (Oct 2, 2013)

Hi!

I am learning FreeBSD and wish to implement a webserver within a jail. I have followed http://www.freebsd.org/doc/handbook/jails-application.html and have got a working jail 'www' on FreeBSD 9.1. Now I want to install Apache and PHP within the jail. I could not find information in this regard and the information at https://wiki.freebsd.org/AppserverJailsHOWTO only has guides for ezjail, not the manually set[]up jail. 

Is there any guide that illustrates the installation of applications within a (plain) jail? (not ezjail).

Thank you in advance.


----------



## SirDice (Oct 2, 2013)

Treat the jail as a separate machine. There's nothing 'special' to do, just install it as you do on the host.


----------



## ph0enix (Nov 13, 2013)

SirDice said:
			
		

> Treat the jail as a separate machine. There's nothing 'special' to do, just install it as you do on the host.



So basically `chroot` to the jailed environment, sync the ports tree and build/install the port?


----------



## ShelLuser (Nov 13, 2013)

ph0enix said:
			
		

> So basically chroot to the jailed environment, sync the ports tree and build/install the port?


Basically "enter" the jail, then sync the tree and install the port.

Entering the jail can be done by executing a shell within the jail, you have the jexec command for that (for example: `# jexec www /bin/sh`). Or if you want to do this more officially you could even start login instead of a shell and then logon as if you'd do on a regular machine.

As for the ports collection..  Sure, you could synchronize a new tree in the jail and treat that separately. But you might get a more efficient environment if you simply shared the ports collection from the host.

You can do that by "re-mounting" (or _binding_) the directory in which the ports collection resides into the jail environment. Look into the nullfs file system for that.

And yeah, in the end merely install the port and be done with it. You could even opt for the usage of binary packages if you don't need to finetune the whole lot.


----------

