Deploying a PHP and MySQL Web App with Heroku (ok)
https://scotch.io/@phalconVee/deploying-a-php-and-mysql-web-app-with-heroku
Last updated
https://scotch.io/@phalconVee/deploying-a-php-and-mysql-web-app-with-heroku
Last updated
Henry Ugochukwu(@LK_wapiti)August 30, 20177 Comments26,147 Views BookmarkCODE DEMO PROJECT
We are going to deploy an app making it publicly accessible on the web with a fantastic service named Heroku. Heroku makes it easy to deploy web apps currently located on your own computer to the web, with just a few simple commands. Before you can deploy apps using Heroku you need two things;
A Heroku account and
Git installed on your machine After creating an account and logging in you’ll see your Heroku dashboard. You will see immediately after login, a notification prompting you to download the Heroku tool belt for your system OS.
With our Heroku account created and Heroku tool belt installed, we can start in on deploying our app.
I prefer to create my PHP projects in my xampp/htdocs directory. So open your terminal and navigate to your preferred path to store this project.
This we do by issuing the Heroku login command as shown below
You’ll be asked for your login credentials (email and password) to proceed. After doing this you are set to begin.
We also need to create a composer.json file as every PHP application deployed by Heroku is required to have one. So inside your folder create a composer.json file.
For the sake of demonstration I’ve prepared another simple PHP web app to deploy using Heroku. You can use any available PHP/MySQL app you have or get the one for this tutorial from GitHub. Once you have downloaded the source or if you have an app you want to use be sure to navigate back into the specified directory on the terminal and continue the steps below. Note: if you are in a new folder don’t forget to “git init” & also “git add .” before you proceed to the other steps below.
Using the git push heroku master
command
ClearDB addon makes it super easy to grab all of the relevant connection information. In our database file you should nave something like below
Next, we update the composer.json file to include the MySQL extension. My database driver is mysqli so I basically need the mysqli extension as seen below
Then
Finally
The running app is just an OAUTH app using codeigniter 3, you should probably test with only the google and facebook sign in buttons. This same exact process we just followed will work for hosting any PHP application using Heroku.
Thanks for your time, and I hope this was helpful.
Like this article? Follow @LK_wapiti on Twitter
The first thing we are going to do is to create a test PHP file which we eventually deploy on heroku. Open your text editor and create an index.php file
The final requirement before we can deploy is to establish a git repository in our directory. Heroku requires a git repository to work its magic during the deployment process.And we are all set!!!
We will start by creating our new Heroku application using the “heroku create” commandBy running the above command our Heroku application was generated and assigned a new auto generated application name. After we deploy our application we will be able to access it using the URL you see here in the terminal [https://….] in our web browser.
To deploy the application we simply run a “git push” command, pushing the files up to Heroku.Heroku automatically detects that we’re deploying a PHP application and sets up the environment appropriately. You can copy your apps URL and take a look at it in the browser.Walla!!! That’s how easy it is to deploy an app publicly using Heroku
Since our app is connected to a local database on our machine, Heroku has no access to it. We can fix this by creating a new MySQL database within Heroku. Heroku offers a “ClearDB” addon which we can add to our application using the Heroku addon ads command in other to attach a MySQL database to it. We do this using the command heroku addons:add cleardb:ignite
as shown below
For those that downloaded the source you will see a SQL file in the root folder, if you already have a database you want to use, export it from localhost/phymyadmin to get going. Let’s connect to our Heroku database and import it using the command heroku config | grep CLEARDB_DATABASE_URL
as shown below in the terminalNow we can import the database export file I previously created (or the one you have) to our CLEARDB database using the command below. Notice that the sql file is stored in my apps root directory.
NB: The above command will be slightly different from yours, so check with caution.Quick Note: When prompted for password, use the one as obtained in here.
Then run composer update
to load the necessary dependenciesWe are good to go!!
All set, now let’s go to back to our browser and make sure our new database connection is working properly. See mine on https://immense-brushlands-25104.herokuapp.com/social_auth