views:

133

answers:

3

I have heard that setting the --prefix=PREFIX option when compiling PHP on linux will allow you to have more than one install of PHP at a time without them clashing. (I think the default if this isn't set is /usr/local). However, I'm not sure what exactly it does or what a good setting to use is. Furthermore, I've also heard that setting it to something other than the default value might make some PHP extensions harder to install.

./configure --prefix=PREFIX ...

update

I just realized that some of the other options such as --exec-prefix might still need to be set to /usr/local since they default to the value of --prefix. This would cause problems if prefix was set to something like web/phpalt because things like the --sbindir is set to `--exec-prefix + /sbin.

Directory and file names:
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local]
  --exec-prefix=EPREFIX   install architecture-dependent files in EPREFIX
                          [same as prefix]
  --bindir=DIR            user executables in DIR [EPREFIX/bin]
  --sbindir=DIR           system admin executables in DIR [EPREFIX/sbin]
  --libexecdir=DIR        program executables in DIR [EPREFIX/libexec]
  --datadir=DIR           read-only architecture-independent data in DIR
                          [PREFIX/share]
  --sysconfdir=DIR        read-only single-machine data in DIR [PREFIX/etc]
  --sharedstatedir=DIR    modifiable architecture-independent data in DIR
                          [PREFIX/com]
  --localstatedir=DIR     modifiable single-machine data in DIR [PREFIX/var]
  --libdir=DIR            object code libraries in DIR [EPREFIX/lib]
  --includedir=DIR        C header files in DIR [PREFIX/include]
  --oldincludedir=DIR     C header files for non-gcc in DIR [/usr/include]
  --infodir=DIR           info documentation in DIR [PREFIX/info]
  --mandir=DIR            man documentation in DIR [PREFIX/man]
  --srcdir=DIR            find the sources in DIR [configure dir or ..]
  --program-prefix=PREFIX prepend PREFIX to installed program names
  --program-suffix=SUFFIX append SUFFIX to installed program names
  --program-transform-name=PROGRAM
                          run sed PROGRAM on installed program names

Based on what PHP is saying then it seems like you could set the following options without any side affects.

./configure --prefix=/custom/path --exec-prefix=/usr/local

However, this is just a guess. ;)

A: 

All that does is change the folder that the PHP binaries will be installed to.

Changing it will change where you are installing it, so technically you could install multiple copies... but why would you do that? That would just make a headache for everything else (your webserver/cgi/cli)

Most of the time, the path is /usr/local or /usr which would install the files in /usr/local/bin and /usr/bin` respectively.

webdestroya
I need to be able to switch back and forth between a PHP 5.2 and PHP 5.3 for testing.
Xeoncross
@Xeoncross - I figured, but you will most likely cause more problems, which will ironically force you to spend time figuring if your code has a problem, or if it has to do with your 5.2/5.3 switching. Why not just run a VM or something with two different PHP installations?
webdestroya
Ya, a VM is an option - but I was hoping that it would be easy to have multiple installs of PHP on linux like it is in windows.
Xeoncross
+1  A: 

The good setting for you to use is /usr/local. The distro packager should use /usr and ISVs should use /opt/<appname>.

This path is used as the base for the CLI executable ($PREFIX/bin), the SAPI library, and the extensions.

Ignacio Vazquez-Abrams
+1  A: 

If you want to switch between 5.2 and 5.3, you're probably better off compiling both Apache and PHP from source, into special directories.

Basically, you could compile apache and php5.2 to some place like /web/php52 (giving --prefix=/web/php52 to configure for both apache and php. Then do the same for apache/php53 with a prefix like /web/php53

You could even get tricky and do things like symlink various configs between the two apache installations to keep things consistent (so the only difference is that one is running 5.3 and the other 5.2)

Then when you want to start up your 5.2 server, you just say:

$ /web/php52/bin/apachectl start

and then to switch over to 5.3

$ /web/php52/bin/apachectl stop
$ /web/php53/bin/apachectl start

I have some (old) build scripts available that may or may not save you some pain if you're compiling on linux (CentOS in particular, but you could make it work pretty easily on non-redhat distros, too)

timdev
Awesome, so I could compile different PHP versions into seporate folders. That's what I want to do. Are there any parts of the PHP core that might be installed outside of the folder if I set the `prefix=/web/php52`? In other words, I would like to be able to just remove the `/web/php52` folder should I no longer need that version without worrying about left over files in other parts of the filesystem. BTW, I'll be using nginx not apache so I'll probably just manually change the location of the fastcgi PHP path when starting it.
Xeoncross
PHP won't put anything outside of it's prefix dir, unless you tell it specifically to do so by using other arguments to `configure`. Nuking whatever your directory you set will completely clean things up.
timdev