Linux system deployment ThinkPHP5+Workerman project

I wrote an article a while ago PHP obtains the K-line data of fire currency through URL and WebSocket , the development ...
Deployment environment
1, Modify yum source
2, Install Nginx, MySQL and PHP
3, Configuration
1, Upload project

I wrote an article a while ago PHP obtains the K-line data of fire currency through URL and WebSocket , the development and debugging of this project are completed under the Windows platform, and have not been run under the linux platform, so today we will start from scratch to deploy the corresponding environment on a new linux server, so that the project can run normally. Don't say much. Let's start to match it.

Deployment environment

The server is Tencent cloud, system CentOS 7.7, 1-core 2G. Installation environment: php7.2 + MySQL 5.7 + nginx1.16

1, Modify yum source

1. Update yum source

yum -y update

2. Download mysql source installation package

wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

3. Install mysql source

yum -y localinstall mysql57-community-release-el7-9.noarch.rpm

4. Check whether mysql source is installed successfully

yum repolist enabled | grep "mysql.*-community.*"

5. Modify PHP and Nginx installation yum source

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

Webtatic: https://webtatic.com
MySQL: https://dev.mysql.com/downloa...

2, Install Nginx, MySQL and PHP

yum -y install nginx yum -y install mysql-community-server yum -y install php72w-devel php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-pdo.x86_64 php72w-mysqlnd php72w-fpm php72w-opcache php72w-pecl-redis

3, Configuration

1. Configure MySQL
Start MySQL service

systemctl start mysqld

View the startup status of MySQL

systemctl status mysqld

Set boot up:

systemctl enable mysqld systemctl daemon-reload

After MySQL installation is completed, in / var/log/mysqld.log A default password is generated for root in the file
Find the root default password in the following way, and log in to MySQL to modify it:

grep 'temporary password' /var/log/mysqld.log # Find default password

Log in to MySQL and enter the default password found above:

mysql -uroot -p

To change the root default password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPass1!';

Or:

set password for 'root'@'localhost'=password('123abc');

Note:
MySQL 5.7 installed the password security check plug-in (validate) by default_ Password), the default password checking policy requires that the password must contain: uppercase and lowercase letters, numbers and special symbols, and the length cannot be less than 8 digits. Otherwise, error 1819 (HY000) will be prompted: your password does not satisfy the current policy requirements

For details, please refer to the MySQL official website password policy: https://dev.mysql.com/doc/ref...

Add remote login user
By default, only the root account is allowed to log in locally. If you want to connect mysql on other machines, you must modify the root account to allow remote connection, or add an account to allow remote connection

Add remote account (Please add carefully)

GRANT ALL PRIVILEGES ON *.* TO 'yourname'@'%' IDENTIFIED BY 'YourPassword@123' WITH GRANT OPTION;

Configure the default encoding as utf8:
Modify / etc/my.cnf Configuration files, vim /etc/my.cnf , add coding configuration under [mysqld], and restart after configuration:

[mysqld] character_set_server=utf8 init_connect='SET NAMES utf8'
systemctl restart mysqld # Restart MySQL


Default profile path:
Configuration file / etc/my.cnf
Log file / var/log/mysqld.log
Service startup script / usr/lib/systemd/system/mysqld.service
socket file / var/run/mysqld/mysqld.pid

2. Configure Nginx
After installation, check whether your firewall is enabled. If it is enabled, we need to modify the firewall configuration and enable the access to the external network port of Nginx.

systemctl status firewalld


If active (running) is displayed, you need to adjust the configuration of firewall rules.

Modify / etc/firewalld/zones/public.xml File, vim /etc/firewalld/zones/public.xml , added in the zone section
Reload firewalld service after saving:

<zone> ... <service name="nginx"/> <zone>
systemctl reload firewalld


To modify the Nginx configuration:

vim /etc/nginx/nginx.conf

In server {}, add:

location / { #Define the name of the home page index file index index.php index.html index.htm; } # All PHP script requests are forwarded to FastCGI for processing. Use FastCGI default configuration location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }


Restart Nginx after configuration:

systemctl start nginx # Start Nginx

Note: This article is just a simple configuration of Nginx. Please use Baidu for more details.

Set boot up:

systemctl enable nginx

3. Set the startup PHP FPM:

systemctl enable php-fpm systemctl start php-fpm # Start PHP FPM

4, Testing
Create a www directory at the root

cd / mkdir -p www

Change the root directory of nginx to / www

vim /etc/nginx/nginx.conf


Restart Nginx after configuration:

systemctl start nginx # Start Nginx

Create php file under / www / file and output phpinfo information

cd /www/
vim test.php
<?php echo phpinfo(); ?>
chmod -R 777 test.php

Browser access http: / / < Internet IP address >/ test.php , if you see PHP information, the installation is successful

At this point, the installation environment (php7.2 + MySQL 5.7 + nginx1.16) on the server has been completed. Now, start to deploy the project to the server.

Deploy project

1, Upload project

1. Server installation FTP
First, confirm whether vsftpd is installed on the server

rpm -qa | grep vsftpd

If not, enter the following command to install

yum -y install vsftpd

Installation successful

Modify the configuration file, vim /etc/vsftpd/vsftpd.conf , disable anonymous login

Set boot up:

systemctl enable vsftpd

Start vsftpd service

systemctl start vsftpd

View the startup status of vsftpd

systemctl status vsftpd

ftp server has been turned on, port 21 has been monitored

Configure vsftpd user and enable root user
Modify the configuration file, vim /etc/vsftpd/ftpusers, and comment out root

Modify the configuration file, vim /etc/vsftpd/user_list, comment out root

Restart vsftpd service

systemctl restart vsftpd

2. Upload project file
Create a new directory of huobiwebsocket under / www /

cd /www/ mkdir -p huobiwebsocket chmod -R 775 huobiwebsocket/

Log in to FTP (software FileZilla) with root's login password, locate at / www/huobiwebsocket /, and upload the code of local huobiwebsocket project to the server.
Modify the corresponding properties and permissions of the project file after the upload is successful

cd /www/huobiwebsocket/ chmod -R 775 *

3. Operation project
First, create a MySQL database huobiwebsocket and import the database file / www/huobiwebsocket/huobiwebsocket.sql

mysql -u root -p
CREATE DATABASE `huobiwebsocket` CHARACTER SET utf8 COLLATE utf8_general_ci; use huobiwebsocket source /www/huobiwebsocket/huobiwebsocket.sql

Enter the directory / www / hoobiwebsocket / and modify the database configuration file

cd /www/huobiwebsocket/ vim application/database.php

Modify the configuration related to the timing task of fire currency K line, vim application/cli/controller/TradeKlineHuobi.php

Start K-line timing task

php TradeKlineHuobi.php start

The timing task is started successfully. It has been connected to the WebSocket server (non fire Currency Server) of the external network and can receive the server push. You can also deploy the woobi WebSocket project on the Internet server, and set vim application/cli/controller/TradeKlineHuobi.php When the $flag variable in is changed to true, you can enable the connection to the fire coin WebSocket server (unable to connect in the intranet), so that you can accept the K-line push of the fire coin server. For details, please refer to huobiwebsocket Project code.

Here, the task is finished!!!
This time I'm deploying a pure CLI project. I'll write a WEB project about how to deploy ThinkPHP5. Please wait
If there is any mistake or unreasonable in the article, please leave a message for correction. Sorry for the bad writing!
Your "three company" is the biggest driving force of my brother's creation. See you next time!

17 June 2020, 23:39 | Views: 2822

Add new comment

For adding a comment, please log in
or create account

0 comments