Nuxtstop

For all things nuxt.js

Starting a new Symfony project on Linux

5 0

Symfony is the fastest major PHP framework with the philosophy to start small and add features when you need them.

So today I'll show you what is needed at minimal to easily serve your new Symfony project. Bonus are some packages which can be installed and I think are useful to start with for developing.

Minimal requirements

Before we start we need 4 things to install:

  • PHP
  • Composer
  • GIT
  • Symfony

Install PHP

In order to use a PHP framework, you need PHP installed. Symfony says it requires PHP 8.0.2 today and the needed PHP extensions are installed and enabled by default in most PHP 8 installations.

In this case however I install PHP 7.4 and specify each and every extension I want to enable by the following commands:

sudo apt install software-properties-common

sudo add-apt-repository ppa:ondrej/php -y

sudo apt update

sudo apt install php7.4 php7.4-fpm php7.4-common php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-curl php7.4-gd php7.4-imagick php7.4-cli php7.4-dev php7.4-imap php7.4-mbstring php7.4-opcache php7.4-soap php7.4-zip php7.4-intl php7.4-bcmath unzip -y
Enter fullscreen mode Exit fullscreen mode

Install Composer

Composer is an application-level package manager that provides a standard format for managing dependencies of PHP software. Simply said, Composer is used to install PHP packages.

To install composer, run this command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Enter fullscreen mode Exit fullscreen mode

You can keep Composer locally (meaning, in the folder where you run this command) or move it globally so you don't have to install it again for your next project. Therefor run the command:

sudo mv composer.phar /usr/local/bin/composer
Enter fullscreen mode Exit fullscreen mode

For more info go to https://getcomposer.org/download/

Install GIT

If you don't know it yet: Git is software for tracking changes in any set of files, it is a very handy tool to keep track of your progression.

Install GIT by this command:

sudo apt-get install git
Enter fullscreen mode Exit fullscreen mode

Now login with your Github account:

git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Enter fullscreen mode Exit fullscreen mode

Not an account yet? Register on Github.com

Install Symfony

There are 2 ways to install Symfony. First by installing Symfony CLI and second by Composer. Although we already installed Composer, I like to install Symfony CLI because it comes with very handy tools you need to develop and run your Symfony application locally.

Run this installer to create a binary called symfony:

wget https://get.symfony.com/cli/installer -O - | bash
Enter fullscreen mode Exit fullscreen mode

The symfony binary provides a tool to check if we are all set up and your computer meets all requirements:

symfony check:req
Enter fullscreen mode Exit fullscreen mode

If all is good to go, you should receive the message:

[OK]
Your system is ready to run Symfony projects
Enter fullscreen mode Exit fullscreen mode

Create a new Symfony project

Now we meet all requirements we are good to go to create your Symfony project:

symfony new my_new_symfony_project
Enter fullscreen mode Exit fullscreen mode

If succeeded you will receive this kind of message:

The Symfony CLI v4.26.12 was installed successfully!
Enter fullscreen mode Exit fullscreen mode

Let's check it out and hop into your new project:

cd my_new_symfony_project
Enter fullscreen mode Exit fullscreen mode

Serve your new project

In order to serve your project, we will fire it up and let it run in the background:

symfony serve -d
Enter fullscreen mode Exit fullscreen mode

This should give us the local url to your new project:

Local Web Server
    Listening on https://127.0.0.1:8000
Enter fullscreen mode Exit fullscreen mode

To stop:

symfony server:stop
Enter fullscreen mode Exit fullscreen mode

Congrats! This is all to get started with the bare minimal of Symfony!

I re-edited the bonus section to this blog My top 5 favorite symfony packages since it ended up being a longer read then planned.