Building LNMP development environment from scratch

Time:2021-3-17

LNMP environment configuration practice

1. Install Linux virtual machine

system requirements

Windows 7 and above

Install VirtualBox virtual machine tools

VirtualBoxIs Oracle’s open source virtual machine software. VirtualBox is known as the strongest free virtual machine software, it not only has complete functions, but also has excellent performance! VirtualBox supports most popular systems, such as MAC, windows, Linux, etc.

Please go to Baidu disk to download:

Link:pan.baidu.com/s/15nYWNHuHHYEWoVGwF…Extraction code: rk4p

Building LNMP development environment from scratch

Then follow the prompts to install step by step.


Install vagrant

VagrantIt is a tool for managing virtual machines, supporting the current mainstream virtual machine systems such as VirtualBox, VMware, AWS, etc. The main function of vagrant is to provide a configurable, portable and reusable software environment. Vagrant lets you write aVagrantfileFile to control the startup of the virtual machine, the configuration of the virtual machine network environment, the file sharing between the virtual machine and the host, and automatically execute some configuration scripts after startup, such as automatically executing a shell script to install some necessary development tools, such as installing and configuring mysql, PHP, and even automatically configuring the nginx site. This means that in a multiplayer project, you just need to synchronizeVagrantfileEach person on the machine has their own development environment, which can ensure the consistent development environment.

Please go to Baidu disk to download:

Link:pan.baidu.com/s/15nYWNHuHHYEWoVGwF…Extraction code: rk4p

Then step by step, follow the default installation.

Building LNMP development environment from scratch


Select virtual machine box

Here we chooseUbuntu16.04First, create a new empty folder in a virtual machine box, and open the shell or CMD command window

Enter the following command:

vagrant init ubuntu/xenial64
vagrant up

Using SSH to connect virtual machine

vagrant ssh

Attached: common instructions of vagrant

Import box

vagrant box add [BOX NAME] [BOX URL]

Show box list

vagrant box list

Remove box list

vagrant box remove [BOX NAME]

Initialize vagrant (create a vagrant environment for the current directory)

vagrant init [BOX NAME]

Start vagrant

vagrant up

Close vagrant

vagrant halt

Stop vagrant

vagrant suspend

Restart virtual machine

vagrant reload

View virtual machine status

vagrant status

Delete the vagrant environment of the current directory

vagrant destroy

2. Install nginx

First, initialize the apt source and use apt fast to improve the download speed

sudo add-apt-repository ppa:apt-fast/stable
sudo add-apt-repository -y ppa:nginx/stable
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update
sudo apt-get -y install apt-fast

When installing apt fast, select apt get, set the thread to 16, and then select no to confirm the installation

Use the following instructions to install nginx

sudo apt-fast -y install nginx

Check out the version information of nginx we installed

nginx -v

At this time, the terminal displays

nginx version: nginx/1.16.1

Use the following command to start the nginx service

sudo service nginx start

3. Install MySQL

Use the following instructions to install MySQL

sudo apt-fast -y install mysql-server

You will be prompted to enter the database during installationrootThe account password is easy to debug in the development environment and can be set simply. Here we set it asroot

After installation, use the following instructions to test whether the installation is successful

mysqladmin --version

The following is displayed in the shell

mysqladmin Ver 8.42 Distrib 5.7.32, for Linux on x86_64

4. Install PHP

Here we choose to install php7.4 version, the latest version of PHP is 8.0

sudo apt-fast install -y php7.4-bcmath php7.4-cli php7.4-curl php7.4-fpm php7.4-gd php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-pgsql php7.4-readline php7.4-xml php7.4-zip php7.4-sqlite3 php7.4-redis

Then we use the following instructions to check the PHP installation

php -v

If the following contents appear on the screen, PHP is installed successfully

PHP 7.4.13 (cli) (built: Nov 28 2020 06:24:27) ( NTS )

Copyright (c) The PHP Group

Zend Engine v3.4.0, Copyright (c) Zend Technologies

with Zend OPcache v7.4.13, Copyright (c), by Zend Technologies

5. Configure port mapping

Modify hostvagrantfileFile, add the following content to map the 8000 port of the host to the 80 port of the virtual machine

config.vm.network "forwarded_port", guest: 80, host: 8000

Then update the vagrant with the following command in the shell

vagrant provison

Then enter the following command to restart vagrant

vagrant reload

At this point, use Google browser to enter in the address barlocalhost:8000The following interface will appear

Building LNMP development environment from scratch

Development environment preparation

In the previous chapter, we have prepared the basic running environment for web development. Next, we will configure and use it

1. Choose an easy to use text editor

There are many common text editors, here to recommend two text editors

  • Sublime Text
  • VSCode

Take vscode as an example

How to install

Go straight tocode.visualstudio.com/downloadDownload the installation package.

Install plug-ins

Plug in name explain
EditorConfig for VS Code Code tab unification
advanced-new-file Quick new file
Duplicate action Right click to quickly create a file copy
Laravel Blade Snippets Blade template syntax highlighting

2. Choose an easy to use command line tool

As an excellent programmer, proficient command line operation is also essential. Many of our operations will use the command line, such as git operation; virtual machine management; deployment to the line, etc.

Here we recommendGit for Windows, install directly after download, do not require too much configuration, default.

3. Choose an easy to use browser

Browser we recommendChromeIt has a very powerful “developer Toolbar” that you can use to modify HTML structure, change CSS properties, debug JavaScript code at breakpoints, monitor HTTP requests on Web pages, etc

Building LNMP development environment from scratch

4. Modify vagantfile, configure network card and code share folder

Create a new code folder locally, open the vagrantfile file with the editor, and add the following configuration

config.vm.network "private_network", ip: "192.168.100.101"
config.vm.synced_folder "../code", "/code"

And then input it at the terminal

vagrant provison
vagrant reload

Then use the following command SSH to connect to the virtual machine

vagrant ssh

Then check the network card configuration

ifconfig -a

In the terminal, we can see the following contents: the network card is configured successfully

enp0s8 Link encap:Ethernet HWaddr 08:00:27Building LNMP development environment from scratch7b:6d

inet addr:192.168.100.101 Bcast:192.168.100.255 Mask:255.255.255.0

At the same time, our local code folder has been shared with the / code directory in the virtual machine

At this point, we enter in the browser192.168.100.101You can see the contents of our nginx welcome page

5. Install winscp and connect virtual machine

Baidu search winscp download and install

Modifying SSH connection configuration

Enter the following command to edit the SSH configuration file

sudo vi /etc/ssh/sshd_config

PressiKey to make the VI editor enter the insert modify modePasswordAuthenticationPut the backnoAmend to readyes, press on the keyboardEscKey, input:wqStay out.

Enter the following command to restart the SSH service

sudo service sshd restart

Install and configure login winscp

Search winscp, download and install it, start the software, create a new site in winscp, as shown in the figure below, and select the file protocolSCP, the password is the same as the user namevagrant

Building LNMP development environment from scratch

Then click Advanced, as shown in the figure below, and click in the left environmentSCP/ShellThere’s one on the rightShell(H)Choose fromsudo su -

Building LNMP development environment from scratch

After logging in to the site, the SCP connection of the virtual machine is completed, and then the files in the system can be modified with the permission of the root account.

6. Using database management software to connect database

Here to recommend a database management softwareNavicat PremiumThis is a convenient visual database management client software

Next, we first set the following MySQL settings in Ubuntu, so that the software can log in to the database with the root account

We can use winscp software to connect the virtual machine and find the/etc/mysql/mysql.conf.d/mysqld.cnfFile, right click to select Edit.

We found it

bind-address = 127.0.0.1

Leave out the comment and change it to

#bind-address = 127.0.0.1

Restart MySQL with the following command

sudo service mysql restart

Next, we create a new user and database with the root account in the terminal

When we install mysql, this is the password of the root account, which is also root. Here we use the following instructions to log in to MySQL

mysql -uroot -proot

At this time, the terminal displays the following information

Server version: 5.7.32-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql>

Now let’s create a file namedapp_mailDatabase of

CREATE DATABASE `app_mail` charset=utf8;

Note that MySQL ends with a seal. You must enter a seal before the end of the command. Otherwise, you can continue to add content

Then we create a user with the same name and give it corresponding permissions

use mysql;
GRANT ALL ON app_mail.* TO 'app_mail'@'%' IDENTIFIED  BY 'app_mail';

At this point, we created an app_ Mail database and account password of the same name. At this time, we can use the management software to log in to the database.

We first enter exit to disconnect the terminal from the database. Then we use the following configuration to create a MySQL connection.

Building LNMP development environment from scratch

This work adoptsCC agreementReprint must indicate the author and the link of this article