Installing Symphony to php project

PHP DOCUMENTATION:

Installing Symphony:

USING THIS GUIDE

to be able to use it you must place it where you have installed your PHP locally or use XAMP installation folder. If you choose to use manually installed PHP it means you have to edit the php.ini-develop file n make a copy then remove"-development" in the file name.

  • The installer will make recommendations on which items to turn on in the ini file, to do that just remove the ";" before those items.

  • So before you can install Symfony you must run the command to allow scoop to do its thing:

RUN THESE COMMANDS ON THE POWERSHELL:

 Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
 # The above one is optional, needed to run a remote script the first time
 irm get.scoop.sh | iex
  • After that run scoop -help to check if scoop is installed.
   scoop install main/symfony-cli
  • when its done installing it will tell you "symfony-cli' (5.7.5) was installed successfully!".

  • use symfony new --webapp my_project to create a application

  • use symfony new my_project to create console, API or microservice.

follow :

  • Steps to create symfony project

  • To create a skeleton project we in windows we run

composer create-project symfony/website-skeleton my-project
  • in mac i think we dont need the "composer" before "create...".

  • cd into the project cd projectName.

  • run symfony server:start -d to start the project.

Adding DB to Project:

  • DB INTEGRATION GUIDE

  • I tried using the integrated terminal in VS Code but it did not work so this time around I am using cmd from File Explore.

  • Ran the command ```composer require doctrine``

  • Realized I was having error with which php version the project wanted so i moved the project outside of the htdocs in XAMP folder to another folder and the command worked.

  • To create a docker file for mysql on docker i used ./bin/console make:docker:database

  • After trying different commands from the docs ```docker-compose exec database mysql -u root --password main`` actually works where, user is root and databases is main.

  • After the terminal shows that I am in mysql I ran show databases; to test.

  • When creating entities Doctren wants us to work with objects and properties not db models 'still need some clarity on this' & it uses the ORM to map the data to DB.

  • To create db models i used php ./bin/console make:entity.

  • Console was supposed to generate the entity with the repository in the project src folder but it only made the entity so I will try again n it should work this time.

  • At this point we have entities but no database to write to, create an entity i had to first install the doctrine migrations bundle Following composer require "doctrine/migrations"

  • and also run the command to add symfony config in yaml -> composer require symfony/yaml

  • Then I had to go to the Configuration Page and add the config...yaml file.

  • After adding the migration config i changed the migration path to the projects one.

  • Also on the same page you follow along on creating and populating the migrations-db.php

  • The command php ./vendor/bin/doctrine-migrations migrate was failing and throwing a 'driver not found error', so I went to enable mysql on the Program Files -> php.ini & the error changed to "An exception occurred in the driver: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it".

  • After many attempts the main thing that helped was installing mysql on the machine and not using the one that is on docker because that connection was failing.

  • So whats clear is docs commands starting with doctrine fail with some error based on how the project was generated but those starting with php ./vendor... eg php ./vendor/bin/doctrine-migrations status will work. size - 9w by 16 h

Did you find this article valuable?

Support Nqubeko Gcabashe by becoming a sponsor. Any amount is appreciated!