Welcome & Setup Overview
What's up developers and welcome back to my new video where we're going to install all tools that you need when you want to create your Symfony project.
Quick note, do you want to support the channel and want me to continue on creating content? You can support the channel on Patreon right now where you can benefit just as a private discord group where you can share your coding issues and other developers will help you out. If you are interested to join, the link will be in the description down below.
The first part of this video is based for Mac users. If you are interested in learning how to set up everything properly for windows or linux I recommend you reading through the documentation I've put on my github.
Once you start learning Symfony I kind of expect you to already have PHP and MySQL installed. If you have done that you don't need to follow the first part of this course, but you can skip forward to the section where we install composer. Also you can install the same tools that I'm installing through brew since it will be exactly the same for windows and linux through their official website.
Installing Homebrew on macOS
Since Symfony is created with PHP, we obviously need to make sure that we have PHP installed. I have deleted everything from our local machine to do it from scratch. PHP can be installed through different ways. You can set up XAMPP, but I personally prefer to use Homebrew. Homebrew is a third-party package that manages your applications on Apple operating systems.
As you can see, I'm currently located on the official website of Homebrew, which is homebrew.sh. And right on the screen, you'll see a section where they are telling us how we can install brew on our local machine. As you can see, it can be done through a bin bash command. So what we can do is to click on the icon that we have right here to copy the entire line of code, which needs to be pasted inside the terminal.
So I've already got my terminal installed and open, and every Mac device has one as well. As you can see right now, mine looks a bit fancier than yours, but it will do the same exact thing. Now what we can do inside the terminal is basically command v to paste the line of code that we just copied and hit enter.
It's asking us for a password, so let's simply add it. Hit enter. It's telling us what it will be installing, and you have the option to go back right now, but we don't, so let's hit enter. And it's installing everything right now. And Homebrew is a very big software package, so this might take a while. So pause the video and I'll see you back once it's done.
Installing & Upgrading PHP with Homebrew
Alright, as you can see, Brew has been installed for me. So what I want to do right now is to run a command called brew help to double check if everything has been set up correctly.
As you might have noticed, the command does work, so Brew has been installed. I don't want to dive into Brew because it could be an entire course for itself, but what I want to do right now is to install PHP through Homebrew.
Most of you guys might have PHP installed since it is a requirement before diving into learning Symfony. Therefore, you can simply double-check it by performing the php --version command. As you can see, my terminal returned a message right here saying that the command PHP has not been found, meaning that I have no PHP installed on my local machine.
It's super easy in Brew to install packages. You need to start off by writing down the keyword brew, followed with the action that you want to perform. In our case, we're going to install something, so let's say space install. Then you need to specify what you want to install. Once again, we're trying to install PHP right here, so let's say space PHP. Let's hit enter. And this might take a minute as well. Once again, pause the video and I'll see you back once it's done.
With the new release of Symfony 6, PHP 8.0.2 or higher is required when you want to run your Symfony projects. There are also some other tools that you need to have installed for Symfony, such as ctype, iconv, pcre, session, SimpleXML, and tokenizer. But don't worry, this will all be handled once you install PHP.
Alright, as you can see it has been finished. And if I scroll up, you'll see that right here PHP has been added with a version of 8.1. Now if this hasn't been outputted for you, you can simply run php --version. And right here you will see that version 8.1.0 has been installed on my local machine.
Now, let's say that a new PHP version comes out in the future and you want to upgrade your PHP version. Well, that can simply be done through Brew as well by saying brew upgrade php. If I run it right now, I'm getting a warning saying that PHP 8.1.0 has already been installed.
Installing MySQL with Homebrew
Now the next tool that we need to install is obviously MySQL. I'm personally not a huge fan of using phpMyAdmin, so let's install that through Brew as well. You simply need to perform the Brew command again. We're going to install something, which is called MySQL.
I'm not going to hit enter since it will overwrite all databases that I currently have. So be aware of that. Since I'm also working on some real life projects, I want you to run this command if you have not installed MySQL.
Once you have installed MySQL, you can perform the mysql command to get access to your databases. If you have a password on your laptop or PC, it will most likely ask for it the first time.
Installing Composer
Next to PHP and MySQL, we will be using a package manager called Composer. Composer might be weird once you start using it for the first time, but once it clicks, you will see how incredible it is.
Now you can install Composer through Brew, but since Windows and Linux need to install it as well, we can make use of their official documentation and website. So let's navigate back to the browser and let's change the URL to getcomposer.org.
Alright, and let me zoom in. Now on the landing screen, you'll see their logo. It says that it's a dependency manager for PHP and we have a download button, so let's click on it. It's simply telling us what we need to do. We have these four PHP lines of codes that we need to run inside the single line. But if we scroll down, you will see an option right here where you can manually install it. Personally, I'm not a big fan of this since it takes a while. So let's scroll up, copy these four lines of code, navigate back to the CLI, exit MySQL, and right here let's command v it and let's hit enter.
It's telling us that Composer 2.1.14 has successfully been installed. We're not completely done yet since we need to add Composer's system-wide vendor bin directory in our path. It might be something you've never done, so let's do it together.
Adding Composer to the System PATH
The path is a system level variable that holds a list of directories. You can check it out by echoing out your dollar path. So your variable path. Hit enter. And this will show a path that you don't need to know out of your head, and my path will probably look different than yours as well. And we're not going to use it again. We're just going to add our Composer right here, and then we're done.
This path is coming from the .bashrc file from the root of our operating system. If you are located in a different location inside the CLI than your root, you simply need to perform a cd to change directories to the root. Once you see the tilde right here, you know that you've reached your project root.
Now if we perform an ls right here to show all files that we have, you will not see a .bashrc file. That's happening because a .bashrc file is a hidden file which starts with a punctuation mark. Therefore we need to perform the ls command again, but we need to add a flag to it of space -a to list all files. It's alphabetically, so let's scroll up to the B section, and right here you will see a .bashrc file.
What we need to do is to enter this file, which can be done through nano. So let's say nano .bashrc. Based on the programming language that you have used, you will find maybe none, one, or multiple exports right here. What we need to do is creating a new one to export our composer file. So let's go right below the last export we had and let's create a new export called path is equal to double quotes. Inside the double quotes we're going to add a dollar sign, home, forward slash, dot composer, forward slash, vendor, forward slash, bin, colon, dollar sign path.
We need to save and exit this file, which can simply be done by pressing down the Control X button. It's asking us if we want to save it, so let's press Y and let's hit enter.
Conclusion & Next Steps
Now that was everything we need. We will be setting up Visual Studio Code in the next episode, but after that we will be starting off building our first Symfony project through Composer.
That being said, this was everything that we need for Symfony. If you do like my content and you want to see more, leave this video a thumbs up. And if you're new to this channel, please hit the subscribe button.