|
| 1 | +# WE4X-SI40 Project |
| 2 | +Group n°10. |
| 3 | + |
| 4 | +## Getting Started |
| 5 | +The following tutorial applies on Windows 10 or later. |
| 6 | + |
| 7 | +### Requirements |
| 8 | +- WSL 2 |
| 9 | +- Docker Desktop |
| 10 | +- PhpStorm |
| 11 | +- Git |
| 12 | + |
| 13 | +#### Install WSL |
| 14 | +1. Make sure hardware virtualization support is enabled in your BIOS |
| 15 | +2. Run the following command in PowerShell as Administrator `wsl --install` and restart your computer. |
| 16 | +Please make sure the following Windows features are being installed: |
| 17 | + - Virtual Machine Platform |
| 18 | + - Windows Subsystem for Linux (WSL) |
| 19 | +3. Install a Linux distro using the following command `wsl --install [Distro]` where `[Distro]` |
| 20 | +is the name. To view all distributions available for download, enter `wsl --list --online` |
| 21 | +4. Configure the Linux distro you chose by supplying a UNIX login and update the system |
| 22 | + |
| 23 | +#### Install Docker Desktop |
| 24 | +1. Download the Docker Desktop installer either from the official [Docker website](https://www.docker.com/) |
| 25 | +or using winget (Windows Package Manager) in PowerShell `winget install Docker.DockerDesktop`. |
| 26 | +2. On the setup screen, please ensure you select `Use WSL 2` instead of `Hyper-V` |
| 27 | +3. When starting Docker for the first time, accept the subscription service agreement. |
| 28 | +You do not need to create an account, working locally is enough |
| 29 | +4. Finally Docker will initialize. This may take a few minutes on first launch |
| 30 | + |
| 31 | +#### Install PhpStorm |
| 32 | +1. Go on the official [Jetbrains PhpStorm website](https://www.jetbrains.com/fr-fr/phpstorm/) and |
| 33 | +download the installer |
| 34 | +2. Proceed with installing PhpStorm then log into your account to activate your license |
| 35 | + |
| 36 | +#### Install Git |
| 37 | +Trivial |
| 38 | + |
| 39 | +### Project Setup |
| 40 | +1. Clone the repo: `git clone https://github.com/TheRefraction/WE4_Project.git` |
| 41 | +and open it in PhpStorm |
| 42 | +2. Copy the env file example `.env.example` to `.env` and fill in your values. |
| 43 | +This file should **NEVER** be committed to GitHub |
| 44 | +3. Start containers by running the following command from the project folder |
| 45 | +`docker compose up -d`. This may take a while the first time |
| 46 | +4. Open http://localhost:8080 to view the website |
| 47 | + |
| 48 | +### PhpStorm Setup |
| 49 | +#### Set the PHP Interpreter |
| 50 | +1. Go to `Settings > PHP` |
| 51 | +2. Next to `CLI Interpreter`, click `...` |
| 52 | +3. Click `+ > From Docker, ...` |
| 53 | +4. Select `Docker Compose` |
| 54 | +5. Set: |
| 55 | + - Server: Docker |
| 56 | + - Configuration files: `./docker-compose.yml` |
| 57 | + - Service: `php` |
| 58 | +6. Apply and confirm |
| 59 | + |
| 60 | +#### Database Link Configuration |
| 61 | +1. On the right panel, click on the `Database` icon |
| 62 | +2. Click on the `+` icon and select `MySQL` data source |
| 63 | +3. Set host to `localhost`, port to `3306`, and provide login information |
| 64 | +as well as the database name |
| 65 | +4. Install drivers if prompted |
| 66 | +5. Test the connection and save |
| 67 | + |
| 68 | +You may now view the database using the right panel. |
| 69 | + |
| 70 | +## Useful Notes |
| 71 | +If you have configured everything correctly, you should have `Connected to MySQL successfully!` |
| 72 | +appear on the `index.php` page. You may also check with the `info.php` page. |
| 73 | + |
| 74 | +### Modifying the `.env` file |
| 75 | +- You may define a user login and a root password. The latter should not be empty for security |
| 76 | +reasons |
| 77 | +- You may define a database that will be created and populated accordingly. |
| 78 | + |
| 79 | +### Local URLs |
| 80 | +- Open http://localhost:8080 to access the current website. All modifications |
| 81 | +made to the files are reloaded when refreshing the page in your |
| 82 | +Internet browser |
| 83 | +- Open http://localhost:8081 to access PhpMyAdmin. You may access |
| 84 | +the dashboard by providing `root` as a username and the password you |
| 85 | +defined in your `.env` file. |
| 86 | +- Sometimes albeit rare, a computer may fail to resolve `localhost`. Should that happen, |
| 87 | +please replace any occurrence of `localhost` by `127.0.0.1`. |
| 88 | + |
| 89 | +### Database Edition |
| 90 | +The database is automatically loaded by Docker using your `.env` file. |
| 91 | +Although the latter is not accessed remotely, this repo provides 2 files |
| 92 | +under the `db/init` directory. SQL files are put in the lexicographic order, |
| 93 | +because that's the order it's initialized. |
| 94 | + |
| 95 | +If you want to add another database, there should be two files, one for the model |
| 96 | +and another for data to use. Thus, make sure you're using the same |
| 97 | +database name in both files. |
| 98 | + |
| 99 | +#### DB Schema `01_schema.sql` |
| 100 | +This part defines a given database and describes how it is structured. |
| 101 | +This is called the **schema**. |
| 102 | + |
| 103 | +#### DB Seed `02_seed.sql` |
| 104 | +This part adds data to the database defined before. This may be useful |
| 105 | +to share some data with source control. This is called the **seed**. |
| 106 | + |
| 107 | +#### What about the rest? |
| 108 | +All information or data you inject with PhpMyAdmin or with PhpStorm is |
| 109 | +stored locally in the Docker container. It will not be shared across |
| 110 | +other team members. |
| 111 | + |
| 112 | +#### Soft reset |
| 113 | +This will remove all data in the database without destroying its structure. |
| 114 | + |
| 115 | +Via PhpMyAdmin: |
| 116 | +1. Login as `root` user |
| 117 | +2. Select the database from the left panel |
| 118 | +3. Click the SQL tab |
| 119 | +4. Copy-paste the contents of `db/init/02_seed.sql` and run it |
| 120 | + |
| 121 | +Via PhpStorm |
| 122 | +1. Open the Database panel on the right |
| 123 | +2. Connect to the DB if not already done |
| 124 | +3. Right-click the database > New > Query Console |
| 125 | +4. Copy-paste the contents of `db/init/02_seed.sql` and run it |
| 126 | + |
| 127 | +**Important!** If your seed uses `INSERT` without `TRUNCATE` first, you |
| 128 | +may get duplicate data. Please add `TRUNCATE TABLE [NAME];` after `USER [DB];` accordingly, |
| 129 | +where `[NAME]` and `[DB]` are respectively the names of table to truncate, and of |
| 130 | +the database. |
| 131 | + |
| 132 | +#### Hard reset |
| 133 | +This will wipe all data and re-run each `.sql` file under the `db/init` |
| 134 | +directory. |
| 135 | + |
| 136 | +Run the following commands: |
| 137 | +- `docker compose down -v` |
| 138 | +- `docker compose up -d` |
| 139 | + |
| 140 | +### Docker Commands |
| 141 | +Those commands should be ran in the project directory. |
| 142 | + |
| 143 | +- Start and rebuild containers: `docker compose up -d` |
| 144 | +- Stop containers: `docker compose down` |
| 145 | +- Stop containers and wipes all volumes: `docker compose down -v`. |
| 146 | +This command will also destroy all local database data! |
| 147 | +- Get containers info: `docker ps` |
0 commit comments