Set buildpack failed for php application developed using wamp server - php

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?

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_xx‌​xxxx?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!

Related

Set Newrelic APP name from ELB env variable on deploy

I need to deploy the same PHP code to 3 environments on AWS Elastic beanstalk. These environments will report to different Application Names on New relic.
The newrelic license key cannot be deployed to the repository.
Please advise on strategies to achieve this.
For PHP in AWS Elastic Beanstalk you the steps are:
In the .ebextensions folder inside your Elastic BeanStalk application,
create a new file named newrelic.config. Add the following content to
the file:
packages:
yum:
newrelic-php5: []
rpm:
newrelic: INSERT_LINK_TO_AGENT
commands:
configure_new_relic:
command: newrelic-install install
env:
NR_INSTALL_SILENT: true
NR_INSTALL_KEY: INSERT_LICENSE_KEY
From: https://docs.newrelic.com/docs/agents/php-agent/frameworks-libraries/aws-elastic-beanstalk-installation-php
If you are using password vault you would then follow their best practices. If you are not then you may have to create a shell script to replace the license key from a secure S3 bucket.
Put your license key in a secure S3 bucket. Then use a Bash script similar to:
#!/bin/bash
password=$(aws ssm get-parameters --region us-east-1 --names MySecureLicenseKey --with-decryption --query Parameters[0].Value)
# code to replace INSERT_LICENSE_KEY - need to update the path to where you have it land
sed 's/INSERT_LICENSE_KEY/$password/g' /etc/newrelic/newrelic.config
Inspired by: https://aws.amazon.com/blogs/mt/use-parameter-store-to-securely-access-secrets-and-config-data-in-aws-codedeploy/

Deployer - no tty present and no askpass program specified - How to deploy with Deployer

I have trouble deploying with Deployer 4.0.2 and I am in need for help of somebody more experienced than me in this.
I want to deploy a repository of mine to a Ubuntu 16.04 server.
I am using laravel homestead as a development environment, where I also installed deployer. From there I ssh into my remote server.
I was able to deploy my code with the root user, until I hit a RuntimeExceptionthat aborted my deployment.
Do not run Composer as root/super user! See https://getcomposer.org/root for details
That made me create another user called george, whom I gave superuser rights. I copied my public key from my local machine to a newly generated ~/.ssh/authorized_keys file, that gave me permission to access the server via ssh.
Yet when I run dep deploy with the new user:
server('production', '138.68.99.157')
->user('george')
->identityFile()
->set('deploy_path', '/var/www/test');
I get another RuntimeException:
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Now it looks like the new user george cannot access the ~/.ssh/id_rsa.pubkey. So I copy them from the root folder into my home folder and also add the public key in the Github SSH settings.
cp root/.ssh/id_rsa.pub home/george/.ssh/id_rsa.pub
cp root/.ssh/id_rsa home/george/.ssh/id_rsa
Only to get the same error as before.
In the end I had to add github to my list of authorized hosts:
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
Only to get the next RuntimeException
[RuntimeException]
sudo: no tty present and no askpass program specified
I managed to comment this code in the deploy.php
// desc('Restart PHP-FPM service');
// task('php-fpm:restart', function () {
// // The user must have rights for restart service
// // /etc/sudoers: username ALL=NOPASSWD:/bin/systemctl restart php-fpm.service
// run('sudo systemctl restart php-fpm.service');
// });
// after('deploy:symlink', 'php-fpm:restart');
to get the deployment process finally done, and now I ask myself, if the restart of php-fpm is really necessary, for me to continue debugging this deployment tool? Or can I live without it?
And if I need it, can somebody help me understand what I need it for? And maybe as a luxury also provide the solution to the RuntimeException?
Try this:
->identityFile('~/.ssh/id_rsa.pub', '~/.ssh/id_rsa', 'pass phrase')
It works great for me - no need for an askpass program.
It helps to be explicit in my experience.
As for your phpfm restart task .. I haven't seen that before. Shouldn't be needed. :)
EDIT:
That you provide a password is probably a good sign that you ought to refactor your Deployer code a bit if you keep it under source control.
I am loading site specific data from a YAML file - which I am not submitting to source control.
The first bit of my stage.yml :
# Site Configuration
# -------------
prod_1:
host: hostname
user: username
identity_file:
public_key: /home/user/.ssh/key.pub
private_key: /home/user/.ssh/key
password: "password"
stage: production
repository: https://github.com/user/repository.git
deploy_path: /var/www
app:
debug: false
stage: 'prod'
And then, in my deploy.php :
if (!file_exists (__DIR__ . '/deployer/stage/servers.yml')) {
die('Please create "' . __DIR__ . '/deployer/stage/servers.yml" before continuing.' . "\n");
}
serverList(__DIR__ . '/deployer/stage/servers.yml');
set('repository', '{{repository}}');
set('default_stage', 'production');
Notice that, when you use serverList, it replaces your server setup in deploy.php

AWS Elastic Beanstalk Deployment Order

I'm deploying code to a single-instance web server AWS EB environment that will provision/update my connected RDS database. I've got an .ebextensions file that calls deployment code:
---
container_commands:
01deploydb:
command: /var/www/html/php/cli/deploy-db.php
leader_only: true
On the same deployment, I dropped the deploy-db.php file back one directory into /cli/. On deployment, I get ERROR: [Instance: i-*****] Command failed on instance. Return code: 127 Output: /bin/sh: /var/www/html/php/cli/deploy-db.php: No such file or directory.
container_command 01deploydb in .ebextensions/01_db.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
If I deploy a version that does not include the command, then deploy a second update including the command, there is no error. However, adding the command and the file it calls at the same time produces the error. A similar sequence occurred earlier with a different command/file.
My question is: is there a documented order/sequence for how AWS updates the environment? I would have expected that my new version would have fully deployed (and the .php file installed) before container_commands are called.
The commands: section runs before the project files are put in place. This is where you can install server packages for example.
The container_commands: section runs in a staging directory before the files are put in its final destination. Here you can modify your files if you need to. Current path is this staging directory so you can run it like this (I might get the app directory wrong, maybe it should be php/cli/deploy-db.php)
container_commands:
01deploydb:
command: cli/deploy-db.php
leader_only: true
Reference for above: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
You can also run a post deploy scripts. This is not very well documented (at least it wasn't). You can do something like this (it won't be leader only though, but you could put a file in this directory through a container_commands:):
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_deploy.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
/var/www/html/php/cli/deploy-db.php

Why deployer is rejecting my credentials?

I've created a new project to deploy my sources in ubuntu. My workspace, generated by a jenkins extraction is in a webserver.
I've installed deployer in this webserver to put in another server my sources validated by jenkins.
I made a "deploy" directory into the project which includes the receipe directory, the deploy.php, and the servers.yml
I've downloaded the receipe directory because i didn't understand what the receipe/common.php is about : https://github.com/deployphp/deployer/blob/master/recipe/common.php
Here is my deploy.php :
<?php
require 'recipe/common.php';
serverList('config/servers.yml');
set('repository', 'git#xx.xx.xx.xx:/opt/git/intranetv2.git');
Here is my servers.yml :
production:
host: xx.xx.xx.xx
user: administrateur
identity_file:
public_key: "~/.ssh/id_rsa.pub"
private_key: "~/.ssh/id_rsa"
password: "aaaaa"
stage: production
deploy_path: "/var/www/intranet"
branch: master
I don't understand why it rejects me when i do :
dep deploy:release production
It is unable to connect with the given credentials.
Thanks.
Does it working then you do it by hands? Do you have password on keys?

repository not found on heroku

Originally tried out Heroku (in order to learn how to use it) and deployed an app, tastyall. Eventually went into Heroku to delete everything done in order to start over (what is below). My Heroku dashboard showed no apps before starting what is below.
My blackopp folder on my desktop contains my empty composer.json and idex.php test file which says contains code to say “Hello”.
My question: why can I not get rid of the old app info that seems to be causing confusion? Where is this coming from? I see it says: rename tastyallphp.php => blackopp.php (100%) but can't seem to make sense of this since there should be no ref to "tasty..." anything.
$ cd /Users/xxxx/Desktop/blackopp
$ pwd
/Users/xxxx/Desktop/blackopp
$ git init
Reinitialized existing Git repository in /Users/xxxx/Desktop/blackopp/.git/
$ git add .
$ git commit -m "initial commit"
[master bff3b6c] initial commit
Committer: xxxx
Your name and email address were configured automatically……
1 file changed, 0 insertions(+), 0 deletions(-)
rename tastyallphp.php => blackopp.php (100%)
$ heroku create blackopp
Creating blackopp... done, stack is cedar-14
https://blackopp.herokuapp.com/ | https://git.heroku.com/blackopp.git
$ git push heroku master
remote: ! No such app as tastyallapp.
fatal: repository 'https://git.heroku.com/tastyallapp.git/' not found
I wonder if deleting my entire Heroku account and starting over would be easier but thought to ask my qestion first.
The app name tastyallapp will be coming from the definition of your heroku remote in the repository config. This is what's used to determine the destination when you do git push heroku master.
Starting over would be one option, but if you'd like to try to fix it you can do:
git remote remove heroku
to remove the previous remote from the old app, and then:
heroku git:remote -a blackopp
to add a new remote that matches the current app name.

Categories