PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 7, 2022

[FIXED] Include Python libraries in composer.json for Heroku

 March 07, 2022     composer-php, heroku, php, python     No comments   

Issue

I'm trying to deploying an app with Heroku via PHP, but it runs a Python script that is dependent on Python libraries to run (e.g. numpy).

How would I go about including this dependency in a composer.json file?


Solution

Use multiple buildpacks.

  1. Configure your application to use the official PHP buildpack:

    heroku buildpacks:set heroku/php
    
  2. Add the official Python buildpack:

    heroku buildpacks:add --index 1 heroku/python
    

    Running heroku buildpacks should show the Python buildpack first and the PHP one second.

    The last buildpack in the list will be used to determine the process types for the application. Any process types defined from earlier buildpacks will be ignored.

  3. Make sure you have a composer.json that defines your PHP dependencies in the root of your repository for your PHP buildpack.

  4. Make sure you have either a requirements.txt file (if you want to use pip) or a Pipfile and Pipfile.lock (if you want to use Pipenv) that defines your Python dependencies in the root of your repository for your Python buildpack.

    It's also a good idea to specify the supported Python version that you wish to use. If you are using Pipenv, this information can be included in your Pipfile. If you are using pip you can use a runtime.txt file in the root of your repository.

The next time you deploy you should see your Python dependencies get installed first, followed by your PHP dependencies.



Answered By - Chris
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing