Reputation: 51
My application folder name is "social_network". It is in wamp\www path. I am trying to deploy app folder("social_network") to heroku using git commands.I followed all the instructions of heroku's instructions pages. I included composer.json file in the app folder, installed composer, kept Procfile. I even gave the commands of "heroku buildpacks:set
".But still the push is being failed with an error message "set buildpack failed".The code in Procfile is:
"web: vendor/bin/heroku-php-apache2."
Is this the process type to be given for the app in wamp server? What folder should I try to deploy- wamp or social_network?I doubt if there will be any more changes to make inorder to deploy as it is developed using wamp server.How can I deploy successfully?
Upvotes: 1
Views: 82
Reputation: 51
The mistake that I had done was having the files of composer.json and Procfile along with my php files under social_network folder while the repository was created in www folder(I had my .git folder in www folder). So, heroku was not able to recognize my app as a php app and the push failed.
As I had a great difficulty to deploy my php application that was developed through wamp server, I would like to explain all the steps involved in deploying the php app which needs a database to heroku.
It is better to have all the application files directly under www folder.
The following documentation can be referred:
Getting started with heroku for php:
Have a heroku account, install php, and install composer and run it. The composer will download required packages in a folder called vendor which should be in your app directory.
Download heroku CLI and login to heroku using the command:
heroku login
Include composer.json file so that heroku recognizes that the application is a php app. It should contain the following code:
{
"require": {
"php": "^5.5.12"
}
}
The above code will instruct Heroku to use the latest version of PHP 5. The version can be anything which your app uses.
Have a Procfile to declare what command should be executed to start the app. It should have the following code:
web: vendor/bin/heroku-php-apache2
Now in cmd, make sure that the path of your www folder:
c:\wamp\www>
If there are any changes made to composer.json file, update the composer.lock file by:
c:\wamp\www> update composer
Next, create a new repository in the www folder by:
c:\wamp\www>git init
Then add your files to the repository.
c:\wamp\www>git add .
Then commit:
c:\wamp\www>git commit
Then create an app in heroku
c:\wamp\www>heroku create
Then comes the part of creating database and establishing connection:
The following documentation can be referred:
ClearDb Database documentation for php by heroku
Create a database:
C:\wamp\www>heroku addons:create cleardb:ignite
Set the url of the database to the app created in heroku:
C:\wamp\www> heroku config:set DATABASE_URL='the url that was created by the above command'
To know the CLEARDB_DATABASE_URL:
C:\wamp\www>heroku config
which gives the url:
CLEARDB_DATABASE_URL= mysql://user:password@host/heroku_db?reconnect=true
Example of the CLEARDB_DATABASE_URL:
mysql://b8xxxxxx:edxxxx@ us-cdbr-iron-east-04.cleardb.net/heroku_xxxxxx?reconnect=true
.
To dump the existing sql file to the sql database in heroku, make sure that the PATH had been set for mysql and then give the following commands:
To get a mysql prompt with connection to the database.
C:\wamp\www>mysql -u b8xxxxxx -h us-cdbr-iron-east-04.cleardb.net -p heroku_xxxxxx
To dump the existing file to heroku database:
C:\wamp\www>mysql --host=us-cdbr-iron-east-04.cleardb.net --user=b8xxxxxx --password=edxxxxxx --reconnect heroku_xxxxxx< yoursqlfile.sql
Now use the database created and connect to it in your code:
<?php
$url = parse_url(getenv("CLEARDB_DATABASE_URL"));
$server = $url["host"];
$username = $url["user"];
$password = $url["pass"];
$db = substr($url["path"], 1);
$con = mysqli_connect("$server", "$username", "$password", "$db");
?>
Then push to the app created in heroku:
c:\wamp\www>git push heroku master
Open the app:
c:\wamp\www>heroku open
That's it! Now the website is hosted onto heroku successfully!
Upvotes: 1