Skip to content

Development environment on Windows

Sylvain Martin edited this page Dec 28, 2022 · 6 revisions

Setting up a development environment on Windows

XAMP (Apache, PHP and MariaDB)

Download XAMMP on the official website, The software still use PHP7, so one should download the las version of PHP7 (in February 2022, it is 7.4.27). Install it in C:\XAMPP. It can also be usfull to put C:\xampp\php in the windows PATH

git

git can be download on its official web site. Then the installation is trivial, just following all the steps of the installer is enough, the only thing one has to be careful is that the git executable must be in windows PATH because it is needed later (a reboot might be necessary).

Code source download

Chose a place where the code source will be download, there are no particular constrains. Here, for the example C:\path\to\the\project\folder has been chosen, but obviously one should change it to fit his file organization.

cd "C:\path\to\the\project\folder"
git clone https://github.com/elefan-grenoble/gestion-compte.git gestion-compte

Composer

Then one need composer, The last version of composer seem not working with Symfony 3.4. one way to install the wanted version is to download the script directly from the web site. one can use php composer.phar self-update 2.2.17 to change the composer version. A more practical way is to use composer locally, only for this project (an not system wise). This avoid having an old version on the system. For that the *.phar application package can be download at the project root, an instead of using the composer command, one use php composer.phar:

cd "C:\path\to\the\project\folder\gestion-compte"

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

# download and install the 2.2.17 version
php composer-setup.php --version=2.2.17

Then one can use composer to install all the package needed by the web application. If no app/config/parameters.yaml exist it will ask you some parameters. It can be simple to let all the default values and then editing the parameters.yaml file after.

php composer.phar install --no-dev

parameters.yaml

Assetic

Assetic is an asset management framework for PHP. it is to manage static assets (like js, and css files). to 'dump' them (meaning to install them at the right place). one should execute the following command to install new assets from the bundles web assets (under a public directory ``src/AppBundle/Resources/public

php bin/console assets:install                           

MailHog

MailHogis an email testing tool that makes it easy to install and configure a local email server. MailHog sets up a fake SMTP server. It can be download on its GitHub webpage. Just download the last version for Windows and copy it in C:/xampp/sendmail/ and for connivance rename it as mailhog.exe.

MailHog interface. From the MailHog GitHub webpage

hosts file

C:\Windows\System32\drivers\etc To be able to type an address in your browser, the hosts file need to be edited to reroute the wanted address to localhost. To edit this file administration privilege need to be use. The the fist step is to start notepad as administrator and to edit the hosts (without any extension) file in C:\Windows\System32\drivers\etc . To open the hosts file in Notepad, click "File", "Open", and navigate to C:\Windows\System32\drivers\etc.

You won't be able to see any files in this directory because they aren't text documents. To change the file type, click on the dropdown in the bottom right of the Open menu and click on "All Files". You'll see a file named hosts. Double click on that file to open it and add the following lines:

127.0.0.1 localhost
127.0.0.1 membres.yourcoop.local
127.0.0.1 mailhog

The fist line is to assure localhost route is manage by you computer, the second is for the website (.local is a reserved address for this purpose) and the last one is optional and only needed for mailhog a tool that catch mail to try email related features.

Apache configuration

One can use the server shipped with symfony, but some incompatibilities and differences can be found with a production server1. To have a better compatibility with the production environment, one can use the Apache server include in XAMPP. For that a virtual host needs to be configured:

In the configuration file C:\xampp\apache\conf\httpd.conf another port has to be added:

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.

Listen 80
Listen 8000

and in the virtual host configuration file C:\xampp\apache\conf\extra\httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot C:/Users/smartin/Documents/Personnel/elefan/gestion-compte/web
    ServerName membres.yourcoop.local:8000
	DirectoryIndex /app_dev.php
	SetEnv APPLICATION_ENV "dev"
	
	<Directory "C:/Users/smartin/Documents/Personnel/elefan/gestion-compte/web">
        DirectoryIndex app_dev.php
        Require all granted 
	FallbackResource /app_dev.php
    </Directory>
	
</VirtualHost>

Then to start just click on the start button next to Apache in XAMP main window.

PHP configuration file

to be able to use MailHog, the file php.ini found in C:\xampp\php file needs to be changed to reroute the mails.

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=0.0.0.0
; http://php.net/smtp-port
smtp_port=1025

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = "C:/xampp/sendmail/mailhog.exe sendmail"

; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header=On

In addition, to be compatible with UTF8, on has to change the following configuration too:

; PHP's default character set is set to UTF-8.
; http://php.net/default-charset
default_charset="UTF-8"

; PHP internal character encoding is set to empty.
; If empty, default_charset is used.
; http://php.net/internal-encoding
internal_encoding="UTF-8"

; PHP input character encoding is set to empty.
; If empty, default_charset is used.
; http://php.net/input-encoding
input_encoding ="UTF-8"

; PHP output character encoding is set to empty.
; If empty, default_charset is used.
; See also output_buffer.
; http://php.net/output-encoding
output_encoding="UTF-8"

MySQL/MariaDB first start

Start MySQL (1) and open the Shell (2) in XAMMP

XAMP_MySQL_first_start

Then create the database (secret the password):

mysql -uroot -psecret -e "DROP DATABASE IF EXISTS symfony;"
mysql -uroot -psecret -e "CREATE DATABASE IF NOT EXISTS symfony;"
mysql -uroot -psecret --default-character-set=utf8mb4 symfony < backup.sql

you may want to add a command at the top of your database dump to avoid cast issues with UT8:

SET NAMES utf8mb4;

1: Footnote content goes here e.g. how the UTF-8 is internally managed, that can cause some inconsistency between the BDD schemes and Doctrine