TNS
VOXPOP
What news from AWS re:Invent last week will have the most impact on you?
Amazon Q, an AI chatbot for explaining how AWS works.
0%
Super-fast S3 Express storage.
0%
New Graviton 4 processor instances.
0%
Emily Freeman leaving AWS.
0%
I don't use AWS, so none of this will affect me.
0%
Operations

Install the Symfony PHP Framework on Ubuntu Server 22.04

Symfony is a very popular framework for the PHP language that is used to simplify the web design process, purpose-built to make building web applications as simple as possible.
Oct 14th, 2023 5:00am by
Featued image for: Install the Symfony PHP Framework on Ubuntu Server 22.04
Feature image by Anja from Pixabay.

If you’re a PHP developer, you might have heard about Symfony. If not, let me tell you a little bit about this piece of software.

Symfony is a very popular framework for the PHP language that is used to simplify the web design process. This backend framework was purpose-built to make building web applications as simple as possible. With Symfony, you can also work with other languages, such as JavaScript and Node.js.

With Symfony, you can build scalable, complicated web applications. One example of a great app built with Symfony is Spotify.

The features found in Symfony include:

  • Model-View-Controller-based system.
  • High-performance.
  • Flexible URI routing.
  • Reusable code.
  • Session management.
  • Error logging.
  • Full-featured database classes.
  • Open source.

Symfony also enjoys a very active community, so you can be sure it’ll be around for a long, long time.

With all of that said, how do you install Symfony on Ubuntu Server 22.04 and start your first project? Let me show you how this is done.

What You’ll Need

To get Symfony up and running, you’ll need two things: A running instance of Ubuntu Server 22.04 and a user with sudo privileges. That’s it.

Let’s get to work.

Installing Required Dependencies

The first thing we must do is install the required dependencies. Log into your Ubuntu Server instance and open a terminal window (if you have a desktop environment installed). At the bash prompt, run the following command to take care of the dependencies:

sudo apt-get install php php-json php-ctype php-curl php-mbstring php-xml php-zip php-tokenizer php-tokenizer libpcre3 git zip unzip git -y

When that completes, you’re ready to install Symfony.

Installing Symfony

At the bash prompt, issue the following command:

wget https://get.symfony.com/cli/installer -O – | bash

The installation should be completed quickly and without issue. Once it finishes, define the Symfony path on your system with the following two commands:


At this point, Symfony is installed and ready to go.

Creating your first Symfony Project

The first thing you must do is make sure Symfony knows who you are. We can do this with the help of a couple of git commands, which are:


Where email address is your email address and full name is your full name.

Next, let’s create a new directory to house our project. Let’s name our project test and create the directory with the command:


Change into that folder and start the project with the command:


The output of the command should look something like this:

Creating a new Symfony project with Composer
WARNING: Unable to find Composer, downloading one. It is recommended to install Composer yourself at https://getcomposer.org/download/
(running /home/jack/.symfony5/composer/composer.phar create-project symfony/skeleton /home/jack/test/project  –no-interaction)

* Setting up the project under Git version control
(running git init /home/jack/test/project)

WARNING: Unable to find Composer, downloading one. It is recommended to install Composer yourself at https://getcomposer.org/download/
(running /home/jack/.symfony5/composer/composer.phar require webapp –no-interaction)
[OK] Your project is now ready in /home/jack/test/project

With the project created, you can then begin developing your project within the test directory. Once you’ve done some basic development, change into the newly-created project directory (found within test) with the command:


You can then start the server with the command (run from within the ~/test/project directory):


Open a web browser on a machine that’s connected to the same LAN and point it to http://SERVER:8000 (Where SERVER is the IP address of the hosting server). You should be greeted with either the Symfony Welcome page (Figure 1), or whatever page you created within the project directory.

Figure 1: Symfony has been successfully installed and the project is up and running.

Stop the server with the Ctrl-X key combination.

Adding Composer into the Mix

Let’s add Composer to Symfony with the command:


Now, run the command (from within your project directory):


Next, create your first controller with:


You should now see a new folder in src/ called Controller. In that folder, you’ll find a file TestController.php. You can then restart the server with:


If you then point your browser to http://SERVER:8000/home (Where SERVER is the IP address of the hosting server), you see the HomeController you just created (Figure 2).

Figure 2: Our HomeController is up and running.

That page indicates where your controller and template reside. Symfony uses Twig as the default templating engine, so you’ll have to have a basic understanding of how that works before you can begin building your projects.

Congratulations, you now have Symfony installed and can start a new project. Once you have a solid grasp of PHP and Twig, you can start building your web apps with an efficiency you might not have otherwise experienced.

Group Created with Sketch.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.