(1) Environment configuration and operation of TinyWebServer

C++ lightweight web server under Linux, project source: TinyWebServer

Configuring the environment (preparing for downloading code, compiling and running)

1. Install VMware

VMware official website

Select the product and click Workstation Pro

Download the trial version (note: you need to register your own account on the official website)

After the download is complete, double-click the exe file

Click next

After agreeing to the agreement, click Next

Change the installation path and click “Next”

Click “Next”

Click “Next”

Click “Install”

Click “Done”

After that, VMware is installed successfully, double-click to open it from the desktop.

Fill in “JU090-6039P-08409-8J0QH-2YR7F” in the “I have a license password for VMware Workstation 17 (H)” order box, and then click “Continue”.

Click “Done”

You can use WMware normally after that

2. Download Ubuntu installation image

Ubuntu official website

Click Download

Click Get Ubuntu Desktop

Scroll down to download 22.04.3

As shown in the picture after downloading

3. Install Ubuntu system

Click to create a new virtual machine in VMware

Select Custom and click Next

Click next

Import Ubuntu and click Next

Fill it out

Click next

Click next

Click next

Click next

Click next

Click next

Click next

Click next

Click next

Click Finish

Enter VMware and select Start this virtual machine:

Choose whether to set the language to Simplified Chinese as needed. I will directly select English here, and then Install Ubuntu (install Ubuntu):

Kyeboard Layout (keyboard layout) defaults to:

Updates and other Software (updates and other software) Here, it is recommended to remove Download updates while installing ubuntu (download updates during installation) and install third-party software for graphics and wi-Fi hardware and additional media formats (for graphics and Wi-Fi hardware and additional media formats) Fi hardware and other media formats (install third-party software), you will not download a lot of content here, but you can avoid problems such as the browser not being able to open videos, pictures, etc. in the future years of use.

Because it is an installed virtual machine, just select Erase disk and install Ubuntu (erase disk and install Ubuntu) here.

Just choose China

Set computer name, password, etc.

After the installation is complete, click Restart:

enter the system

4. Install and configure mysql

Open in terminal

Install database

Enter the following in the terminal

# Install mysql
sudo apt upgrade & amp; & amp; sudo apt install mysql-server mysql-client libmysqlclient-dev
# Enter mysql
sudo mysql -u root
#Create user - configure it according to your needs
create user 'starry'@'%' identified by 'root';
#Give the new user full permissions
grant all on *.* to 'starry'@'%';

# Exit mysql
exit

# Set up mysql remote connection
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
# Change to
bind-address = 0.0.0.0
# Restart mysql service
sudo service mysql restart

Table creation

# Enter mysql
sudo mysql -u root
#Create database yourdb
create database yourdb;
# Use database yourdb
use yourdb;
#Create user table
CREATE TABLE user(
    username char(50) NULL,
    passwd char(50) NULL
)ENGINE=InnoDB;

# adding data
INSERT INTO user(username, passwd) VALUES('name', 'passwd');

Check mysql status

systemctl status mysql.service

You can use the following command to view the table and its contents:

 show databases; //You can view the current database
show users;
select *from user;

You need to enter the mysql environment first, and then use the above command

Enter mysql:

sudo mysql -uroot -p
5. Download the code, compile and run

Download to local

Click to copy link

Clone to local using git

# If you don’t have git, use the following command (if you have git, ignore this step)
sudo apt install git -y
# Execute the following command to clone the project locally
git clone https://github.com/qinguoyi/TinyWebServer.git

At this time, the TinyWebServer folder appears on the desktop

Enter the project, modify the main.cpp file configuration, and execute make

 cd Tinywebserver
 vi main.cpp
 make

First, you need to confirm that the database in main.cpp is the same as your mysql database configuration.
View database name and password

 cd /etc/mysql
sudo vim debian.cnf

Then open main.cpp and modify the corresponding configuration (click main.cpp directly in the TinyWebServer folder to modify)

Compile Tinywebserver (compile and run)

cd Tinywebserver
sh ./build.sh

Error encountered during compilation: fatal error: mysql.h: No such file or directory
Solution: Install the link library apt-get install libmysqlclient-dev

Error encountered while compiling: g++ Compiling: No such file or directory

Solution: install g++

sudo apt-get install g++ 

Run the executable file and access the project

# Run
./server
# Open the browser and visit
http://127.0.0.1:9006/

Open the browser in VMware, enter the URL and visit

At this point, the project runs successfully.