cloudfoundry / php-buildpack

A Cloud Foundry Buildpack for PHP.
Apache License 2.0
142 stars 342 forks source link

How do I change apache's httpd configuration file in php runtime, config WEBDIR and load apache modules using options.json? Thanks #158

Closed marcocianci closed 8 years ago

marcocianci commented 8 years ago

What version of Cloud Foundry are you using? --> cf version 6.21.1+cd086c8-2016-08-18 What version of the buildpack you are using? --> v4.3.10 If you were attempting to accomplish a task, what was it you were attempting to do? ---> I'm trying to to load apache module "autoindex" and update composer for my app. ---> When I set "WEBDIR" I got 404. ---> I would also like to know which variable to edit the vhosts.

What did you expect to happen? --> load apache module autoindex, update composer inside app's folder,

What was the actual behavior? --> I got 404 and can't update composer for my app. --> This link does not work more: https://github.com/cloudfoundry/php-buildpack/blob/master/docs/config.md

Which steps for reproduction ? 1-) Create new web app using buildpack php; 2-) Add git and edit code 3-) create folder yii2-app-advanced with .htaccess ` DirectoryIndex index.php IndexIgnore .htaccess /.?? ~ # /HEADER /README _/vti

RewriteBase / RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php ``` RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] ```

4-) Create .bp-config/options.json { "WEBDIR": "htdocs/yii2-app-advanced", "PHP_VERSION": "{PHP_56_LATEST}", "PHP_EXTENSIONS": [ "bz2", "zlib", "openssl", "curl", "mcrypt", "mbstring", "pdo" ], "ADDITIONAL_PREPROCESS_CMDS": [ "cd ./app/lib/", "php -r \"readfile('https://getcomposer.org/installer');\" | php", "php composer.phar global require \"fxp/composer-asset-plugin:~1.2.0\"", "php composer.phar install", "cd ../../htdocs/yii2-app-advanced", "php composer.phar update -o", "a2enmod autoindex", "a2enmod headers", "service apache2 restart" ] } ` LOG ERROR 8/23/2016 3:09:04 PM OUT App All settings correct for using Composer 8/23/2016 3:09:07 PM OUT App Composer successfully installed to: /home/vcap/app/lib/composer.phar 8/23/2016 3:09:07 PM OUT App Use it: php composer.phar 8/23/2016 3:09:07 PM ERR App Changed current directory to /home/vcap/app/.composer 8/23/2016 3:09:08 PM ERR App ./composer.json has been created 8/23/2016 3:09:08 PM ERR App Loading composer repositories with package information 8/23/2016 3:09:09 PM ERR App Updating dependencies (including require-dev) 8/23/2016 3:09:25 PM ERR App - Installing fxp/composer-asset-plugin (v1.2.1) 8/23/2016 3:09:26 PM ERR App Downloading: Connecting... Downloading: 0% Downloading: 5% Downloading: 10% Downloading: 15% Downloading: 20% Downloading: 25% Downloading: 30% Downloading: 35% Downloading: 40% Downloading: 45% Downloading: 50% Downloading: 55% Downloading: 60% Downloading: 65% Downloading: 70% Downloading: 75% Downloading: 80% Downloading: 85% Downloading: 90% Downloading: 95% Downloading: 100% 8/23/2016 3:09:27 PM ERR App Writing lock file 8/23/2016 3:09:27 PM ERR App Generating autoload files 8/23/2016 3:09:28 PM ERR App Composer could not find a composer.json file in /home/vcap/app/lib 8/23/2016 3:09:28 PM ERR App To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section 8/23/2016 3:09:29 PM ERR App Composer could not find a composer.json file in /home/vcap/app/lib 8/23/2016 3:09:29 PM ERR App To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section 8/23/2016 3:09:29 PM ERR App app/.profile.d/rewrite.sh: line 10: a2enmod: command not found 8/23/2016 3:09:29 PM ERR App app/.profile.d/rewrite.sh: line 11: a2enmod: command not found 8/23/2016 3:09:29 PM ERR App apache2: unrecognized service 8/23/2016 3:09:29 PM ERR App /bin/bash: line 31: cd: app: No such file or directory 8/23/2016 3:09:29 PM ERR App Traceback (most recent call last): 8/23/2016 3:09:29 PM ERR App File "/home/vcap/app/.bp/bin/start", line 30, in 8/23/2016 3:09:29 PM ERR App filename='logs/proc-man.log') 8/23/2016 3:09:29 PM ERR App File "/usr/lib/python2.7/logging/init.py", line 1532, in basicConfig 8/23/2016 3:09:29 PM ERR App hdlr = FileHandler(filename, mode) 8/23/2016 3:09:29 PM ERR App File "/usr/lib/python2.7/logging/init.py", line 903, in init 8/23/2016 3:09:29 PM ERR App StreamHandler.init(self, self._open()) 8/23/2016 3:09:29 PM ERR App File "/usr/lib/python2.7/logging/init.py", line 928, in _open 8/23/2016 3:09:29 PM ERR App stream = open(self.baseFilename, self.mode) 8/23/2016 3:09:29 PM ERR App IOError: [Errno 2] No such file or directory: '/home/vcap/app/lib/logs/proc-man.log' 8/23/2016 3:09:29 PM ERR DEA Instance (index 0) failed to start accepting connections 8/23/2016 3:09:29 PM OUT API App instance exited with guid 44380c03-878f-4fea-8fb4-3598f18f2cf8 payload: {"cc_partition"=>"default", "droplet"=>"44380c03-878f-4fea-8fb4-3598f18f2cf8", "version"=>"e9b1de1a-6812-4e89-9761-a533c9e70cfb", "instance"=>"b553fdcd972c40809d361647c278dfd8", "index"=>0, "reason"=>"CRASHED", "exit_status"=>1, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1471964969} 8/23/2016 3:09:29 PM OUT API App instance exited with guid 44380c03-878f-4fea-8fb4-3598f18f2cf8 payload: {"cc_partition"=>"default", "droplet"=>"44380c03-878f-4fea-8fb4-3598f18f2cf8", "version"=>"e9b1de1a-6812-4e89-9761-a533c9e70cfb", "instance"=>"b553fdcd972c40809d361647c278dfd8", "index"=>0, "reason"=>"CRASHED", "exit_status"=>1, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1471964969} 8/23/2016 3:12:12 PM OUT DEA Removing crash for app with id 44380c03-878f-4fea-8fb4-3598f18f2cf8 8/23/2016 3:12:12 PM OUT DEA Stopping app instance (index 0) with guid 44380c03-878f-4fea-8fb4-3598f18f2cf8 8/23/2016 3:12:12 PM OUT DEA Stopped app instance (index 0) with guid 44380c03-878f-4fea-8fb4-3598f18f2cf8

Please confirm where necessary:

cf-gitbot commented 8 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/128864695

The labels on this github issue will be updated when the story is started.

dmikusa commented 8 years ago

There's no need to install additional HTTPD modules, they are all compiled and included by default. These are the ./configure args used for HTTPD.

https://github.com/cloudfoundry/binary-builder/blob/master/recipe/httpd_meal.rb#L44-L51

All you need to do is drop in a config file to indicate which additional modules should be loaded by HTTPD. The default list is here.

https://github.com/cloudfoundry/php-buildpack/blob/master/defaults/config/httpd/extra/httpd-modules.conf

Put a copy of that in .bp-config/httpd/extra/httpd-modules.conf and it will override the default supplied with the build pack.

RochesterinNYC commented 8 years ago

@marcocianci please let us know if @dmikusa-pivotal's suggestion fixes your specific issue.

marcocianci commented 8 years ago

@RochesterinNYC Yes! Thanks. I am setting the environment for Yii2.

but I'm still some difficulties. I am referring to the documentation.

TheSecMaven commented 5 years ago

My issue is related to this somewhat. We also are trying to load a module but this isn't a module that is uploaded publicly (from a vendor). Are there methods to do this with our own .so file that we have?

dmikusa commented 5 years ago

You could do the same thing described here -> https://github.com/cloudfoundry/php-buildpack/issues/158#issuecomment-241771312

The difference would be that you'd need to put a full path to the compiled module which you'd need to bundle and push with your app. The path to your app root can be set with $HOME in HTTPD config files, or you can hard code /home/vcap/app/where/you/put/the/module.so, your choice.

TheSecMaven commented 5 years ago

Was trying this and had issues.

Here is repo structure . ├── TODO.TXT ├── authtest.php ├── .bp-config │ ├── httpd.conf │ └── extra │ | ├── httpd-modules.conf ├── custom_modules │ ├── agent.conf │ └── mod_openam.so ├── edit_group.php ├── edit_user.php ├── groups.php ├── images │ ├── banner.png │ └── favicon.ico ├── includes │ ├── accesskey.js │ ├── config.inc.php │ ├── cred.inc.php │ ├── cred.inc.php_old │ ├── footer.inc.php │ ├── functions.inc.php │ ├── header.inc.php │ └── main.css ├── index.php ├── index.php_old ├── logout.php ├── manifest-dev.yml ├── test.php └── users.php

I took http-modules and added this line: LoadModule amagent_module /home/vcap/app/custom_modules/mod_openam.so

I then reference the module in httpd.conf with these 2 lines: AmAgent On AmAgentConf $HOME/custom_modules/agent.conf

And fails with this error: 2019-09-06T07:15:28.917-05:00 [CELL/0] [OUT] Starting health monitoring of container 2019-09-06T07:15:29.208-05:00 [APP/PROC/WEB/0] [OUT] 12:15:29 httpd | httpd: Syntax error on line 58 of /home/vcap/app/httpd/conf/httpd.conf: Syntax error on line 115 of /home/vcap/app/httpd/conf/extra/httpd-modules.conf: Cannot load /home/vcap/app/custom_modules/mod_openam.so into server: /home/vcap/app/custom_modules/mod_openam.so: cannot open shared object file: No such file or directory 2019-09-06T07:15:29.225-05:00 [APP/PROC/WEB/0] [OUT] 12:15:29 php-fpm | [06-Sep-2019 12:15:29] NOTICE: ready to handle connections 2019-09-06T07:15:29.225-05:00 [APP/PROC/WEB/0] [OUT] 12:15:29 php-fpm | [06-Sep-2019 12:15:29] NOTICE: fpm is running, pid 61 2019-09-06T07:15:29.339-05:00 [APP/PROC/WEB/0] [OUT] Exit status 1

dmikusa commented 5 years ago

Oh, I know what's going on. You don't have a WEBDIR (ie. htdocs, public, etc..). When that happens, the buildpack will move all your files into WEBDIR, which defaults to htdocs. Thus the path to your module changes.

I would strongly suggest that you create a WEBDIR. Call it htdocs, or if you want to call it something different, add "WEBDIR": "<name>" to options.json. The buildpack will see that exists and not need to move files around.

If you can't/don't want to do that, then you need to adjust the path in your config file to where things will be, which should be /home/vcap/app/htdocs.

TheSecMaven commented 5 years ago

This worked perfectly! Thank you.

As a separate note, we are trying to do a similar thing with nginx buildpack and am wondering if a similar thing is happening and thats why loading the custom module in nginx fails.

dmikusa commented 5 years ago

Excellent! The Staticfile buildpack moves files like this, but the Nginx buildpack does not, as far as I know.