Symfony

How To Install and Get Started with Symfony on Ubuntu 24.04 or Newer

Welcome to the Greenhost.cloud blog! Today, we’re diving into the world of Symfony, one of the most powerful PHP frameworks available. Whether you’re a seasoned developer or a newbie, Symfony offers a robust platform for building web applications. In this post, we will guide you through the installation process on Ubuntu 24.04 (and newer) and provide tips on getting started with your first Symfony project.

Why Choose Symfony?

Before we jump into the installation, let’s briefly discuss why Symfony is a popular choice among developers:

  • Modular and Flexible: Symfony allows you to use only the components you need, making it a highly customizable framework.
  • Strong Community Support: With an active community, Symfony provides extensive documentation, forums, and third-party bundles to extend functionality.
  • Best Practices: Symfony follows best practices that help you write clean, maintainable code.

Prerequisites

Before installing Symfony, ensure you have the following prerequisites:

  • Ubuntu 24.04 or newer: The latest version of Ubuntu for optimal performance and security.
  • PHP: Symfony requires PHP 8.1 or higher. Check your PHP version with the command:
  php -v
  • Composer: A dependency manager for PHP. You can install Composer globally on your system.

Step 1: Installing PHP and Required Extensions

Let’s start by installing PHP and the necessary extensions. Open your terminal and run:

sudo apt update
sudo apt install php php-cli php-xml php-mbstring php-curl php-zip php-mysql

Step 2: Installing Composer

To install Composer, run the following commands:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'd4a...') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
sudo mv composer.phar /usr/local/bin/composer

Verify the installation by checking the Composer version:

composer --version

Step 3: Installing Symfony CLI

The Symfony CLI tool makes it easy to create and manage Symfony applications. Install it with the following command:

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

Then, move the Symfony binary to a directory in your $PATH:

sudo mv ~/.symfony*/bin/symfony /usr/local/bin/symfony

You can verify the installation with:

symfony -v

Step 4: Creating a New Symfony Project

Now that you have Symfony installed, let’s create a new project. You can do this using the Symfony CLI:

symfony new my_project_name --full

Replace my_project_name with your desired project name. The --full option installs the full Symfony application, including all the components.

Step 5: Running Your Symfony Application

Navigate to your project directory:

cd my_project_name

Start the local web server with the following command:

symfony server:start

You should see output indicating that the server is running. Open your web browser and navigate to http://localhost:8000 to see your new Symfony application in action!

Step 6: Explore and Develop

Now that you have your Symfony application up and running, it’s time to explore the framework. Here are some resources to help you get started:

  • Documentation: The official Symfony documentation is comprehensive and a great place to start.
  • Symfony Flex: Learn about Symfony Flex, which helps manage your Symfony project dependencies.
  • Bundles: Explore Symfony bundles to add functionality to your application.

Conclusion

Congratulations! You’ve successfully installed Symfony on Ubuntu 24.04 and set up your first project. The journey of developing powerful web applications awaits you, and with Symfony, the possibilities are endless.

Stay tuned for more tutorials and tips from Greenhost.cloud, and happy coding!