Web page development using Laravel (1) Overview of Laravel and environment settings

Machine Learning Artificial Intelligence Natural Language Processing Semantic Web Algorithm Search Technology DataBase Technology Ontology Technology Digital Transformation DevOps UI and DataVisualization Workflow & Services IT Infrastructure PHP Navigation of this blog

Summary

PHP is a scripting language that runs on the server side and is primarily used for developing web applications. PHP was developed by Rasmus Lerdorf in 1995 and is currently developed and maintained by the open source community.

PHP is widely used to generate dynamic web pages, manipulate databases, upload and download files, and other functions. Since PHP can be embedded in HTML, it can also be used to execute PHP scripts directly within web pages. It is also widely used as a framework for popular web applications such as WordPress, Joomla, Drupal, etc., because it can run on many operating systems and is easily integrated with many databases and web servers, It is recognized as the language of choice for web application development because it can run on many operating systems and easily integrates with many databases and web servers.

To further streamline web application development, PHP has software that provides tools and functionality for web applications called application frameworks, such as Laravel, Symfony, CodeIgniter, and CakePHP.

This section describes the mechanism and specific implementation of Laravel, a PHP application framework, based on “PHP Framework Laravel Web Application Development.

In this article, I will give an overview of Laravel and describe how to set up the development environment.

Laravel Overview

Laravel is a PHP framework developed by Taylor Otwell. Although it is a framework, it has gained more support than many other frameworks.

One of the features of Laravel is its low learning cost. For example, one of Laravel’s unique features, Facade, allows you to use each function by simply calling PHP’s static class methods.

//Use the session facade to obtain key values.
Sname = Session::get("name");

At first glance, the above code looks like it is reading a class method of Session, but it is actually executing an instance method of another class. This is a good way to shield the framework’s internal complexities and provide an easy-to-use interface.

The next feature is that Laravel uses Symfony Component in its core, which is a proven framework that has been used for many years to develop various systems. The company is built on top of this foundation.

In addition, Laravel is a framework with many features. In addition to basic functionality such as routing, controllers, views, and ORMs (Object/Relational Mapping), Laravel also includes password and OAuth authentication, events, queues, unit tests, DI containers, and much more. Another feature is the ease of replacing core classes and adding functions in service providers and service containers.

Here is a brief overview of Laravel’s configuration

After installation, Laravel creates a Controllers directory under app/Http and a views directory under resource, but the directory arrangement is not enforced and Laravel itself manages dependencies and packages for each function. Composer is used, and as long as classes are autoloaded and loaded, the directory structure can be freely defined by the developer.

Development using the MVC (MOdel View Controller) pattern is of course possible, but it is also possible to use the ADR (Action Dpmain Response) and repository patterns, as well as domain-driven design such as layered architecture and hexa-later architecture. The architecture employed in this context can also be used. The types and sizes of web applications that developers create may vary, but Laravel allows development to proceed according to the methods and application policies that suit the development team.

Building a Laravel development environment (Laravel Sail)

Next, we will discuss how to build a development environment to run Laravel.

To build an environment for Laravel, a virtual environment is built on macOS or Windows, and an environment for running Laravel is built on top of it. Here, we first describe two typical methods, Laravel Sail and Homestead, for building an environment to run Laravel.

Laravel Sail includes the basic configuration required to run Laravel (PHP, built-in web server, MySQL), Redis middleware for caching, Mailhog (a simple mail server), Selenium and Node, and is an operating environment used with Docker. The company will be

In addition to the software included in Laravel Sail, Homestead includes the nginx web server, multiple RDBMS such as PostgreSQL, memcached, and Node including Gulp.

Laravel Sail comes standard with all the necessary software and has the advantage of being more nimble than Homestead; Homestead requires relatively more yaml file editing and command line operations to run Laravel applications in Vagrant. It also includes more software than Laravel Sail.

Launch Docker environment

Laravel Sail is an official development environment provided by Laravel, which allows you to easily build a Laravel development environment using a tool called Docker.

Docker is software that can create and run virtual environments called containers, and is characterized by its lightweight and high-speed operation compared to Vurtual Box, a virtual environment PF. In addition, servers, infrastructure resources, middleware, and various environment settings can be coded and managed, and the environment can be easily reproduced from the code. This mechanism makes it easy to match the OS and middleware settings of the development environment with those of the production environment, and its use has been spreading in recent years in a variety of web services.

Docker, the company that provides Docker, made a major strategic shift in 2020, selling its enterprise-oriented products to other companies and focusing on products for developers, and since then, Docker Hub, a repository service for Docker containers, and Docker Docker Hub will remain free for individuals, while Docker Desktop will remain free for individuals, but will be paid for by companies with more than 250 employees or more than 1.1 billion yen. (Starting in September 2019) Prices will be $5, $7, and $22 per month.

Laravel Sail runs Laravel applications on Docker virtual containers. The first step is to set up Docker, which is required to run Laravel Sail. Note that to run Dcoker in a window environment, a 64-bit version of windows 10 or higher is required.

To install Docker, access the “get started” page of Docker, and follow the instructions to “see docker desktop for mac” for mac and “see docker desktop for windows” for windows. Install the software.

In the case of mac, the CUP is divided into “intel chip” and “apple silicon” cases, but you can download the application for each chip version by selecting it from the button under “download docker desktop for mac” and downloading it to the application folder. The system can be made to work by moving it to a new location.

In the case of windows, download it by selecting the button under “download docker desktop for windows” and follow the instructions under “install Docker Desktop on Windows”. The following four steps are required.

  • Installation of docker desktop
  • windows subsystem for linux (WSL) installation and configuration
    • Install the WSLinux kernel update package for x64 machines from the microsoft page
  • installation and configuration of linux subsystems
    • Open windows powershell for command line operation from administrator privileges (right click on “windows PowerShell” from the windows menu and select “Run as administrator” to run it)
    • Enter the following command in Powershell to enable the windows subsystem for linux option feature
    • > dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux/all /norestart
      
      > dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
      
      >wsl --set-default-version 2
  • Setting up a linux subsystem for use with docker
    • Install a Linux subsystem to run on windows (go to Microsoft Store and click on “Ubuntu” to install)
    • To configure Docker to recognize the installed Linux subsystem, click the icon on the docker desktop menu bar to display the Setting screen, select the menu item “General”, and then select “Use the WSL 2 based engine”. Make sure it is checked.
    • Then click “resiuece” -> “WSL INTEGRATION”, check the Linux subsystem you installed (ubuntu in this case), and click “Apply&Restart” to restart Docker.
Laravel Sail

After installing and configuring Docker, download Laravel Sail. First, create a directory under the user’s home directory with the name “laravel_docker” from the command line, and download the file in that directory.

//Download Laravel Sail
#Go to home directory
$ cd

#Create [Laravel_docker] directory and move
$ mkdir laravel_docker
$ cd laravel_docker

#Download Laravel Sail using the curl command
$ curl -s https://laravel.build/sample | bash

During the download, enter a password to change directory permissions. When the final written message appears, the download is complete.

Thank you! we hope you build something incredible, Dive in with: cd sample && ./vendor/bin/sail up

A sample directory is created directly under the laravel_docker directory, and the sample directory contains a set of Laravel program files.

After downloading Laravel Sail, start Laravel Sail and run Laravel immediately. Go to the aforementioned sample directory on the command line, and then . /vendor/bin/sail up -d command.

//Laravel Sail startup commands
# Move to the sample directory and execute the startup command
$ cd sample
$ ./vendor/bin/sail up -d

When the command is executed, the following message is displayed and the startup process begins. The initial startup takes a few minutes because the necessary files are downloaded. When all six containers starting with “sample” are started and “done” is displayed, the startup is complete.

After Laravel Sail has been started, access “hyyp://localhost” in a web browser to see the Laravel Welcome screen.

To exit Laravel Sail, go to the command line screen and click . /vendor/bin/sail down.

In the Laravel command, “sail up” starts the container. sail up -d” starts the container in the background. The container can be terminated by “sail down”.

In the next article, we will outline the construction of specific applications.

コメント

タイトルとURLをコピーしました