Home Backend Development PHP Tutorial Deploying PHP applications on Heroku

Deploying PHP applications on Heroku

Jul 29, 2016 am 09:04 AM
git https php

Heroku deploys PHP applications

I read a technical blog post on 51cto today, and accidentally saw the heroku cloud platform. As for what this platform does, it’s a long story. The following will focus on how to deploy PHP applications through heroku.

hrerku official website: https://www.heroku.com/

1. Basic operations

Friends who are already familiar with heroku can skip this step

  1. First register an account and a heroku account
  2. Log in after registration Go to heroku, then go directly to the management background, then click "Personal Apps" on the left menu, enter the page as shown below, click the "+" button on the upper right, and select "Create new app"
    Deploying PHP applications on Heroku

  3. Enter the create app page, fill in the app name and select the server location. A project web address will be generated based on the app name: https://myapp-one.herokuapp.com/, as shown in the following figure:
    Deploying PHP applications on Heroku

  4. app creation completed Then you will see the interface as shown below:
    Deploying PHP applications on Heroku
    As shown in the picture, the app page will have 5 tab navigation

    • Resources
      What is placed is the project configuration information and third application (database or something)
    • Deploy
      Here I tell you how to deploy your application, which is also the focus of the discussion later
    • Metrics
      Indicates the current project status
    • Activity
      It’s the log of the deployment operation
    • Access
      Project Owner
    • Settings
      Project settings, such as modifying the project name, project git address information, deletion, etc.

2. Deploy PHP applications

After the above basic operations are understood and prepared, we can talk about the focus of this article, how to deploy PHP applications

  • Open the created application, take the myapp-one I created here as an example, click the "deploy" tab, and then as shown in the figure below, the default is to use heroku git, it can also be github or dropbox, today I will focus on heroku's own Git deployment operation, in fact, the following has roughly introduced how to operate it, I will translate it: Deploying PHP applications on Heroku
  • Download the heroku command line tool, there will be different versions for download according to different platforms. After the download is completed, enter your terminal and enter Enter the following command. After entering, press Enter to prompt you to enter your registration email and password. If you successfully log in, you will be prompted with a success message
<code><span>$ </span>heroku login</code>
Copy after login
  • After successful login, enter the project directory you want to deploy, initialize git and set the git project address
<code>$ git init
$ heroku git:remote -<span>a</span> myadd-<span>one</span><span># </span>
或者 
$ git remote <span>add</span> heroku <span>https</span>://git.heroku.com/myapp-<span>one</span>.git</code>
Copy after login
  • After completion, submit the project to git
<code><span>$ </span>git add -<span>A</span><span>$ </span>git commit -m <span>"init myapp-one"</span></code>
Copy after login
  • Create a composer.json file in the project directory with the content {}, and then submit it to the project
<code><span>$ </span>echo <span>"{}"</span> > composer.json
<span>$ </span>git add  composer.json
<span>$ </span>git commit -m <span>"add  composer.json"</span></code>
Copy after login
  • Set up heroku's php build toolkit
<code>$ heroku buildpacks:<span>set</span> https:<span>//github.com/heroku/heroku-buildpack-php</span></code>
Copy after login

-Add a Procfile file in the project root directory to set the initial command for project execution (very important, explain 'php -S 0.0.0.0:POR T?tsite/api /ht mlthiseach justis php5.4ofafter WITH ofwebserver , Use 0.0.0.0Table showanyWHE MachineAppliance CanVisitAsk, PORT is the port (no need to change) , -t means docroot. If you start the web directory, you don’t need to write it in the root directory. If it is in a subdirectory, just write the relative path (such as site/api/html),

<code><span>$ </span>echo <span>" web: php -S 0.0.0.0:$PORT -t site/api/html  "</span> > <span>Procfile</span><span>$ </span>git add  <span>Procfile</span><span>$ </span>git commit -m <span>"add Procfile to start program"</span></code>
Copy after login
Finally execute the following command to deploy the project online
<code><span>$ </span>git push heroku master <span>#部署项目,每次修改了也要执行这个命令</span><span>$ </span>heroku open <span># 打开项目,其实就是用浏览器访问当前web应用</span></code>
Copy after login
I personally tried the above successful configuration process. If there are any omissions, please forgive meFor specific reference, the official documents are as follows:Official instructions for PHP deployment: https://devcenter.heroku.com/articles/getting-started- with-php#introductionHeroku PHP build package address: https://github.com/heroku/heroku-buildpack-phpheroku command line tool instructions: https://devcenter.heroku.com/categories/command -line').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); }); The above introduces the deployment of PHP applications on Heroku, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
The Continued Use of PHP: Reasons for Its Endurance The Continued Use of PHP: Reasons for Its Endurance Apr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

The top ten free platform recommendations for real-time data on currency circle markets are released The top ten free platform recommendations for real-time data on currency circle markets are released Apr 22, 2025 am 08:12 AM

Cryptocurrency data platforms suitable for beginners include CoinMarketCap and non-small trumpet. 1. CoinMarketCap provides global real-time price, market value, and trading volume rankings for novice and basic analysis needs. 2. The non-small quotation provides a Chinese-friendly interface, suitable for Chinese users to quickly screen low-risk potential projects.

The Compatibility of IIS and PHP: A Deep Dive The Compatibility of IIS and PHP: A Deep Dive Apr 22, 2025 am 12:01 AM

IIS and PHP are compatible and are implemented through FastCGI. 1.IIS forwards the .php file request to the FastCGI module through the configuration file. 2. The FastCGI module starts the PHP process to process requests to improve performance and stability. 3. In actual applications, you need to pay attention to configuration details, error debugging and performance optimization.

How to set the default run configuration list of SpringBoot projects in Idea for team members to share? How to set the default run configuration list of SpringBoot projects in Idea for team members to share? Apr 19, 2025 pm 11:24 PM

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...

When building a microservice architecture using Spring Cloud Alibaba, do you have to manage each module in a parent-child engineering structure? When building a microservice architecture using Spring Cloud Alibaba, do you have to manage each module in a parent-child engineering structure? Apr 19, 2025 pm 08:09 PM

About SpringCloudAlibaba microservices modular development using SpringCloud...

Git: The Core of Version Control, GitHub: Social Coding Git: The Core of Version Control, GitHub: Social Coding Apr 23, 2025 am 12:04 AM

Git and GitHub are key tools for modern software development. Git provides version control capabilities to manage code through repositories, branches, commits and merges. GitHub provides code hosting and collaboration features such as Issues and PullRequests. Using Git and GitHub can significantly improve development efficiency and team collaboration capabilities.

Using Laravel: Streamlining Web Development with PHP Using Laravel: Streamlining Web Development with PHP Apr 19, 2025 am 12:18 AM

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

See all articles