Here is a step-by-step guide on how to set up a PHP and MySQL app on Heroku:
First, you'll need to create a Heroku account if you haven't already. You can do this by going to heroku.com and clicking the "Sign up" button.
Once you've created an account, log in to the Heroku Dashboard.
Click the "New" button in the top right corner of the dashboard and select "Create new app".
Give your app a name and select the region you want it to be hosted in.
Click the "Create app" button.
Next, you'll need to add a new add-on to your app. Search for the "ClearDB MySQL" add-on and select it.
Choose the pricing plan that best suits your needs and click "Provision".
After the add-on is provisioned, go to the "Settings" tab of your app and click the "Reveal Config Vars" button.
You'll need to add a few environment variables to connect to your MySQL database. The exact variable names may vary depending on your add-on, but they should look something like this:
CLEARDB_DATABASE_URL
: This variable will contain the URL of your MySQL database. You'll need to use this URL to connect to your database in your PHP code.
CLEARDB_DATABASE_NAME
: This variable will contain the name of your MySQL database.
CLEARDB_DATABASE_USERNAME
: This variable will contain the username you'll use to connect to your MySQL database.
CLEARDB_DATABASE_PASSWORD
: This variable will contain the password you'll use to connect to your MySQL database.
{
"require": {
"php": ">=7.0.0"
}
}
web: vendor/bin/heroku-php-apache2 public/
This Procfile tells Heroku to use the heroku-php-apache2 buildpack to run your app, and to serve the files in the public directory.
git init
git add .
git commit -m "Initial commit"
heroku git:remote -a <your-app-name>
git push heroku master
That's it! You now have a PHP and MySQL app running on Heroku.