[Linux] WSL2 Build an environment for laravel7 with Ubuntu 20.04

Development environment

-Host OS: windows10 Home Insider Preview ・ Guest OS: wsl2 Ubuntu 20.04

Environment to be built this time

・ Php 7.4.7 ・ Composer version 1.10.7 ・ Laravel Framework 7.16.1

procedure

① Install php7.4 ② Install the php extension required to install laravel ③ Install composer ④ Install laravel & create a project

① Install php7.4

Execute the following command.

1: Check for package updates

$ sudo apt update 

2: Install the software-properties-common package.

$ sudo apt install software-properties-common

I want to add a repository in step 3, but by default the command to add a repository is not installed. The packages installed here are for adding repositories.

3: Add repository

$ sudo add-apt-repository ppa:ondrej/php

4: Update the package again. (① Same procedure)

5: Install PHP

$ sudo apt install php7.4

After checking the version, if the following is displayed, the installation is complete.

$ php -v

PHP 7.4.7 (cli) (built: Jun 12 2020 07:44:38) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.7, Copyright (c), by Zend Technologies

For the time being, check the installation location of php.

$ which php
/usr/bin/php

② Install the php extension required to install laravel

According to laravel official website, the following modules (packages that provide extensions) are required to use laravel.

BCMath PHP Extension Ctype PHP Extension Fileinfo PHP extension JSON PHP Extension Mbstring PHP Extension OpenSSL PHP Extension PDO PHP Extension Tokenizer PHP Extension XML PHP Extension

You can check the installed modules with the following command.

php -m

By default, BCMath, Mbstring and XML are not installed. In addition, zip is required when executing the installer command of laravel with Composer, so install it with the following command together with these.

sudo apt install php7.4-bcmath php7.4-mbstring php7.4-xml php7.4-zip

** If you do not add "php (installed php version)-" at the beginning of the package name, it will cause an error. It's easy to forget, so be careful. ** **

Run php -m again to see if the module was installed successfully.

[PHP Modules]
bcmath
ctype
fileinfo
json
mbstring
openssl
PDO
tokenizer
xml
zip

[Zend Modules]
Zend OPcache

(Other modules are displayed, but this time they are omitted.)

③ Install Composer

Copy and paste the command described in Composer official website download page.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

(The command spans multiple lines, but you can copy and paste them all at once.)

Composer will be installed in the current directory, but move it to a directory in your path.

sudo mv  composer.phar /usr/local/bin/composer

For those unfamiliar with Linux commands, the above command 1: Change the location of composer.phar from the current directory (current directory) to $ HOME / usr / local / bin / composer 2: composer Renaming .phar to composer.

Check the version of Composer.

composer -v

Composer version 1.10.7 2020-06-03 10:03:56

④ Install laravel & create a project

Download the laravel installer using Composer.

composer global require "laravel/installer"

As soon as the download is complete, add the following line to your .bashrc and put it in the Composer vendor / bin directory.

.bashrc


export PATH="$PATH:$HOME/.config/composer/vendor/bin"

After passing the path, move to the directory for the project and execute the laravel new command to create the laravel project.

mkdir laravel_sample
cd laravel_sample
laravel new sample_app
.
.
.
.
.
Package manifest generated successfully.
Application ready! Build something amazing.

Various messages will be displayed, but if this message is displayed on the last two lines, there is no problem.

Finally, check if you can display the initial page of laravel. In laravel, you can perform various operations with the php artisan command.

In Ruby on Rails, the rails command is used for operation, but I want to be careful not to execute the laravel command in the same way.

cd sample_app
php artisan serve

When you access localhost: 8000 ...

スクリーンショット (9).png

It was displayed normally.

Reference material

Laravel - The PHP Framework For Web Artisans Composer Install 7.x Laravel

Recommended Posts

[Linux] WSL2 Build an environment for laravel7 with Ubuntu 20.04
Build python3 environment with ubuntu 16.04
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
Build an environment for Blender built-in Python
Build an LNPP environment on Amazon Linux 2
Create an environment for Django x Apache x mod_wsgi with Vagrant (Ubuntu 16.04)
[Linux] Build a jenkins environment with Docker
[Linux] Build a Docker environment with Amazon Linux 2
Steps to build a Django environment with Win10 WSL Ubuntu18.04 + Anaconda + Apache2
For beginners to build an Anaconda environment. (Memo)
Build python environment with pyenv on EC2 (ubuntu)
Building an Anaconda environment for Python with pyenv
Various commands for building an environment with Apache
Build a Kubernetes environment for development on Ubuntu
How to build Java environment on Ubuntu (Linux)
Try building an environment for MayaPython with VisualStudioCode
Build a mruby development environment for ESP32 (Linux)
Build an Arch Linux environment on Raspberry Pi
I tried to build an environment of Ubuntu 20.04 LTS + ROS2 with Raspberry Pi 4
Creating an environment for OSS-DB Silver # 1_Create a Linux environment (CentOS7 virtual environment) with VirtualBox/Vagrant
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
Build an interactive environment for machine learning in Python
Build a python environment for each directory with pyenv-virtualenv
Building an environment for natural language processing with Python
Create an environment for MkDocs on Amazon Linux (attempted)
Create an environment for test automation with AirtestIDE (Tips)
Build a Django environment for Win10 (with virtual space)
I tried to build an environment for machine learning with Python (Mac OS X)
Create an environment with virtualenv
Linux Kernel Build for DE10nano
Build an Anaconda virtual environment
Build python environment with direnv
Linux environment construction (on WSL environment)
Rebuilding an environment for machine learning with Miniconda (Windows version)
Linux beginners create Ubuntu 16.04 environment on Docker (for Mac)-first half-
Build Azure Pipelies with Azure DevOps in a Linux self-hosted environment
Build a machine learning scikit-learn environment with VirtualBox and Ubuntu
[Memo] Build a development environment for Django + Nuxt.js with Docker
Build an Ubuntu python development environment on Google Cloud Platform
Create an environment for "Deep Learning from scratch" with Docker
Create a Todo app with Django ① Build an environment with Docker
Build a LAMP environment with Vagrant (Linux + Apache + MySQL + PHP)
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
The basics of building an in-house server for Linux (CentOS 8.1, openSUSE 15.1, Ubuntu 20.04)! File server with Samba
No more dual boot or VM! Let's build a Linux environment with WSL2 & Windows Terminal [WSL2]
I created an environment for Masonite, a Python web framework similar to Laravel, with Docker!
DL Laravel environment construction method (Linux)
Prepare pipenv environment with amazon Linux 2
Create a Python execution environment for Windows with VScode + Remote WSL
Build python virtual environment with virtualenv
Build Mysql + Python environment with docker
[AWS] Build an ECR with AWS CDK
Build Flask environment with Dockerfile + docker-compose.yml
Build PyPy execution environment with Docker
Build IPython Notebook environment with boot2docker
Created an environment for Anaconda & Jupyter
Build Python 3.8 + Pipenv environment on Ubuntu 18.04
Using Kali Linux Gui with WSL2
Create a USB boot Ubuntu with a Python environment for data analysis
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
Build an environment to execute C ++ functions from Python with Pybind11 (for Windows & Visual Studio Code people)