Heroku: Run Rails Application with PHP Script? - php

I have a rails application that uses php code. I am calling the php code directly with a system call 'php path/to/script.php'
This works fine on my local machine where I have php installed. I'm looking to deploy this to somewhere like Heroku. To solve this problem, I am using the multibuildpack Github library:
github.com/ddollar/heroku-buildpack-multi
I have specified in my .buildpacks
https://github.com/heroku/heroku-buildpack-php.git
https://github.com/heroku/heroku-buildpack-ruby.git
and both install just fine. The problem is that Heroku treats the application like a php application. On the Heroku logs, it states that it is using the php configuration and is starting php-fpm when I want it to run as a rails application.
How do I go about fixing this? Specifically, how do I make sure that php is ready on Heroku when I make the system call

You can do this by using multiple buildpacks
heroku buildpacks:add heroku/php --index 1 -a app-name
Also create a composer.json file on the root of your project, you can even specify the php version like this:
{
"require": {
"php": ">=5.4",
"ext-mcrypt": ">=2.5.8"
}
}
Finally create a composer.lock with
php composer.phar update --ignore-platform-reqs
Commit, deploy your code and all set.

If PHP CLI is installed you could use the gem "php_process", which I wrote, to call the PHP library instead of bundling PHP files, which may be what is causing Heroku to define your project as using PHP.
https://github.com/kaspernj/php_process

I don't believe there is a way to fix this because according to Heroku - they support both languages and determine which language is used in the application. It seems it's one language or the other.
I write PHP and have dabbled with Ruby on Heroku, but haven't tried mixing the two. It sounds a lot messier than I would be comfortable with, personally.
Why not try contacting Heroku Support?

Related

How to Deploy a Cake PHP App

I wonder if someone can help me. I've been handed in a Cake PHP app that I need to 1) add minor changes 2) deploy. I've never really worked with Cake before and was wondering whether do I need to anything in order for it to work?
For instance, With a Node app, you need to install modules npm install. With a Rails app you'll likely need to install the gems bundle install.
Is there something similar with Cake? I've set the localhost server, but when I try to access the url I get all sort of errors. Some I've fixed (missing environment settings which I just override the Redis host and port). The latest one is:
{
"exception":{
"class":"MissingControllerException",
"code":404,
"message":"Controller class Controller could not be found.",
"file":"\/Library\/WebServer\/Documents\/php\/oompbe\/vendors\/cakephp\/lib\/Cake\/Routing\/Dispatcher.php",
"line":154,
"trace":[
"#0 \.../app\/webroot\/index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
"#1 {main}"
]
}
}
PS: What's up with all the crazy \/\/?
PPS: Can I find out the version Cake I'm running?
CakePHP is just php. As most properly done php apps these days it comes with composer. I recommend you to read at least the basics of it's manual. Composer is an awesome tool.
git clone <repo>
cd <reponame>
composer install
If you start a new Cake application the official documentation tells you how to this as well:
composer create-project --prefer-dist cakephp/app [app_name]
If you want to automate things further composer provides you callback scripts. They'll allow you to automate tasks, basically trigger commands, after different actions. This is pretty useful to build assets after a composer update for example. I recommend you to not put lots of commands into that section but instead have dedicated script files you trigger by the callbacks.
Can I find out the version Cake I'm running?
If installed via composer it is usually in vendor/cakephp/cakephp/version.txt. Check the content of that file.

How to run a Symfony app without using the built-in server?

In the documentation is clearly explained how to run the built-in server to run a Symfony App.
Ok, all works well and i'm very happy, but:
How can i run a Symfony App without using the server but simply something like http://localhost/path/to/symfonyApp/web/app.php?
Here the documentation: http://symfony.com/doc/current/cookbook/web_server/built_in.html
Maybe something like this could help: Install Symfony 2 with wamp
This is also explained in docs:
Configuring a Web Server
It's not too hard, if you're running a local server (Apache/wamp) and have PHP configured to it already. If you're on a windows machine you'll want to run it with a nice linux-esque terminal like Cygwin. You'll also want to have Composer to automate a lot of your Symfony tasks.
Then just download Symfony and put it in your web facing folder (htdocs, www, whatever you call it) and configure it according to what you need.

Trouble installing Omnipay via Netbeans composer extension

I am currently trying to install Omnipay into my Codeigniter project. I am stuck on windows because I do not have ssh access to the box where this needs to run on. So far I have gotten a new directory in the project root that is named "vendor" and it contains a lot of empty directories referring to Symfony (for what reason is beyond me).
Then I get a runtime exception that I need to enable the openssl extension in my php to download the necessary files and this is where I am stuck at. I don't run WAMP on my computer and I just use the php.exe I downloaded to work with netbeans.
Isn't there an easier way to get omnipay to run? Like just download the files from somewhere and plug them into my project like normal? It seems to be an aweful lot of headache to get a simple library to run in my CI project.
Please forgive my ignorance towards composer but I currently see no benefit of using it for this particular project.
You can "just download" the files here: https://github.com/omnipay/common/archive/master.zip
The problem is, Omnipay depends on Guzzle (an HTTP library), and Guzzle depends on some Symfony components. So you will spend the rest of the day downloading dependencies and making sure you have all the necessary files. That is the problem Composer solves for you.
I don't have any experience running Composer on Windows, but I would start here:
http://getcomposer.org/doc/00-intro.md#installation-windows
Using the Installer
This is the easiest way to get Composer set up on your machine.
Download and run Composer-Setup.exe, it will install the latest
Composer version and set up your PATH so that you can just call
composer from any directory in your command line.
Once you have Composer installed, you should simply be able to make a file named composer.json in your project root, with the following contents:
{
"require": {
"omnipay/omnipay": "~2.0"
}
}
Then use the Command Prompt and cd to your project's directory, and run composer update to download the Omnipay files and all their dependencies.

How can a Heroku php buildpack compile sass / yuicompress before building?

I have a simple php buildpack (based on this here: https://github.com/lenglead/heroku-buildpack-php) that I want to expand to compile my assets on build. I don't want to include compiled/minified css/js in my repo, but Heroku needs it to exist. My idea was as follows:
Have a script in my repo that compiles the sass and calls a yuicompress on the javascript/css files and places in them in a specific directory.
Call this in the buildpack before Heroku begins bundling so that when it bundles, it bundles the compiled files in their appropriate location.
However, I'm running into issues since Heroku doesn't have sass/yuicompress installed. I'm very new to Heroku so I'm not sure what direction I should be taking here:
Download and install sass/yui-compress in my buildpack, then run. (like this: https://github.com/abhishekmunie/heroku-buildpack-static-css/)
Have them permanently saved on my Heroku app, via a .gemfile. Is this even possible for php apps or are gemfiles just for ruby?
Also I hear people saying that Heroku is 'readonly' so maybe this isn't even possible? Basically, I'd just like to do the compilation on Heroku rather than keep it in the repo.
Thanks!
I kinda answered this question myself. I'm following the code at https://github.com/abhishekmunie/heroku-buildpack-static-css/ and converting to my needs with decent results. I'd recommend anyone else look at that code as it seems fairly platform agnostic.

Can projects using PHP framework operate standalone?

I am interested in the PHP framework, especially by symfony and ZendFramework, but I am not sure of one thing: I saw the need to type command lines to create a project with these frameworks. Ok, but once the project is finished, is it possible to move files to another server without installing anything (except for Apache)?
Thank you in advance
Ps: No report, but do StackOverflow uses a framework?
It is absolutely possible to run a symfony or zend framework application without installing the framework on the server. Symfony has a special mechanism to pack everything into one folder. If you use zend framework you basically have to copy the "Zend" folder to your "lib" directory and you are ready to go.
As far as I know, StackOverflow is build on ASP.net and C# running on several windows servers.
Firstof, most of those commands are needed for development only. But also you do not have to have the commands in your global path, it's also possible to execute the scripts directly.
In case of symfony that would be something like
./symfony-framework/data/bin/symfony
if you installed symfony to symfony-framework.
I believe stackoverflow is based on .NET MVC or plain ASP .NET - http://meta.stackoverflow.com will give you that answer
With Zend Framework, it is possible. The Zend_Tool part, which sets up the basics of your project is just addition. You can, but you don't have to use it at all. You can just write the project from scratch yourself, just stick to the standard project architecture.
Anyway, once the project is ready, it does not need any command line setup, other than mayby setting correct file system permission if your project needs to write some files.
I can't say about symphony, but I assume it also can be just copied to the target server.
I don't know, how about ZF, but project made with Symfony can be easily moved to another server just by copying files. However it will be difficult to maintain your project without commands. Also you have to copy all Symfony's core files to your server, but it will be better to install Symfony there before.
About Symfony:
Usually, you develop locally on your dev environment (using Wampserver or MAMP for example). You will require access to the command line to run symfony commands, specially for complex tasks like ORM tasks. So you have to install symfony on that environment.
According to the official doc the recommended installation method is through SVN (either the trunk or a tag) inside your project folder.
When you'll push the files from your dev environment to another (using project:deploy if you can), all the required files will be pushed.
So there is no need to install (in the sense of "run" or "execute") anything on the live environment server. The only "installation" method that requires an access to the command line is the PEAR install method, which is not recommended.
The only problem that I had when I deployed an application was a user permission problem on the cache folder, but that's easy to fix by changing the folder permission.

Categories