Create and Setup Symfony Project

  448 views   9 months ago Symfony

Symfony is fast and leading PHP framework built on top of the Symfony Components. Drupal, phpBB, and eZ Publish frameworks also built on Symfony Components.

In this article, we will go through how to create new Symfony framework using composer command. We will also setup Symfony application and connect with MySQL database.

Requirement

Before creating your first Symfony application you must have installed:

1. PHP 7.2.5 or higher version with extensions.
2. Composer, which is used to install PHP packages.

Create Symfony application

Run the below composer command to create new symfony application.

composer create-project symfony/website-skeleton my_project

Now go to the project folder

cd my_project/

If you need to know more details about Symfony project, use the below command. 

php bin/console about

Setting environment

In the root path, copy .env.test file to .env and add the below database details in it.

DATABASE_URL="mysql://root:[email protected]:3306/persons"

You will also need to configure Symfony with apache web server. For the live server, you will need fully-featured web server. Run the below command to install apache symfony pack.

composer require symfony/apache-pack

This will add .htaccess file in public folder. You should define all apache rules in that file.

To run Symfony commands, you can do anything from the below.

Use it as a local file:

/home/jitesh/.symfony/bin/symfony

Or add the following line to your shell configuration file:

export PATH="$HOME/.symfony/bin:$PATH"

Or install it globally on your system:

mv /home/jitesh/.symfony/bin/symfony /usr/local/bin/symfony

Run the below command to start symfony server

symfony server:start

And open web browser and open http://localhost:8000/. You will see welcome page.

I hope it will help you.

Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]