PHP Steem Apps with Steem Connect and Laravel - Part I: Initial Setup by hernandev

View this thread on steempeak.com
· @hernandev · (edited)
$105.61
PHP Steem Apps with Steem Connect and Laravel - Part I: Initial Setup
![image.png](https://cdn.utopian.io/posts/7f00c43b0a83b66980d4f10124e7ce6ff96bimage.png)


#### What Will I Learn?
This tutorial is the first installment of a series of tutorials providing step-by-step instructions to bootstrap a Steem based application using the [Laravel Framework](https://laravel.com) and [SteemConnect](https://steemconnect.com) (though the [SteemConnect SDK](https://github.com/hernandev/sc2-sdk-php) for PHP).

- 1 - Registering a SteemConnect application.
- 2 - Creating the Project.
- 3 - Laravel Configuration.
- 4 - Installing Dependencies.

#### Requirements
To follow this tutorial series, you should be familiar with the following:

- A [PHP](https://php.net) [7.1+](https://secure.php.net/supported-versions.php) environment with [Composer](https://getcomposer.org/) installed.
- Basic PHP experience.
- Basic Laravel Framework experience.
- Basic understanding of SteemConnect.
- Basic understanding of the Steem blockchain RPC.
- Basic command line experience.

#### Difficulty

- Basic to Intermediate, depending on the previous knowledge of each of the requirements.

#### Tutorial Contents

In this tutorial we are going to start a Laravel application, configure the very basic bits and install the package dependencies need in order to setup SteemConnect and the RPC client.1

For the fun of it, we will call this application LaraSteem, which is just joining the words Laravel and Steem.

##### Registering a SteemConnect application.

SteemConnect applications, are in it's core, special Steem accounts handled by SteemConnect. They are used to sign the transactions in behalf of the users.

In other to create applications that interacts with the Steem blockchain through SteemConnect, we need to register those applications.

So, head to the SteemConnect dashboard, at [https://steemconnect.com/dashboard](https://steemconnect.com/dashboard) and click on the **[My Apps](https://steemconnect.com/apps/me)** menu.

If you never did this process before, this will will not show any application, and we are going to create the first one.

If you already have an application registered there, you may chose to use the existing ones or create a new one.

The menu link can be seen highlighted on the image below:

 ![image.png](https://cdn.utopian.io/posts/9f88f110ea436adeca2a6a7d7e3dded8d6faimage.png)

To then register a new application, you may click the **[New App](https://steemconnect.com/apps/create)** link, also, highlighted on the screenshot below:

![image.png](https://cdn.utopian.io/posts/b003bb5136aac5c294a8314fa243cbe9c6bcimage.png)

Now, it's time to chose your application name. You may notice on the application creation form, that a 3 STEEM balance is required. That's because each SteemConnect application, is itself a Steem account.

One common practice here is to name the SteemConnect applications the same username your main account uses, in our case, we are calling the example application `LaraSteem`, so the convention recommends creating the application as `larasteem.app`

![image.png](https://cdn.utopian.io/posts/b343207c152f73b2c6b8262c95b84255b8d6image.png)

After setting the name of our SteemConnect application, just click the **"Create Application"** button.

This will redirect us for the application settings page, that will be empty, since it's a newly created application.

On the screenshot below, you can notice I've filled most of the details, and you may set those as you wish.

There is, one little point we need to be careful here. The **`Redirect URI(s)`** must match the URL on the application, that will be responsible for handling the authorization flow.

We will build this later on this tutorial series, but for now, assuming we will use the Laravel embedded HTTP server, se the value to `http://localhost:8080/auth/callback`, and later this will make more sense, once we build the authentication code.

![image.png](https://cdn.utopian.io/posts/855c4d221b6d8745bec2bc881fd2b2f8eab5image.png)

The application visible / not visible setting, is just a setting that will not list your application on the SteemConnect dashboard for others to discover. There's no security problems at making it visible, it's your choice.

Also, the application icon, is optional, but highly recommended. You need to use an external image host to upload the icon, feel free to chose one.

After clicking save, the page will stay there on screen, we will need to refresh that page, to ensure the icon appears:

![image.png](https://cdn.utopian.io/posts/8e2f458e51ac1af0e093bfe8595684f25d4eimage.png)

After configuring the application, we will return to the **[My Apps](https://steemconnect.com/apps/me)** page, were we can now see the newly created application listed, among any other applications you may have.

Click the application name, to show it's details:

![image.png](https://cdn.utopian.io/posts/65f39c88a0f5f95aaae13161c83f9daa27ddimage.png)

On the application details, will you find the corresponding OAuth client id (which is the application name itself) and a yet hidden client secret. Hit "click to reveal" so you can obtain the secret key that will later be used to authenticate users on the application.

![image.png](https://cdn.utopian.io/posts/765f5e9d84eb0d597a8b841a0bca10b3c35aimage.png)

Write down the value revealed on the client secret field, and be aware of this:

---
> **Never Reveal the client secret to anyone, it's an information only your application and SteemConnect know. As the name suggests it's a secret and you should take care of it just like you would with your Steem account password.**
---

##### Creating the Project.

Finally, we will start on the code side of things. To create the LaraSteem application, we will start on a default Laravel skeleton, which could be obtained by the `composer create` command.

So, let's create the application:

```bash
composer create laravel/laravel lara-steem
```

This will be enough for generating the Laravel skeleton on a directory called `lara-steem`.

After doing this, feel free to open this directory on your preferred PHP code editor or IDE. On a personal choice, I personally use the PHPStorm IDE by Jetbrains, but, any editor will work just fine.

Also, any command line instruction from now one, will assume your working directory is the `lara-steem` folder. 

Now, an optional step, but highly recommended it's to set a base namespace for the application, we will set the base namespace as `LaraSteem` so it matches our project name.

To rename all source code at once, we can run the Laravel Artisan command:

```bash
php artisan app:name LaraSteem
```

To ensure no composer caching was left behind after this, run the auto-loader dump command on composer:

```bash
composer dump
```

##### Laravel Configuration.

If you are not familiar with Laravel, you should take a few minutes to read through its [configuration documentation](https://laravel.com/docs/5.6/configuration). 

For this tutorial we will use SQLite for the database and file for caching, to make it really simple to follow by novices.

If you have any experience with Laravel, it's recommended you use Redis as the caching driver, and MySQL or PostgreSQL as the database.

##### Application name.

Most of the configuration, will be done in the `.env` file that can be found at the root of the `lara-steem` directory.

Edit this file, changing the variable `APP_NAME`  to LaraSteem (or any other name you may wanna use).

Also, change the **`DB_CONNECTION`** variable value to `sqlite`

You may remove the other `DB_*` variables, if you are using SQLite. Feel free to configure this as you wish.

At the end, the .env file would look something like this:

```env
APP_NAME=LaraSteem
APP_ENV=local
APP_KEY=base64:XBM2S/h9Bt5E/RLBoBHsj2nF0hGC/ZZQif71Xq8Q1nc=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=sqlite

BROADCAST_DRIVER=log
```

The APP_KEY is set dynamically, please do not use the same shown on this tutorial, keep the one generated locally when you created the application or generate a new one with the `php artisan key:generate` command.

###### Starting the SQLite Database file.

When using the SQLite driver for database, we will init the SQLite database file by running the following command.

```sh
touch database/database.sqlite
```

##### Installing the Dependencies.

As for the package dependencies, we will use on the LaraSteem application:

- [hernandev/sc2-sdk-php](https://github.com/hernandev/sc2-sdk-php)

The SDK client will handle all authentication, authorization and broadcasting of operations to the Steem blockchain.

To install the SteemConnect SDK for PHP, run the following command:

```sh
composer require hernandev/sc2-sdk-php
```

- [hernandev/light-rpc](https://github.com/hernandev/light-rpc)

The LightRPC client will be used to call Steem API and retrieve content.

To install the LightRPC client library, run the following command:

```sh
composer require hernandev/light-rpc
```

On the next installment of this tutorial series, we will configure both SDK and LightRPC clients for usage within a Laravel project.

#### Curriculum

You just read the Part I of a tutorial series, all installments are listed bellow:

- [Part I: Initial Setup](https://utopian.io/utopian-io/@hernandev/php-steem-apps-with-steem-connect-and-laravel-part-i-initial-setup)
- [Part II: Steem Configuration](https://utopian.io/utopian-io/@hernandev/php-steem-apps-with-steem-connect-and-laravel-part-ii-steem-configuration)
- *@todo: update with the other parts once published.*

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@hernandev/php-steem-apps-with-steem-connect-and-laravel-part-i-initial-setup">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
post_id43,459,903
authorhernandev
permlinkphp-steem-apps-with-steem-connect-and-laravel-part-i-initial-setup
categoryutopian-io
json_metadata"{"staff_pick": null, "platform": "github", "config": {"questions": [{"question": "Does the tutorial address a minimum of 3 substantial concepts and no more than 5?", "answers": [{"answer": "3-5 substantial concepts covered in the tutorial.", "value": 10, "answer_id": 1}, {"answer": "Less than 3 or more than 5 substantial concepts covered in the tutorial.", "value": 5, "answer_id": 2}, {"answer": "No substantial or recognisable concepts.", "value": 0, "answer_id": 3}], "question_id": "tut-1"}, {"question": "Concepts covered in the tutorial are indicated in the post text with a short description of each concept and when appropriate, images?", "answers": [{"answer": "Thorough text and images for concepts covered.", "value": 10, "answer_id": 1}, {"answer": "Minimal text and images.", "value": 5, "answer_id": 2}, {"answer": "No or very little text and images.", "value": 0, "answer_id": 3}], "question_id": "tut-2"}, {"question": "Does the contributor provide supplementary resources, such as code and sample files in the contribution post or a GitHub repository?", "answers": [{"answer": "Yes", "value": 10, "answer_id": 1}, {"answer": "No", "value": 0, "answer_id": 2}], "question_id": "tut-3"}, {"question": "Is the tutorial part of a series?", "answers": [{"answer": "Yes.", "value": 10, "answer_id": 1}, {"answer": "Yes, but first entry in the series.", "value": 5, "answer_id": 2}, {"answer": "No.", "value": 0, "answer_id": 3}], "question_id": "tut-4"}, {"question": "Is there an outline for the tutorial content at the beginning of the post?", "answers": [{"answer": "Yes.", "value": 10, "answer_id": 1}, {"answer": "Yes, but not detailed enough or does not cover all sections.", "value": 5, "answer_id": 2}, {"answer": "No.", "value": 0, "answer_id": 3}], "question_id": "tut-5"}, {"question": "Does the writing style meet the Utopian standard considering formalness, informativeness and clarity of the content?", "answers": [{"answer": "It is formal, informative and well written with clear content.", "value": 10, "answer_id": 1}, {"answer": "It is informative with clear content but not formal enough.", "value": 5, "answer_id": 2}, {"answer": "The contribution could be more informative or contains unrelated information, formality and clarity of the content are good enough.", "value": 4, "answer_id": 3}, {"answer": "Not all sections were clear enough but overall holds value for the project.", "value": 2, "answer_id": 4}, {"answer": "Not at all.", "value": 0, "answer_id": 5}], "question_id": "c-1"}, {"question": "Was the provided category template for the editor followed?", "answers": [{"answer": "All points of the template were included with additional points as well.", "value": 5, "answer_id": 1}, {"answer": "The template was followed without additions.", "value": 4, "answer_id": 2}, {"answer": "The template was edited but the points were covered in different way.", "value": 3, "answer_id": 3}, {"answer": "Not all points of the template were covered in the contribution but the structure is clear enough.", "value": 3, "answer_id": 4}, {"answer": "The template was not followed but the structure is clear enough.", "value": 2, "answer_id": 5}, {"answer": "The contents are not clearly structured at all.", "value": 0, "answer_id": 6}], "question_id": "c-2"}, {"question": "Did the contributor tag other users?", "answers": [{"answer": "No other users were tagged by the contributor.", "value": 5, "answer_id": 1}, {"answer": "Used tags are reasonable and all tagged people are connected to the project and/or the contribution.", "value": 5, "answer_id": 2}, {"answer": "The contribution contains mentions of other users that are not directly related to the contribution but related in other ways.", "value": 2, "answer_id": 3}, {"answer": "The contributor misuses tagging of other users.", "value": 0, "answer_id": 4}], "question_id": "c-3"}, {"question": "Did the contributor ask for upvotes, resteems, follows or witness vote?", "answers": [{"answer": "No", "value": 5, "answer_id": 1}, {"answer": "Yes, but not in a way that disturbs readability. ", "value": 5, "answer_id": 2}, {"answer": "Yes.", "value": 0, "answer_id": 3}], "question_id": "c-4"}, {"question": "Was a graphical content like images, charts, videos or screenshots included?", "answers": [{"answer": "Yes, the graphical content is included and adds more value to the contribution.", "value": 5, "answer_id": 1}, {"answer": "No but the contribution works well without graphical content well.", "value": 4, "answer_id": 2}, {"answer": "Yes, but most of the graphical content\u2019s purpose is just for presentational matters.", "value": 3, "answer_id": 3}, {"answer": "No relevant or useful graphical content is included in the contribution.", "value": 0, "answer_id": 4}], "question_id": "c-5"}, {"question": "How would you rate the overall added value?", "answers": [{"answer": "Extraordinary value to both the project and the open source community overall.", "value": 20, "answer_id": 1}, {"answer": "Significant value to the project or open source community.", "value": 15, "answer_id": 2}, {"answer": "Some value to the project or open source community.", "value": 10, "answer_id": 3}, {"answer": "Little value to the project or open source community.", "value": 5, "answer_id": 4}, {"answer": "No obvious value to project or open source community.", "value": 0, "answer_id": 5}], "question_id": "c-6"}]}, "pullRequests": [], "users": ["hernandev", "todo"], "questions": null, "app": "utopian/1.0.0", "score": null, "type": "tutorials", "links": ["https://cdn.utopian.io/posts/7f00c43b0a83b66980d4f10124e7ce6ff96bimage.png", "https://laravel.com", "https://steemconnect.com", "https://github.com/hernandev/sc2-sdk-php", "https://php.net", "https://secure.php.net/supported-versions.php", "https://getcomposer.org/", "https://steemconnect.com/dashboard", "https://steemconnect.com/apps/me", "https://cdn.utopian.io/posts/9f88f110ea436adeca2a6a7d7e3dded8d6faimage.png", "https://steemconnect.com/apps/create", "https://cdn.utopian.io/posts/b003bb5136aac5c294a8314fa243cbe9c6bcimage.png", "https://cdn.utopian.io/posts/b343207c152f73b2c6b8262c95b84255b8d6image.png", "https://cdn.utopian.io/posts/855c4d221b6d8745bec2bc881fd2b2f8eab5image.png", "https://cdn.utopian.io/posts/8e2f458e51ac1af0e093bfe8595684f25d4eimage.png", "https://cdn.utopian.io/posts/65f39c88a0f5f95aaae13161c83f9daa27ddimage.png", "https://cdn.utopian.io/posts/765f5e9d84eb0d597a8b841a0bca10b3c35aimage.png", "https://laravel.com/docs/5.6/configuration", "https://github.com/hernandev/light-rpc", "https://utopian.io/utopian-io/@hernandev/php-steem-apps-with-steem-connect-and-laravel-part-i-initial-setup", "https://utopian.io/utopian-io/@hernandev/php-steem-apps-with-steem-connect-and-laravel-part-ii-steem-configuration"], "moderator": {"time": "2018-04-14T16:29:23.509Z", "pending": false, "reviewed": true, "flagged": false, "account": "cha0s0000"}, "community": "utopian", "tags": ["utopian-io", "php", "laravel", "steemconnect", "steemdev"], "total_influence": null, "repository": {"full_name": "hernandev/sc2-sdk-php", "owner": {"login": "hernandev"}, "id": 123650676, "fork": false, "html_url": "https://github.com/hernandev/sc2-sdk-php", "name": "sc2-sdk-php"}, "image": ["https://cdn.utopian.io/posts/7f00c43b0a83b66980d4f10124e7ce6ff96bimage.png"], "format": "markdown"}"
created2018-04-13 21:22:39
last_update2018-04-14 16:29:27
depth0
children3
net_rshares24,253,063,615,587
last_payout2018-04-20 21:22:39
cashout_time1969-12-31 23:59:59
total_payout_value76.137 SBD
curator_payout_value29.473 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9,768
author_reputation12,365,800,117,459
root_title"PHP Steem Apps with Steem Connect and Laravel - Part I: Initial Setup"
beneficiaries
0.
weight1,500
accountutopian.pay
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (32)
@cha0s0000 ·
thanks for the contribution , it has been approved 

----------------------------------------------------------------------
Need help? Write a ticket on https://support.utopian.io.
Chat with us on [Discord](https://discord.gg/uTyJkNm).

**[[utopian-moderator]](https://utopian.io/moderators)**
properties (22)
post_id43,581,161
authorcha0s0000
permlinkre-hernandev-php-steem-apps-with-steem-connect-and-laravel-part-i-initial-setup-20180414t163136142z
categoryutopian-io
json_metadata"{"app": "utopian/1.0.0", "community": "utopian", "tags": ["utopian-io"]}"
created2018-04-14 16:31:30
last_update2018-04-14 16:31:30
depth1
children0
net_rshares0
last_payout2018-04-21 16:31:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length293
author_reputation30,982,118,529,863
root_title"PHP Steem Apps with Steem Connect and Laravel - Part I: Initial Setup"
beneficiaries
0.
weight1,500
accountutopian.pay
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@utopian-io ·
### Hey @hernandev I am @utopian-io. I have just upvoted you!
#### Achievements
- You have less than 500 followers. Just gave you a gift to help you succeed!
- Seems like you contribute quite often. AMAZING!
#### Utopian Witness!
<a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness</a>

**Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x**
properties (22)
post_id43,626,964
authorutopian-io
permlinkre-hernandev-php-steem-apps-with-steem-connect-and-laravel-part-i-initial-setup-20180415t001057462z
categoryutopian-io
json_metadata"{"app": "utopian/1.0.0", "community": "utopian", "tags": ["utopian-io"]}"
created2018-04-15 00:10:57
last_update2018-04-15 00:10:57
depth1
children0
net_rshares0
last_payout2018-04-22 00:10:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length714
author_reputation152,913,012,544,965
root_title"PHP Steem Apps with Steem Connect and Laravel - Part I: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@doctorvee ·
This is very informative and I learnt a lot from it, thanks Master @Hernandev you're awesome
👍  
properties (23)
post_id45,067,561
authordoctorvee
permlinkre-hernandev-php-steem-apps-with-steem-connect-and-laravel-part-i-initial-setup-20180423t213135319z
categoryutopian-io
json_metadata"{"app": "steemit/0.1", "users": ["hernandev"], "tags": ["utopian-io"]}"
created2018-04-23 21:31:36
last_update2018-04-23 21:31:36
depth1
children0
net_rshares1,949,865,914
last_payout2018-04-30 21:31:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length92
author_reputation522,128,954,779
root_title"PHP Steem Apps with Steem Connect and Laravel - Part I: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)