Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Time:2020-8-1

(Fei) Yao (Hua)

As time went by, four months passed quietly, and my first project in my life came to an end. And I also became a master of HTML, PHP, WeChat official account development and Linux server deployment code what I did not know.
Looking back on the previous exploration process, it is not hard, but also difficult. Looking back on the process of crawling around the posts in order to understand a function before, it is really full of emotion. With the progress of my own bit by bit, the ability of consulting materials is gradually strengthened, and the time for solving problems is greatly shortened.
In order to make Xiaobai, who is just beginning to learn from me, to avoid detours, I recorded the process of deploying thinkphpp5.1 for reference.

1: Linux simple command


Connect to the server:

For the students who have just started, when you get a Linux server, the first thing you think of is to open the remote desktop connection of windows, and then excitedly enter the IP address. After that, the remote connection fails

Attention, this is Linux, not windows. If it is not set up, Linux can’t connect to the desktop directly. In addition, Linux doesn’t use graphical interface, but uses simple and efficient command line.

So, if you want to log in to Linux, you need to use a tool called SSH.

What is SSH

SSH is the abbreviation of secure shell, which is formulated by the network working group of IETF; SSH is a security protocol based on application layer. SSH is a reliable protocol which provides security for remote login sessions and other network services. SSH protocol can effectively prevent information leakage in the process of remote management.
——From Baidu Encyclopedia

For Windows users, you need to download the SSH tool putty. If you are using GitHub, SSH can be directly supported in its bash.

For Mac users, the terminal directly supports SSH.

Linux users… Definitely don’t need to read this introductory article…

First command, login:

ssh [email protected]
Change "root" to the user name on your server. If it is a newly installed system, it is likely to be root
Replace "XXX" with the IP address of the server

After entering enter, you will be prompted to enter the password. The password entered in the terminal is invisible, so don’t be surprised. Just enter it at ease.

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

After successful login, you can see the input line again. The user changes from a local user to a user on the server.

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

If you need to disconnect SSH, just log out

logout

Next is the basic operation

Move to a directory:

cd /your/place

The first / after the CD is the root, which means that this is the top level of the tree structure, and everything else is below the root.

Maybe a beginner might think, “you just give me a CD command and let me find the file. How can I find it? Do I have to remember the location of every file? “

Nonono, there is a artifact in the terminal called tab:

  • If the user can’t remember the full name of the command, click tab, and the system will try to match the command as much as possible: when there is more than one optional command, the command line does not respond. If you press tab again, the terminal will print all possible commands
  • When the user can’t remember what files are in the current directory, they just need to CD to a certain path and then press tab twice to display all the files in this directory. Then, enter the name of a part of the directory you want to go to, and click tab. If this prefix is unique in the current directory, it can be automatically supplemented.
Command line without tab, soulless

Display the folder under the directory:

ls

If you need to show hidden files:

ls -a

New folder: (test folder name)

mkdir test

Folder or file name change: (original file name, new file name can be supplemented by tab)

mv test ThinkPhp

Create a new file: (directory name / file name)

touch test/a.txt

To edit a file using VIM:

vim a.txt

VIM simple operation:

Up and down left and right keys - cursor movement
I - insert text
D - delete entire line
ESC - exit current mode (i.e. enter command mode)
: - enter command
: W - write to file (save)
: Q - exit
: WQ - save and exit

Important: modify the folder permissions (test is the folder name)

chmod -R 777 test
//- R means to recursively change permissions to files and files in a folder
// r(4),w(2),x(1)

Important: folder deletion (necessary for running)

rm -rf test
//If you need root permission, change to
sudo rm -rf test
//Don't try any important documents at your own risk

With the above command, you can basically operate Linux command line smoothly.


2. Selection of server software


At first, I planned to manually install the operating environment on the server, until one day, the teacher suddenly said: there are images directly integrated with the operating environment on the major virtualization platforms. Then I suddenly realized that the use of the integrated environment image can greatly reduce the time of struggling.
As you can see in the figure below, Apache, PHP, mysql, FTP are all available. As long as you install the image, you don’t have to fiddle with anything.

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

(if you don’t want to use the image of the integrated software, you can install the original system and download the running environment by yourself.)

After the system is installed, the browser input IP or domain name, you can see the successful jump to the TP home page, which indicates that the system and the operating environment are working normally.

The next step is SSH login to the server.


3. Deployment of tp5.1


For different images, the location of the document root may be different. This path should be defined when encapsulating the image. If you can’t find the root of TP5 the first time you log in, you can use the search method:

find / -name thinkphp
//"/" is the search path. Setting it to the root directory is to search all files
//If you search the root directory, it will take a long time. Please wait patiently
//ThinkPHP is the name of the file to search for

Find the file directory, CD to that directory, LS, you can normally display the TP5 framework files.

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Then rename the old TP folder because we want to add a new folder

(this article changes ThinkPHP to thinkphp00)
mv thinkphp/ thinkphp00/

We can use GitHub to transfer code to the server and avoid setting up FTP. Therefore, first submit the code to GitHub repository locally, and then find the clone link in GitHub’s repository and click the button to copy.

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Find the parent directory of the original ThinkPHP on the terminal,

git clone http://your.address thinkphp
//HTTP is followed by the GitHub repository address
//ThinkPHP is the name of the folder cloned to the server,
//If not, the default folder name of the project will be used

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Since Apache in the image changes the location of the root directory, the URL is shorter

(in order to further reduce the length of the URL, you can turn on the rewriting function in the future index.php I don’t need to input any more)

//No input is required index.php And public:
http://your ip/public/index.php/Module/Controller/Function
//Just enter:
http://your.ip/index.php/Module/Controller/Function
//If you turn on override again, the link becomes:
http://your.ip/Module/Controller/Function

If there is no accident, you should be able to access the methods under a certain controller

If “not found” appears, it indicates that the link input may be wrong, or the location set in Apache is not correct, or the settings are not set correctly

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server


4. Deploy MySQL


After a series of operations, the website of our project has been accessible, but if you click a few times, you will report an error. Then… Have you forgotten something – yes, database! The database has not been imported.

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud ServerQL.png](/img/bVbzs92)

Start the service first, and then try to log in to the database

//Start MySQL service
service mysqld start
//Log in as root with password
mysql -u root -p

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Then I suddenly found out that I didn’t know the default password

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Then I went to search and found that the password of the goods was in a file, so I found the document

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

As expected, some achievements have been made,

It should be noted that the password here is only for viewing. If you directly change the content of this file, any information in the database will not change

After you have the password, you can log in successfully. At this time, you can only log in locally and cannot access remotely (prompt 1130 error, permission problem)

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Therefore, it is necessary to turn on the user’s remote access rights

//Find the host name, account number and password of all users
select host,user,passward from mysql.user;
//Authorize any host name to log in remotely with root user and 123456 password
grant all on *.* to [email protected]"%" indentified by '123456';
//Note: the password is only for demonstration. In the actual production environment, it is strictly forbidden to use the root user for remote access, let alone set the password to 123456 like an idiot!!!

Then, in Navicat software, you can remotely connect to the database on the server

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

As like as two peas, the same database is set up on the server as OK.

(I won’t tell you that datasheets in Navicat can be copied directly by dragging and dropping them.)

Then, it’s almost the last step. Modify the database address in the config on the server

cd /your thinkphp address/thinkphp/config 
vim database.php

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

Just change the user name and password to. Then ESC: WQ enter saves and logs out. When you log in again, you will find this long lost smile

Getting started with Linux basic commands and deploying thinkphpp5 + MySQL on Cloud Server

At this point, the cloud server deployment of ThinkPHP and MySQL is completed!


Summary:


Linux command and project deployment can be said to be the basic operation of programmers. Before learning these contents, I also took many detours. The significance of blogging is to find problems and share the process of solving problems.

For linux commands, my own experience is that you don’t need to memorize the code deliberately, but when you use it, you will naturally become familiar with many skills as you gradually enrich your experience.