Apache HTTPD And Apache Tomcat

 Hi, I am using httpd feature of php build for application url redirection from one domain to other domain [301/302]. The problem is how to configure virtualhost tag and directory tag in httpd.conf file. Can you please share sample code on it.

sathish Mandhadapu's profile image
sathish Mandhadapu posted Oct 08, 2019 11:04 PM

 

Daniel Mikusa's profile image
Daniel Mikusa

You certainly can do that, but you're really getting outside the scope of the PHP buildpack. The default configuration is meant to run one app, so effectively you're talking about providing a very custom HTTPD configuration.

 

A few pointers:

 

First, add a `.profile` file in the root of your project. Put this in there.

# delete the line starting with `php-fpm:` # this makes PHP not start, which is good cause we don't need it sed -i '/^php-fpm/d' $HOME/.procs   # unzip stie files if they are zipped pushd site/ if [ -f "site.tar.gz" ]; then tar zxf site.tar.gz --strip-components 1 rm site.tar.gz fi popd

It does two things. First, it makes it so that PHP won't actually run. You can't easily prevent it from being installed, but you can make it not run, which saves you some memory. Second it will before your app starts optionally extract a tar gzip version of your site into the `site/` directory. This can dramatically speed up the `cf push` times for your app if you have lots of small (less than 65k) files, which many static sites do. If you don't include a zip of your site, it does nothing.

 

Create `.bp-config/httpd/httpd.conf` and in that put your totally custom HTTPD config file. This will completely override anything from the buildpack so you need a full and valid HTTPD config file. If you don't want to completely override the buildpack, you can put just select files in `.bp-config/httpd/extra/` which override these files (the file names must match exactly). You can use a blank file to just remove behavior, like to turn off the PHP configuration. PROTIP: you can use `${HOME}` to reference the root of your project and `${PORT}` which is helpful for `Listen` and `DocumentRoot`.

 

Make a folder for the files you want to serve up, put that under the root of your project. If you don't care about the name, use `htdocs` (even if you're not serving up any files do this). If you need a different name, add `.bp-config/options.json` and put `{"WEBDIR": "site"}` (or replace site with the name of your public files folder. If you don't create this folder, the buildpack will move files around and it'll probably break the paths you expect in your httpd.conf file which may cause your app to fail to start.

 

For what it's worth, there is a Cloud Native buildpack for just HTTPD. This will make doing fun custom things with HTTPD easier in the future, when Cloud Foundry can run Cloud Native Buildpacks.

 

Hope that helps!

Daniel Mikusa's profile image
Daniel Mikusa

All of the changes I mentioned above are within your application so they will not be overwritten if/when the PHP buildpack is updated.

Daniel Mikusa's profile image
Daniel Mikusa

Sorry, I'm not sure I understand what you're asking, but it should accept any valid HTTPD configuration. The only thing that jumps out about using VirtualHost is that you'd need to use name based virtual hosts because there will be only one IP in your container.

 

Hope that helps!

sathish Mandhadapu's profile image
sathish Mandhadapu

As I am customizing the Php buildpack, when there is an update to the PHP buildpack, will these be overwritten? Or will these customizations stay as we configured them?

sathish Mandhadapu's profile image
sathish Mandhadapu

If I have more than one Virtualhost tag in httpd configuration file. Is there any possibility of providing each virtualhost with different tag name. So, that it will be easy to filter them when required.