Tutorial-9122023

How to Install Symfony PHP Framework on Ubuntu 22.04

p1 1

How to Install Symfony PHP Framework on Ubuntu 22.04

Symfony is one of the most popular PHP frameworks used for web applications. It is known for its independent components, which can be easily integrated into any other PHP project. Symfony is released as open-source software and is suitable to build PHP applications of any size.

This tutorial will show you how to install the Symfony PHP framework on Ubuntu 22.04.

Prerequisites

  • A server running Ubuntu 22.04.
  • A valid domain name is pointed to your server IP.
  • A root password is configured on the server.

Install PHP

Symfony is a PHP framework so PHP must be installed on your server. If not installed, you can install it with other dependencies using the following command.

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

Once PHP and other PHP components are installed, you can proceed to the next step.

Install Symfony on Ubuntu 22.04

The simplest and easiest way to install Symfony is from an automatic installation script.

You can download and run the Symfony installation script using the following command.
wget https://get.symfony.com/cli/installer -O - | bash

Once Symfony is installed, you will get the following output.
2022-12-21 10:59:24 (11.6 MB/s) - written to stdout [6100/6100]

Symfony CLI installer

Environment check
[*] cURL is installed
[*] Tar is installed
[*] Git is installed
[*] Your architecture (amd64) is supported

Download
Downloading https://github.com/symfony-cli/symfony-cli/releases/latest/download/symfony-cli_linux_amd64.tar.gz...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 5232k 100 5232k 0 0 2309k 0 0:00:02 0:00:02 --:--:-- 7400k
Uncompress binary...
Installing the binary into your home directory...
The binary was saved to: /root/.symfony5/bin/symfony

The Symfony CLI was installed successfully!

Use it as a local file:
/root/.symfony5/bin/symfony

Or add the following line to your shell configuration file:
export PATH="$HOME/.symfony5/bin:$PATH"

Or install it globally on your system:
mv /root/.symfony5/bin/symfony /usr/local/bin/symfony

Then start a new shell and run 'symfony'

Next, you will need to define the Symfony system path on your system. You can do it with the following command:
export PATH="$HOME/.symfony5/bin:$PATH"
source ~/.bashrc

Create a Symfony Project

At this point, Symfony is installed on your server. Now, you will need to create a new Symfony project to use it.
symfony new project --full

You will get the following output.
* Setting up the project under Git version control
(running git init /root/project)

[OK] Your project is now ready in /root/project

Next, navigate to your project and run the web server using the following command.
cd project
symfony server:start

You should get the following output.

[OK] Web server listening
The Web server is using PHP CLI 8.1.2
http://127.0.0.1:8000

[Web Server ] Dec 21 11:01:36 |DEBUG | PHP Reloading PHP versions
[Web Server ] Dec 21 11:01:36 |DEBUG | PHP Using PHP version 8.1.2 (from default version in $PATH)
[Application] Dec 21 11:01:15 |INFO | DEPREC User Deprecated: The "MonologLogger" class is considered final. It may change without further notice as of its next major version. You should not extend it from "SymfonyBridgeMonologLogger".
[Web Server ] Dec 21 11:01:36 |INFO | PHP listening path="/usr/bin/php8.1" php="8.1.2" port=44005
[PHP ] [Wed Dec 21 11:01:36 2022] PHP 8.1.2-1ubuntu2.9 Development Server (http://127.0.0.1:44005) started

Access Symfony

At this point, the Symfony server is started and listens on port 8000. You can now access it using the URL http://your-server-ip:8000. You should see the Symfony default page on the following screen.

PHP Symfony framework

Conclusion

Congratulations! you have successfully installed the Symfony PHP framework on Ubuntu 22.04. You can now start building a PHP-based web application using the Symfony framework. Feel free to ask me if you have any questions.

Đăng ký liền tay Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !

Add Comment

Click here to post a comment

Đăng ký liền tay
Nhận Ngay Bài Mới

Subscribe ngay

Cám ơn bạn đã đăng ký !

Lỗi đăng ký !