Context:
I am using a Windows computer but developping on Ubuntu 20.04 thanks to the WSL (Windows Subsystem for Linux).
When I Install php using the apt package system, I get by default the 7.4.1 version, and it is the only version available in the sources (use apt-search to get the available packages).
Getting the right php version for Symfony 6
The latest version of Symfony 6 is the 6.1.4 at the time of this writing (see the Symfony release page for the last version and its php dependency)
requires php >= 8.1
Note that the php 7.4.3 version is OK for the Long Term Release Version (5.4.12) of Symfony.
jpmena@LAPTOP-E2MJK1UO:~/CONSULTANT$ php --version
PHP 7.4.3 (cli) (built: Jun 13 2022 13:43:30) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies
Adding the 8.1 version of php to my Ubuntu
I choose Linuxcapable as the website for the explanations on the migration.
On my Ubuntu I am using Apache as the Web Server, but for developping Symfony I won’t use it. I will use the integrated php server instead!
- First of all ensure that your Linux packages are up to date
- Then add the (one command line is enough for the key and the sources’ list) Ondřej Surý PPA
- Update your package database
- Install php8.1
#before adding the new source update your packages jpmena@LAPTOP-E2MJK1UO:~$ sudo apt update .......................... jpmena@LAPTOP-E2MJK1UO:~$ sudo apt upgrade ................................. # import Ondřej Surý PPA ## software-properties-common is not necessary because most of the time already installed jpmena@LAPTOP-E2MJK1UO:~$ sudo apt install software-properties-common && sudo add-apt-repository ppa:ondrej/php -y ........................................... # here we see that ondrej key has been added jpmena@LAPTOP-E2MJK1UO:~$ ll /etc/apt/sources.list.d/ total 12 drwxr-xr-x 2 root root 4096 Sep 17 16:13 ./ drwxr-xr-x 7 root root 4096 Sep 17 16:13 ../ -rw-r--r-- 1 root root 122 Sep 17 16:13 ondrej-ubuntu-php-focal.list #listing the content of the ppa repository (contains 2 lines) jpmena@LAPTOP-E2MJK1UO:~$ cat /etc/apt/sources.list.d/ondrej-ubuntu-php-focal.list deb http://ppa.launchpad.net/ondrej/php/ubuntu focal main # deb-src http://ppa.launchpad.net/ondrej/php/ubuntu focal main # the corresponding gpg keys is also present jpmena@LAPTOP-E2MJK1UO:~$ ll /etc/apt/trusted.gpg.d/ | grep -i ond -rw-r--r-- 1 root root 360 Sep 17 16:13 ondrej_ubuntu_php.gpg #now we update again the package list jpmena@LAPTOP-E2MJK1UO:~$ sudo apt update .................................... # the package comes with php8.0, php8.1, php 8.2 I do install the last one jpmena@LAPTOP-E2MJK1UO:~$ sudo apt install php8.2 .................................................... The following additional packages will be installed: libapache2-mod-php8.2 libpcre2-8-0 php8.2-cli php8.2-common php8.2-opcache php8.2-readline # I do also install php8.1 as it is the official version for Symfony6 jpmena@LAPTOP-E2MJK1UO:~$ sudo apt install php8.1 ................................................
Setting the 8.1 version of php as the default
There is only one command to chose the php client active by default
jpmena@LAPTOP-E2MJK1UO:~$ sudo update-alternatives --config php There are 3 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/bin/php8.2 82 auto mode 1 /usr/bin/php7.4 74 manual mode 2 /usr/bin/php8.1 81 manual mode 3 /usr/bin/php8.2 82 manual mode Press <enter> to keep the current choice[*], or type selection number: #I press Enter since php8.2 is the one I want # I check the version: jpmena@LAPTOP-E2MJK1UO:~$ php --version PHP 8.2.0RC1 (cli) (built: Sep 14 2022 10:24:43) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.0RC1, Copyright (c) Zend Technologies with Zend OPcache v8.2.0RC1, Copyright (c), by Zend Technologies # I see that php8.2 is only a release candidate so I switch back to php8.1 jpmena@LAPTOP-E2MJK1UO:~$ sudo update-alternatives --set php /usr/bin/php8.1 update-alternatives: using /usr/bin/php8.1 to provide /usr/bin/php (php) in manual mode
I dont need to check for the apache php module since I will use the php embedded server of Symfony
Adding composer and the Symfony client
Composer
Now the the right php is installed we need a tool named Composer to manage the dependencies of a Symfony project
To install composer just go to the Composer download link and follow the instructions:
#first download the setup jpmena@LAPTOP-E2MJK1UO:~$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" # then check if the installer has not been corruptedduring download jpmena@LAPTOP-E2MJK1UO:~$ php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" Installer verified # Run the installer: jpmena@LAPTOP-E2MJK1UO:~$ php composer-setup.php All settings correct for using Composer Downloading... Composer (version 2.4.2) successfully installed to: /home/jpmena/composer.phar Use it: php composer.phar # place the php archive of composer in the path and rename it composer jpmena@LAPTOP-E2MJK1UO:~$ sudo mv composer.phar /usr/local/bin/composer # make it executable: jpmena@LAPTOP-E2MJK1UO:~$ sudo chmod +x /usr/local/bin/composer #check the version if it is the one announced on the composer website jpmena@LAPTOP-E2MJK1UO:~$ composer --version Composer version 2.4.2 2022-09-14 16:11:15
The Symfony client:
The Symfony client is a software written in the GO programming language (Sources are on GitHub). It is aimed at helping developpers creating and running Symfony projects.
To install the Symfony client just follow the instructions of the Symfony WebSite
- First import the symfony package source list and its keys
#installing the symfony repository and its gpg key jpmena@LAPTOP-E2MJK1UO:~$ curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | sudo -E bash [sudo] password for jpmena: Executing the setup script for the 'symfony/stable' repository ... OK: Checking for required executable 'curl' ... OK: Checking for required executable 'apt-get' ... OK: Detecting your OS distribution and release using system methods ... ^^^^: ... Detected/provided for your OS/distribution, version and architecture: >>>>: >>>>: ... distro=ubuntu version=20.04 codename=focal arch=x86_64 >>>>: NOPE: Checking for apt dependency 'apt-transport-https' ... OK: Updating apt repository metadata cache ... OK: Attempting to install 'apt-transport-https' ... OK: Checking for apt dependency 'ca-certificates' ... OK: Checking for apt dependency 'gnupg' ... RUN: Importing 'symfony/stable' repository GPG key ...gpg: WARNING: unsafe ownership on homedir '/home/jpmena/.gnupg' OK: Checking for apt signed-by key support ... OK: Importing 'symfony/stable' repository GPG key ... OK: Checking if upstream install config is OK ... OK: Installing 'symfony/stable' repository via apt ... OK: Updating apt repository metadata cache ... OK: The repository has been installed successfully - You're ready to rock! #verification that the repository and its keys have been installed jpmena@LAPTOP-E2MJK1UO:~$ cat /etc/apt/sources.list.d/symfony-stable.list # Source: Symfony # Site: https://github.com/symfony-cli/symfony-cli # Repository: Symfony / Symfony CLI # Description: The Symfony CLI tool deb [signed-by=/usr/share/keyrings/symfony-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/symfony/stable/deb/ubuntu focal main deb-src [signed-by=/usr/share/keyrings/symfony-stable-archive-keyring.gpg] https://dl.cloudsmith.io/public/symfony/stable/deb/ubuntu focal main
- Then install symfony client like any other Ubuntu package:
jpmena@LAPTOP-E2MJK1UO:~$ sudo apt install symfony-cli .................................................. Preparing to unpack .../symfony-cli_5.4.13_amd64.deb ... Unpacking symfony-cli (5.4.13) ... Setting up symfony-cli (5.4.13) ...
4 réponses à “Creating an environment on Windows for developping in Symfony 6”
Hey there are using WordPress for your blog platform?
I’m new to the blog world but I’m trying to get started
and set up my own. Do you require any coding expertise to
make your own blog? Any help would be greatly appreciated!
Thanks for some other fantastic post. Where else may just anyone get
that type of info in such a perfect approach of writing?
I have a presentation next week, and I’m on the search for such info.
Thanks in support of sharing such a good idea, article
is fastidious, thats why i have read it entirely
I am no longer positive the place you are getting your info, but good topic.
I must spend some time finding out more or understanding more.
Thanks for magnificent information I used to be on the lookout for this information for my mission.