-Host OS: windows10 Home Insider Preview ・ Guest OS: wsl2 Ubuntu 20.04
・ Php 7.4.7 ・ Composer version 1.10.7 ・ Laravel Framework 7.16.1
① Install php7.4 ② Install the php extension required to install laravel ③ Install composer ④ Install laravel & create a project
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
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.)
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
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 ...
It was displayed normally.
Laravel - The PHP Framework For Web Artisans Composer Install 7.x Laravel