Symfony : Code style + Virtual Host + Git

what you have to know and do before starting a Symfony project

In this tutorial , we suppose to create an application for a shop of toys.

The Tutorial contains 3 parts :

  1. Symfony Code Style
  2. Virtual Host
  3. Git

1. Code Style

Symfony coding style standards are based on the standard PSR-02 .

2. Virtual Host

You don’t have to start the server every time . You can create a virtual host on your system and navigate to a domain you choose.

  • First , install the package “apache-pack”
$ composer require symfony/apache-pack
  • hosts ( /etc) :
127.0.0.1 www.toys-shop.com
  • toys-shop.com.conf ( /etc/apache2/sites-available)
<VirtualHost *:80>
ServerName toys-shop.com
ServerAlias www.toys-shop.com

DocumentRoot /var/www/toys-shop/public
<Directory /var/www/toys-shop/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>

ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
  • 000-default.conf ( /etc/apache2/sites-available)

change the port number of apache ( 8081 as an example )

  • ports.conf (/etc/apache2)

Add :

Listen 8081
  • Activate the virtualHost
$ sudo a2ensite toys-shop.com.conf
$ sudo a2dissite 000-default.conf
$ sudo systemctl restart apache2
  • User permissions ( chown + chmod )
$ sudo chown -R $USER:$USER /var/www/toys-shop/public
$ sudo chmod -R 777 /var/www/toys-shop/public

3. Git

$ git config user.name= "you git username"
$ git config user.email= "username@exemple.com"

Create a project on your git account ( gitlab or github )

Clone the repository

$ git clone ssh://git.url.of.your.project

Copy the content of the project in the new repository

$ git add .
$ git commit -m "first commit"
$ git push

If you are working in teams and each one should work on a separate branch , use the following command line :

$ git checkout -b <your_branch_name>
$ git add -A
$ git commit -m " a message indicates changes you have made"
$ git push origin <your_branch_name>

I am Mouna , developer from Tunisia .
 If you curious to learn more , explore the following links :