|
| 1 | +# Setup Guide for PHP 8.4 + Symfony 7.3 + SQLite on WSL2 |
| 2 | + |
| 3 | +This guide covers setting up PHP 8.4, Symfony 7.3, SQLite on WSL2 (Ubuntu), |
| 4 | +managing the project with GitHub, and running tests with GitHub Actions. |
| 5 | + |
| 6 | +## Environment |
| 7 | + |
| 8 | +- Windows 11 + WSL2 (Ubuntu) |
| 9 | +- PHP 8.4 |
| 10 | +- Symfony 7.3 |
| 11 | +- SQLite |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## 1. Install PHP 8.4 |
| 16 | + |
| 17 | +```bash |
| 18 | +sudo add-apt-repository ppa:ondrej/php |
| 19 | +sudo apt update |
| 20 | +sudo apt install php8.4-cli php8.4-sqlite3 php8.4-curl php8.4-xml php8.4-mbstring php8.4-zip php8.4-intl php8.4-opcache |
| 21 | +``` |
| 22 | + |
| 23 | +Verify PHP installation: |
| 24 | + |
| 25 | +```bash |
| 26 | +php -v |
| 27 | +``` |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## 2. Install Composer |
| 32 | + |
| 33 | +```bash |
| 34 | +curl -sS https://getcomposer.org/installer | php |
| 35 | +sudo mv composer.phar /usr/local/bin/composer |
| 36 | +``` |
| 37 | + |
| 38 | +Verify Composer installation: |
| 39 | + |
| 40 | +```bash |
| 41 | +composer --version |
| 42 | +``` |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## 3. Install Symfony CLI |
| 47 | + |
| 48 | +```bash |
| 49 | +curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | sudo -E bash |
| 50 | +sudo apt install symfony-cli |
| 51 | +``` |
| 52 | + |
| 53 | +Verify Symfony CLI installation: |
| 54 | + |
| 55 | +```bash |
| 56 | +symfony -v |
| 57 | +``` |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## 4. Create Symfony Project |
| 62 | + |
| 63 | +```bash |
| 64 | +symfony new my_project --version="7.3.*" --webapp |
| 65 | +cd my_project |
| 66 | +``` |
| 67 | + |
| 68 | +--- |
| 69 | + |
| 70 | +## 5. Configure SQLite |
| 71 | + |
| 72 | +Edit `.env`: |
| 73 | + |
| 74 | +```env |
| 75 | +DATABASE_URL="sqlite:///%kernel.project_dir%/var/data_%kernel.environment%.db" |
| 76 | +# DATABASE_URL="postgresql://app:!ChangeMe!@127.0.0.1:5432/app?serverVersion=16&charset=utf8" |
| 77 | +``` |
| 78 | + |
| 79 | +Create the database: |
| 80 | + |
| 81 | +```bash |
| 82 | +php bin/console doctrine:database:create |
| 83 | +``` |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## 6. Run the Server |
| 88 | + |
| 89 | +```bash |
| 90 | +symfony server:start |
| 91 | +``` |
| 92 | + |
| 93 | +Open `http://localhost:8000` in your browser to verify. |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## 7. Set up GitHub Repository |
| 98 | + |
| 99 | +Edit `.env.dev` to set a non-sensitive `APP_SECRET`: |
| 100 | + |
| 101 | +```env |
| 102 | +APP_SECRET="THIS_IS_FOR_DEV_SO_NOT_REALLY_SECRET" |
| 103 | +``` |
| 104 | + |
| 105 | +Create a repository on GitHub and push your project: |
| 106 | + |
| 107 | +```bash |
| 108 | +git init |
| 109 | +git branch -M main |
| 110 | +git add . |
| 111 | +git commit -m "Initial commit" |
| 112 | +git remote add origin git@github.com:<username>/<repo-name>.git |
| 113 | +git push -u origin main |
| 114 | +``` |
| 115 | + |
| 116 | +--- |
| 117 | + |
| 118 | +## 8. Configure GitHub Actions for Testing |
| 119 | + |
| 120 | +Install PHP-CS-Fixer: |
| 121 | + |
| 122 | +```bash |
| 123 | +composer require --dev friendsofphp/php-cs-fixer |
| 124 | +``` |
| 125 | + |
| 126 | +Create `.github/workflows/ci.yml` in your project root: |
| 127 | + |
| 128 | +```yaml |
| 129 | +name: CI |
| 130 | + |
| 131 | +on: [push, pull_request] |
| 132 | + |
| 133 | +jobs: |
| 134 | + symfony-tests: |
| 135 | + runs-on: ubuntu-latest |
| 136 | + |
| 137 | + steps: |
| 138 | + - uses: actions/checkout@v4 |
| 139 | + |
| 140 | + - name: Set up PHP 8.4 |
| 141 | + uses: shivammathur/setup-php@v2 |
| 142 | + with: |
| 143 | + php-version: "8.4" |
| 144 | + extensions: sqlite, intl, mbstring, xml, zip |
| 145 | + coverage: none |
| 146 | + |
| 147 | + - name: Install dependencies |
| 148 | + run: composer install --prefer-dist --no-progress |
| 149 | + |
| 150 | + - name: Check coding standards (optional) |
| 151 | + run: PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --diff |
| 152 | + |
| 153 | + - name: Run tests (PHPUnit) |
| 154 | + run: vendor/bin/phpunit |
| 155 | +``` |
| 156 | +
|
| 157 | +Currently, PHP-CS-Fixer does not officially support PHP 8.4, thus |
| 158 | +`PHP_CS_FIXER_IGNORE_ENV=1` is set to bypass version checks temporarily. |
| 159 | + |
| 160 | +Commit and push your changes to trigger tests via GitHub Actions. |
| 161 | + |
| 162 | +--- |
| 163 | + |
| 164 | +## 9. Run PHPUnit Tests |
| 165 | + |
| 166 | +Symfony 7.3 includes PHPUnit 12 by default: |
| 167 | + |
| 168 | +```bash |
| 169 | +php bin/phpunit |
| 170 | +``` |
| 171 | + |
| 172 | +Ensure all tests pass successfully. |
| 173 | + |
| 174 | +--- |
| 175 | + |
| 176 | +Your Symfony setup on WSL2 is now complete, including GitHub management and |
| 177 | +automated testing with GitHub Actions. |
0 commit comments