How to Deploy Zend Framework 2 in Bluemix

2019-07-11 20:51发布

问题:

I've deployed ZF2 application in bluemix system. After deployment I reach

Not Found

The requested URL / was not found on this server. error.

After I've added .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^APP_HOST$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.APP_HOST$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

And getting error:

Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. Run php composer.phar install or define a ZF2_PATH environment variable.' in /home/vcap/app/htdocs/init_autoloader.php:53 Stack trace: #0 /home/vcap/app/htdocs/public/index.php(15): require() #1 {main} thrown in /home/vcap/app/htdocs/init_autoloader.php on line 53

I found A CloudFoundry Build Pack for PHP.. I also tried how there described, but no result.

回答1:

I found the way to deploy any PHP Framework to Bluemix system. I've tested ZF2 and Yii2 frameworks. Add in

manifest.yml

buildpack: https://github.com/cloudfoundry/php-buildpack#v3.2.2
  env:
    CF_STAGING_TIMEOUT: 15
    CF_STARTUP_TIMEOUT: 15

Create a htdocs folder. Move all generated project files into this newly created htdocs folder with the exception of these four files:

  1. .gitignore
  2. composer.json
  3. composer.lock
  4. manifest.yml

Create a new folder in the root of our application named .bp-config. Change directories into this folder and create a new filed named options.json. Within this file, include the following json snippet:

{
     "PHP_VERSION": "{PHP_55_LATEST}",
     "COMPOSER_VENDOR_DIR": "htdocs/vendor",
     "WEBDIR": "htdocs/public",
     "PHP_EXTENSIONS": [ "bz2", "zlib", "openssl", "fpm", "tokenizer", "curl", "mcrypt", "mbstring", "pdo", "FRAMEWORK NAME"]  
}

For Zend Framework 2 "FRAMEWORK NAME" to "ZF2", for Yii2 to "Yii2".



回答2:

Please use zend framework buildpack instead:

https://github.com/zendtech/zend-server-php-buildpack-bluemix

# cf push -b https://github.com/zendtech/zend-server-php-buildpack-bluemix