در حال بارگذاری ...

Installing Laravel Octane1:27

extension, the SWOL PHP extension, or the Roadrunner library. Let's get started by running Octane on our local machine and see how we can do it. We will start by installing Octane using Composer. So composer require laravel/octane. And then we run php artisan octane:install. Octane asks if we are going to use Roadrunner or SWOL. We will go for SWOL. And here we go. The octane:install command adds a new octane.php configuration file in our project, let's check it out.

Reviewing Octane Configuration2:01

The octane install command adds a new octane.php configuration file in our project, let's check it out. And the first attribute here defines the Octane server we are using. It uses Roadrunner by default. But if we check the .env file, we will see that the octane install command added octane_server equals SWOL, because we selected SWOL while installing Octane. Now back to the configuration file. And here we can see an option to force HTTPS links. We will leave that as false since we don't need HTTPS on the local machine. And below that, we can see a bunch of listeners where we can run custom logic when certain

We will leave that as false since we don't need HTTPS on the local machine. And below that, we can see a bunch of listeners where we can run custom logic when certain Octane events are fired. For example, when an Octane worker process starts, Octane adds two listeners to override the native php isUploadedFile and moveUploadedFile methods as they need special handling. There are also multiple listeners registered in the requestReceived event. We will look into these later in this course. For now, we will leave the configuration defaults and go test our setup. Now instead of installing the SWOL php extension on our machine, we can use Laravel Sail to run a Docker image that have our application installed along with the SWOL php extension.

Installing Laravel Sail3:23

Now instead of installing the SWOL php extension on our machine, we can use Laravel Sail to run a Docker image that have our application installed along with the SWOL php extension. So let's go ahead and install Sail. So composer require laravel/sail --dev. And then we install it by running php artisan sail:install. We get asked for the services we want to install with MySQL selected by default. So we will keep the default and continue. The command will take a couple of minutes to finish on the first install on the machine. So let's give it some time. During the installation, Sail pulls several Docker images and builds multiple containers.

So let's give it some time. During the installation, SAIL pulls several Docker images and builds multiple containers that we need in order to serve our Laravel application. And here we go, SAIL installation is complete. Now let's publish the SAIL configuration files. So php artisan sail:publish. This will publish a Docker directory in the root of our project. So let's go check it out. And open the directory that corresponds to the php version we are using in SAIL. The default is php 8.2.

Configuring Sail for Octane4:43

And open the directory that corresponds to the php version we are using in SAIL. The default is php 8.2. So let's open the 8.2 directory. Here we have the Dockerfile, the php.ini file, the start-container.sh script, and the supervisor configuration file. Let's open the supervisor.conf file. Under the php program table, let's edit the command attribute. This is the command that SAIL will run to start the php server that runs our application. We will replace it with the octane server. So we will need to change the command to run octane start instead.

Building and Running Containers5:22

We will replace it with the octane server. So we will need to change the command to run php artisan octane:start instead. Now let's build the SAIL container, php artisan sail:build, and add the --no-cache flag. I use this flag here so Docker builds a fresh container image and not use any layer that already exists on my machine. This may take a few minutes, so give it some time. And here we go. Now let's start the SAIL container, php artisan sail:up, all looks good. So let's visit our app in the browser, http://0.0.0.0 and on port 80. And here we go.

Verifying Octane Setup6:07

So let's visit our app in the browser, http://0.0.0.0 and on port 80. And here we go. Our application is now served by Laravel Octane from inside the Docker container. Well that was easy. We now have Octane up and running with a SWOOl server on our machine. This server starts a number of php worker processes, loads the Laravel application in memory and then waits for incoming requests. If you prefer to see or to use Roadrunner instead of SWOOl, you may apply the same steps but choose Roadrunner instead of SWOOl. Roadrunner requires a binary to be present.

Installing OctaneConfiguring Sail to run Octane

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