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
- First register an account and a heroku account
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"
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:
-
app creation completed Then you will see the interface as shown below:
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:
- 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 ml′thiseach 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.