تماشای این درس نیاز به اشتراک حرفه‌ای دارد.

Overview of Server Stack0:00

So, in this lesson, we are going to install the software needed to run our Laravel application on the VBS. We will obviously need to install php to interpret our PHP scripts into code that the VBS can execute. We will also need to install Composer to be able to install our application dependencies. But first, let's explore how we may allow clients on the web to run our Laravel application through web requests. On the left-hand side here, we have our Laravel application. We need clients to be able to command the server to run this application when they connect to port 80 or port 443.

Introducing Nginx Role0:36

We need clients to be able to command the server to run this application when they connect to port 80 or port 443. Obviously, for the server to be able to run the application, it needs to have PHP installed, along with any other PHP extensions our application may need. But PHP is just a programming language. You give it a name of a PHP file and it interprets the scripts in that file for the server to execute. We need to install a web server software on the VPS to receive web requests and forward them to where the PHP code lives. That's where Nginx is needed.

Linking via PHP-FPM1:16

them to where the php code lives. That's where Nginx is needed. It is an open-source web server that is highly efficient and reliable. So with Nginx standing on the edge of our VPS facing the public internet, and php installed on the server and ready to interpret the scripts inside the Laravel application, we need a link between them. Something that enables Nginx to start several php processes to handle the incoming web requests in the most efficient way. Unfortunately, php offers PHP FPM as a highly effective process manager for php. We will need to install PHP FPM on the server and configure Nginx to forward web requests

Unfortunately, php offers PHP-FPM as a highly effective process manager for PHP. We will need to install PHP-FPM on the server and configure Nginx to forward web requests to it. FPM will then take those requests and hand them to a pool of PHP processes that it manages. These processes will start our Laravel applications, pass the request data, receive the response, and hand it back to Nginx. So requests go through Nginx, PHP-FPM, and Laravel. And the response is handed from the Laravel application to PHP-FPM, and then back to Nginx. And that's basically the most common way of running PHP applications in production. Let's go ahead and install all this.

Installing Nginx and PHP3:23

And to do that, we need super user privileges on the server. The super user of the server is called root. And since we are logged in as the ubuntu user, we need to use the sudo program, which allows the root user to delegate certain privileges to certain users on the system. In AWS EC2 instances, all root privileges are delegated to the ubuntu user by default. So we just need to use the sudo program before running any commands that require super user privileges to inform the server that we want to exercise our privileges to run these commands. So here we run sudo apt update. The command will take a few seconds to execute. And once it's done, we will run apt install nginx php 8.1-fpm.

The command will take a few seconds to execute. And once it's done, we will run apt install nginx php 8.1 fpm. So this command will install nginx, php 8.1, and php 8.1-fpm. It will ask us if we want to continue, we will answer with yes. And here we go, nginx and php-fpm are installed. Now to verify that nginx works, we will need to visit the IP address of the server in the browser. So let's go copy the IP address, paste it in the browser window. And nothing, the browser keeps loading, but it's receiving nothing. Remember that our security group only allows access on port 22.

Opening Ports 80/4435:01

And nothing, the browser keeps loading, but it's receiving nothing. Remember that our security group only allows access on port 22. We will need to allow access on port 80 since that's the default port web browsers use. So let's do that. Let's go back to our stack template file. Add a new rule, this one will allow access on port 80. And while we are at it, let's add another rule to allow access on port 443, which is used by web browsers to access secure websites. Now let's go to the terminal and log out from the VBS session. Then run aws cloudformation deploy provide the stack name laracasts and the template.

Now let's go to the terminal and log out from the VBS session. Then run aws cloudformation deploy provide the stack name laracasts and the template file stack.json. Now we will wait for the stack changes to complete successfully, but I'll skip the waiting through the power of video editing. And here we go. Let's now go copy the IP address again and paste it in the browser. And it's working, the request came through, nginx listened, and it displayed its default welcome page. Now let's go back to the terminal, ssh into the server.

Installing Composer Dependencies6:25

welcome page. Now let's go back to the terminal, ssh into the server. And now let's install the libraries needed to run composer and install the app dependencies. So we run sudo apt install. We need the zip library unzip, and the zipphp extension, the curl extension, and the xml extension. Run the command, approve the installation. And here we go. Now let's install composer by pasting the install command. And done.

Now let's install composer by pasting the install command. And done. Let's move the composer.phar file to the local /usr/local/bin directory so we can run composer from anywhere on the server. So sudo mv composer.phar /usr/local/bin/composer. Let's verify this step, run composer --version. And here we go. Composer is installed and we can run it from within any directory on the VPS. And now we have all the software that we need to install and run our Laravel application. And that's what we are going to do in the next lesson.

And now we have all the software that we need to install and run our Laravel application. And that's what we are going to do in the next lesson. I will see you then.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟