Skip to content

Commit 1d3c2d0

Browse files
committed
Update README.md
Documented the Codespace launch process and generally improved the documentation.
1 parent f066bca commit 1d3c2d0

File tree

1 file changed

+72
-29
lines changed

1 file changed

+72
-29
lines changed

README.md

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# How To Build a Laravel + MongoDB Back End Service
22

3-
This code was writting in conjunction with [this article](https://www.mongodb.com/developer/languages/php/laravel-mongodb-tutorial/?utm_campaign=devrel).
3+
This code was writting to accompany [this article](https://www.mongodb.com/developer/languages/php/laravel-mongodb-tutorial/?utm_campaign=devrel).
44

55

66
## Prerequisites
@@ -13,47 +13,85 @@ You'll need the following installed on your computer to follow along with this t
1313

1414
The article mentions several ways to get a Laravel development environment up and running.
1515

16-
# Preparing the Laravel project to run
16+
# 🚀 Launch this repo in CodeSpaces
1717

18-
Before the project can run properly, we need to take several actions.
18+
<img src="https://i.imgur.com/5STvIPX.png">
1919

20-
## 1. Install dependencies
20+
⏳Codespaces will build the app's container(s). This may take **~3 minutes**.
2121

22-
In the Laravel project folder, install the Composer dependencies with the command
22+
<img src="https://i.imgur.com/1IBKVjx.png">
2323

24-
`composer install`
24+
✅Done! We now have our project running inside CodeSpaces. We can proceed to setting up Laravel
2525

26-
## 2. Create the .env file
26+
<img src="https://i.imgur.com/9b6P1ba.png">
2727

28-
Laravel uses the .env file for environment-specific configurations, like database credentials, application key, and other settings. Create one from the included example file:
28+
<p></p><p></p>
2929

30-
`cp .env.example .env`
30+
# 👋 Before you run this Laravel app
3131

32-
## 3. Generate a Laravel Application key
32+
## 1. Laravel setup
3333

34-
Laravel might ask to generate a new application key. You can do it by running this command in the laravel project folder.
34+
After cloning the code repo or launching a Docker/CodeSpaces instance, the project needs a few more things before the Laravel App can run:
3535

36-
`php artisan key:generate`
36+
1. install dependencies via Composer
37+
2. create a new .env file
38+
3. generate a new Laravel App Key
3739

38-
## 4. Add the MongoDB connection string to .env
40+
You can conveniently do all three by running the `init_repo.sh` from the
41+
PHP container.
3942

40-
We need to add the MongoDB connection string with the username / password to the .env file. add this line, but remember that your connection string might look different.
43+
<img src="https://i.imgur.com/P0ZNlot.png">
4144

42-
`DB_URI=mongodb+srv://USERNAME:PASSWORD@clustername.subdomain.mongodb.net/?retryWrites=true&w=majority`
45+
The script will install the package via Composer, create an .env and create an App key.
46+
47+
<img src="https://i.imgur.com/6P6MlFX.png">
4348

44-
## 5. Ready!
49+
## 2. Ready!
4550

4651
Head to the site URL and you should see the Laravel Homepage
4752

48-
# Xdebug
53+
<img src="https://i.imgur.com/pkORDBj.png">
54+
55+
<p></p>
56+
57+
<img src="https://i.imgur.com/fbZlygD.png">
58+
59+
Our base Laravel app is ready 🥳.
60+
61+
❗Note that this branch already has the Model and Migrations already setup.
62+
63+
64+
**Next**, you can connect to a MongoDB Cluster and try some of the things we talked about in our [How To Build a Laravel + MongoDB Back End Service](https://www.mongodb.com/developer/languages/php/laravel-mongodb-tutorial/)
65+
66+
Add the MongoDB connection string with the username / password to the .env file. add this line, but remember that your connection string might look different.
67+
68+
In .env, add
69+
70+
`DB_URI=mongodb+srv://USERNAME:PASSWORD@clustername.subdomain.mongodb.net/?retryWrites=true&w=majority`
71+
72+
# 🚀 Launch locally with Docker
73+
74+
Assuming that you already have Docker Desktop installed on Windows/Mac or Docker on Linux,
75+
76+
- clone the repository to a local directory
77+
- navigate to the ./devcontainer folder
78+
- execute `docker compose up`
79+
- in the PHP container, execute the init_repo.sh script
80+
81+
Once the containe(s) are up, visit http://localhost
82+
83+
84+
# Optional: Xdebug
4985

5086
The xdebug.php-debug VS Code extension is automatically installed if you launch via devcontainer.json.
5187

52-
If you are using our container directly (docker compose up), or via VS Code (devcontainer), we suggest the following Xdebug configs visual studio
88+
👀 **Important**: our `.devcontainer/.docker/php/xdebug.ini` file is setup by default with `xdebug.client_host=localhost`, which should works for **CodeSpaces** and Devcontainers.
5389

54-
### localhost
90+
For **local development**, you need to replace `localhost` with the IP where your code IDE runs or a dns name that maps to it. That's because your PHP container and the IDE host tend to have different IPs.
5591

56-
The debug config file is located in `<repository_dir>/.vscode/launch.json`
92+
If you are using our container directly (docker compose up), or via VS Code (devcontainer), we suggest the following Xdebug configs visual studio. Note the difference in path mapping.
93+
94+
## CodeSpaces and (inside a Devcontainer)
5795

5896
```json
5997
{
@@ -62,21 +100,26 @@ The debug config file is located in `<repository_dir>/.vscode/launch.json`
62100
"request": "launch",
63101
"port": 9003,
64102
"pathMappings": {
65-
// ${workspaceFolder} == directory where /.vscode/ is
66-
// the syntax is SERVER_PATH : LOCAL_PATH
67-
"/var/www/htdoc": "${workspaceFolder}/src"
103+
"/var/www/htdoc": "${workspaceFolder}"
68104
}
69105
},
70106
```
71107

72-
### devcontainer
73-
74-
- TODO
75-
76-
### Codespaces
108+
## local development with Docker
77109

78-
- TODO
110+
The debug config file is located in `<repository_dir>/.vscode/launch.json`
79111

112+
```json
113+
{
114+
"name": "Listen for Xdebug",
115+
"type": "php",
116+
"request": "launch",
117+
"port": 9003,
118+
"pathMappings": {
119+
"/var/www/htdoc": "${workspaceFolder}/src"
120+
}
121+
},
122+
```
80123

81124
# Disclaimer
82125

0 commit comments

Comments
 (0)