-
Notifications
You must be signed in to change notification settings - Fork 62
linux 环境配置
#linux 环境配置
不知道怎么设置cmake,没有配出asio与boost asio 共存CMakeLists.txt
如果你安装了boost asio 那么需要指定独立的asio地址,把独立asio放到paozhu项目下面,后面讲这么拷贝。 框架目录下有一个asio.zip压缩包,新版兼容openssl3.0
vendor
view
asio
- asio.hpp
- asio
类似这样子
#安装 gcc
$ sudo apt update
$ sudo apt install build-essential
本文以ubuntu20.04 安装为蓝本,ubuntu22.04 应该默认是 gcc-11 ubuntu22可以跳过gcc11安装 所以直接 sudo apt install build-essential 可以安装好gcc-11
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt install -y gcc-11
sudo apt install -y g++-11
gcc-11 --version
g++-11 -v
可以不安装gcc-10 sudo apt install gcc-10 //可能没有gcc-11 sudo apt install g++-10
$ sudo apt-get install manpages-dev
$ sudo apt-get install libboost-dev //动态库用到 libboost-all-dev
$ sudo apt install libboost-filesystem-dev
$ sudo apt install git
$ sudo apt install cmake
如果是 Fedora 系统需要,这样才能编译上 -fsanitize=address
$ sudo yum install libasan
安装依赖库
sudo apt install brotli
sudo apt install libgd-dev
sudo apt install qrencode libqrencode-dev
sudo apt-get install openssl libssl-dev
也可以在框架根目录写一个测试文件testasio.cpp
$ g++ testasio.cpp
testasio.cpp
#include "asio/asio.hpp"
#include <iostream>
int main(){
std::cout<<ASIO_VERSION<<std::endl;
return 0;
}
应该输出,最好用asio 1.28以上 102800
安装mysql8
参考 https://zhuanlan.zhihu.com/p/262721133 https://naturetrible.blog.csdn.net/article/details/122030359
sudo apt-get install mysql-server
sudo apt-get install mysql-common
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
sudo service mysql status # 查看服务状态
sudo service mysql start # 启动服务
sudo service mysql stop # 停止服务
sudo service mysql restart # 重启服务
$ sudo service mysql status
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-06-29 19:57:13 CST; 2min 23s ago
Main PID: 22401 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 8745)
Memory: 359.0M
CGroup: /system.slice/mysql.service
└─22401 /usr/sbin/mysqld
6月 29 19:57:11 hzq-Default-string systemd[1]: Starting MySQL Community Server...
6月 29 19:57:13 hzq-Default-string systemd[1]: Started MySQL Community Server.
查看密码 List first password
$ sudo cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = 5hiIbvxR2DgC7ekz
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = 5hiIbvxR2DgC7ekz
socket = /var/run/mysqld/mysqld.sock
登陆加root密码
mysql -u debian-sys-maint -p
创建root用户
create user 'root'@'%' identified by '12345678';
授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
刷新权限 FLUSH PRIVILEGES
修改密码,注意如果是生产环境不要用12345678
ALTER user 'root'@'localhost' IDENTIFIED BY '12345678';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '12345678';
我们去验证是不是设置上密码了
选择mysql库看一有用户
use mysql;
select host,user,authentication_string from user;
+-----------+------------------+------------------------------------------------------------------------+
| host | user | authentication_string |
+-----------+------------------+------------------------------------------------------------------------+
| % | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | debian-sys-maint | $A$005$*HO7jVD!i#
g4FuU2y95DdV87pa2WisukPk4JCFhEZ5R2zEnFWMzrc3e. |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+-----------+------------------+------------------------------------------------------------------------+
如果可以我们退出
mysql -u root -p 输入12345678 可以登陆了
如果是系统 Fedora38 数据库是 MariaDB 直接用root权限进去改密码
# systemctl start mariadb
# systemctl enable mariadb
# systemctl status mariadb
# sudo mysql -u root -p
我们写一个测试文件验证下
g++ mysqltest.cpp -std=c++20 -I/usr/include/mysql -lmysqlclient
mysqltest.cpp
#include <memory>
#include <iostream>
#include "mysql.h"
using std::cout;
using std::endl;
int main() {
// 默认的安装方式端口是3306
std::unique_ptr<MYSQL, decltype(&mysql_close)> conn(new MYSQL, &mysql_close);
mysql_init(conn.get());
if(!mysql_real_connect(conn.get(),"127.0.0.1","root","12345678","mysql",3306,NULL,0))
{
std::cout<<"mysql db link error!"<<std::endl;
std::cout<<mysql_error(conn.get())<<std::endl;
}
cout <<"Done!" <<endl;
}
现在已经安装完成所有需要基础软件
如果需要CRUD演示,还要导入conf目录下几个sql文件,参考ORM入门文章,可以稍后导入,接着继续往下。
asio1.22.1已经兼容openssl3了,所以ubuntu22.04 安装基础软件包应该没有那么困难,直接apt-get 安装就可以了
编译paozhu c++ web framework 框架 进入框架目录
mkdir build
cd build
cmake ..
如果没有相应的包,去安装相应的包
make
配置服务器 conf 目录
server.conf 文件 把里面的路径配置成你的路径
然后回到 框架目录 运行
sudo ./bin/paozhu
需要80 等端口 必须管理员权限运行,打开浏览localhost可以看到也页面了。
============================================
到此你已经配置完毕,如果你想php后端可以往下设置。
##php-fpm 主要和配置##
sudo apt install php-fpm php php-gd
sudo systemctl restart php8.1-fpm
修改 /etc/php/8.1/pool.d/www.conf
listen = 127.0.0.1:9000
user = 你用户名
group =你的组
netstat -an 看看有没有9000端口
编辑paozhu conf/server.conf文件
isuse_php=1
rewrite_php=/Users/hzq/Documents/www/thinkphp/public|index.php
fastcgi_host=127.0.0.1
fastcgi_port=9000
查看状态
sudo systemctl status php8.1-fpm
1 access denied 权限问题
使用chown -R 你用户名:你的组 目录
php.ini文件中
cgi.fix_pathinfo=1:将0 改为 1
2 File not found 或 Primary script unknown
php-fpm.conf 中的配置用户名
user = 你用户名
group =你的组