首页
关于
友链
留言
统计
Search
1
基于Rocky Linux 8.10系统使用源码搭建LNMP环境,附加安装SQLite
237 阅读
2
阿里云轻量应用服务器图文安装红帽系统RHEL8.10
59 阅读
3
.NET Framework
45 阅读
4
博客测试文章
18 阅读
5
基于LNMP环境搭建Typecho博客
17 阅读
软件整理
C/C++学习笔记
Linux学习笔记
博客搭建
杂项
Search
标签搜索
Nginx
测试
LNMP
Typecho
红帽系统
Alpine Linux
GRUB
windows
PowerShell
MySQL
SQLite
PHP
Rocky Linux
HTTPS
SSL
Let's Encrypt
GDB
hansyee
累计撰写
100
篇文章
累计收到
2
条评论
首页
栏目
软件整理
C/C++学习笔记
Linux学习笔记
博客搭建
杂项
页面
关于
友链
留言
统计
搜索到
1
篇与
的结果
2024-08-06
基于Rocky Linux 8.10系统使用源码搭建LNMP环境,附加安装SQLite
1. 环境说明 标识 说明 相关链接 L Rocky Linux x86_64 官方网站下载页面8.10 DVD版镜像下载地址8.10 Boot版镜像下载地址8.10 Mininal版镜像下载地址 N Nginx 官方网站下载页面1.26.1下载地址 M MySQL x86_64 官方网站社区版下载页面8.0.39下载地址8.4.2LTS下载地址 P PHP 官方网站7.4.33下载地址8.2.22下载地址 S SQLite 官方网站下载页面3.46.0下载地址 2. Rocky Linux 此处使用 Rocky-8.10-x86_64-boot.iso 镜像进行网络安装,这样可同步软件仓库安装最新版本。 国内镜像下载地址:mirrors.ustc.edu.cn Rocky-8.10-x86_64-boot.iso 2.1. 虚拟机安装过程演示 安装系统启动界面 选择安装界面语言 安装位置 Installation Destination 网络配置 Network & Host Name 软件安装源 Installation Source 选择 https,输入 mirrors.ustc.edu.cn/rocky/8.10/BaseOS/x86_64/os 软件选择 Software Selection 语言支持 Language Support 时间 Time & Date 设置root用户密码 Root Password 安装信息汇总 Installation Summary 开始安装 Begin Installation 完成安装 2.2. 系统简单配置 添加 devuser 用户,并自动创建家目录 /home/devuser,这里可以按各自喜好自定义用户名,不推荐直接使用 root 用户操作命令 useradd devuser -m -s /bin/bash 修改密码 passwd devuser 添加到用户组 wheel 以便后续使用 sudo 命令来执行一些需要管理员权限的命令 usermod -aG wheel devuser 注:后续操作登录到用户 devuser 执行,需要管理员权限的命令使用 sudo 执行 配置 EPEL 软件仓库 sudo dnf config-manager --set-enabled powertools sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm 安装基本开发工具 sudo dnf install gcc gcc-c++ gdb make cmake automake autoconf perl perl-devel python36 python36-devel git vim 创建工作区目录 mkdir -p /home/devuser/workspace/lnmp 3. Nginx 3.1. 安装 下载 wget -P /home/devuser/workspace/lnmp/ https://nginx.org/download/nginx-1.26.1.tar.gz 解压 tar -xf /home/devuser/workspace/lnmp/nginx-1.26.1.tar.gz -C /home/devuser/workspace/lnmp/ 安装依赖包 sudo dnf install pcre pcre-utf16 pcre-utf32 pcre-devel \ pcre2 pcre2-utf16 pcre2-utf32 pcre2-devel openssl openssl-devel \ libxml2 libxml2-devel libxslt libxslt-devel gd gd-devel \ GeoIP GeoIP-devel gperftools gperftools-devel \ libatomic_ops libatomic_ops-devel 编译配置 cd /home/devuser/workspace/lnmp/nginx-1.26.1/ ./configure --prefix=/usr/local/nginx --builddir=build-out \ --user=www-data --group=www-data \ --with-select_module --with-poll_module --with-threads --with-file-aio \ --with-http_ssl_module --with-http_v2_module --with-http_v3_module \ --with-http_realip_module --with-http_addition_module \ --with-http_xslt_module=dynamic \ --with-http_image_filter_module=dynamic \ --with-http_geoip_module=dynamic \ --with-http_sub_module --with-http_dav_module --with-http_flv_module \ --with-http_mp4_module --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_auth_request_module --with-http_random_index_module \ --with-http_secure_link_module --with-http_degradation_module \ --with-http_slice_module --with-http_stub_status_module \ --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module \ --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module \ --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module \ --with-google_perftools_module --with-cpp_test_module \ --with-compat --with-pcre --with-libatomic 编译 make 安装 sudo make install 3.2. 配置 添加 www-data 用户 sudo useradd www-data -M -s /sbin/nologin 创建虚拟主机配置文件夹,便于分别管理 sudo mkdir /usr/local/nginx/conf/vhosts 编辑 nginx 主配置文件 sudo vi /usr/local/nginx/conf/nginx.conf 修改内容如下 user www-data www-data; worker_processes auto; error_log /usr/local/nginx/logs/error.log; #error_log /usr/local/nginx/logs/error.log notice; #error_log /usr/local/nginx/logs/error.log info; pid /usr/local/nginx/logs/nginx.pid; events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; log_format main '
r
e
m
o
t
e
a
d
d
r
−
remote_user [
t
i
m
e
l
o
c
a
l
]
"
request" ' '
s
t
a
t
u
s
body_bytes_sent "
h
t
t
p
r
e
f
e
r
e
r
"
″
"
http_user_agent" "
Double subscripts: use braces to clarify
Double subscripts: use braces to clarify
PKG_CONFIG_PATH \ --with-libdir=lib64 编译 make -j4 编译测试 make test 安装 sudo make install 6.2. 配置 复制 php.ini 配置文件 sudo cp /home/devuser/workspace/lnmp/php-8.2.22/php.ini-development /usr/local/php/8.2.22/lib/php.ini 编辑 php.ini 配置文件 sudo vi /usr/local/php/8.2.22/lib/php.ini 以下参数按需修改 date.timezone = Asia/Shanghai upload_max_filesize = 10M post_max_size = 10M memory_limit = 256M include_path = ".:/usr/local/php/8.2.22/include:/usr/local/php/8.2.22/lib/php" disable_functions = passthru,exec,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server 复制 php-fpm 相关配置文件 sudo cp /usr/local/php/8.2.22/etc/php-fpm.conf.default /usr/local/php/8.2.22/etc/php-fpm.conf sudo cp /usr/local/php/8.2.22/etc/php-fpm.d/www.conf.default /usr/local/php/8.2.22/etc/php-fpm.d/www.conf 复制 systemd 脚本(启用 --with-fpm-systemd 参数后编译自动生成该脚本) sudo cp /home/devuser/workspace/lnmp/php-8.2.22/sapi/fpm/php-fpm.service /usr/lib/systemd/system/ 修改脚本 ProtectSystem 参数,否则后续无法启动 sudo vi /usr/lib/systemd/system/php-fpm.service 参数修改为如下 ProtectSystem=off 设置开机启动 sudo systemctl enable php-fpm.service 启动服务 sudo systemctl start php-fpm.service 7. 测试 编写测试网页 sudo vi /usr/local/nginx/html/test.php 内容如下 <?php phpinfo(); ?> 配置 nginx 以支持 php sudo cp /usr/local/nginx/conf/vhosts/defautl.conf /usr/local/nginx/conf/vhosts/defautl.conf.bak sudo vi /usr/local/nginx/conf/vhosts/defautl.conf 修改后的内容如下 server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php
You can't use 'macro parameter character #' in math mode
You can't use 'macro parameter character #' in math mode
{ root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME
d
o
c
u
m
e
n
t
r
o
o
t
fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} 重新加载 nginx 配置 sudo systemctl reload nginx 浏览器访问 http://192.168.31.84/test.php (需替换自己实际服务器ip)出现如下php页面即表示安装成功 8. 出现的问题及解决方法汇总 8.1. 编译类 8.1.1. nginx 问题1: checking for PCRE2 library ... not found checking for PCRE library ... not found checking for PCRE library in /usr/local/ ... not found checking for PCRE library in /usr/include/pcre/ ... not found checking for PCRE library in /usr/pkg/ ... not found checking for PCRE library in /opt/local/ ... not found checking for PCRE library in /opt/homebrew/ ... not found ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using --without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using --with-pcre=<path> option. 解决: sudo dnf install pcre pcre-utf16 pcre-utf32 pcre-devel pcre2 pcre2-utf16 pcre2-utf32 pcre2-devel 问题2: checking for OpenSSL library ... not found checking for OpenSSL library in /usr/local/ ... not found checking for OpenSSL library in /usr/pkg/ ... not found checking for OpenSSL library in /opt/local/ ... not found checking for OpenSSL library in /opt/homebrew/ ... not found ./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=<path> option. 解决: sudo dnf install openssl openssl-devel 问题3: checking for libxslt ... not found checking for libxslt in /usr/local/ ... not found checking for libxslt in /usr/pkg/ ... not found checking for libxslt in /opt/local/ ... not found ./configure: error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries. 解决: sudo dnf install libxml2 libxml2-devel libxslt libxslt-devel 问题4: checking for GD library ... not found checking for GD library in /usr/local/ ... not found checking for GD library in /usr/pkg/ ... not found checking for GD library in /opt/local/ ... not found checking for GD library in /opt/homebrew/ ... not found ./configure: error: the HTTP image filter module requires the GD library. You can either do not enable the module or install the libraries. 解决: sudo dnf install gd gd-devel 问题5: checking for GeoIP library ... not found checking for GeoIP library in /usr/local/ ... not found checking for GeoIP library in /usr/pkg/ ... not found checking for GeoIP library in /opt/local/ ... not found checking for GeoIP library in /opt/homebrew/ ... not found ./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library. 解决: sudo dnf install GeoIP GeoIP-devel 问题6: checking for Google perftools ... not found checking for Google perftools in /usr/local/ ... not found checking for Google perftools in /opt/local/ ... not found checking for Google perftools in /opt/homebrew/ ... not found ./configure: error: the Google perftools module requires the Google perftools library. You can either do not enable the module or install the library. 解决: sudo dnf install gperftools gperftools-devel 问题7: checking for atomic_ops library ... not found ./configure: error: libatomic_ops library was not found. 解决: sudo dnf install libatomic_ops libatomic_ops-devel 8.1.2. php 问题1: checking for libsystemd >= 209... no configure: error: Package requirements (libsystemd >= 209) were not met: Package 'libsystemd', required by 'virtual:world', not found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables SYSTEMD_CFLAGS and SYSTEMD_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. 解决: sudo dnf install systemd systemd-devel 问题2: checking for sqlite3 >= 3.7.7... no configure: error: Package requirements (sqlite3 >= 3.7.7) were not met: Package 'sqlite3', required by 'virtual:world', not found Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix. Alternatively, you may set the environment variables SQLITE_CFLAGS and SQLITE_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. 解决: 前面的 SQLite 编译后生成的库文件被指定安装在 /usr/local/lib64 目录下,在对 php 进行编译配置时可在 configure 执行的参数中加入 PKG_CONFIG_PATH 变量来包含该目录,这样 pkg-config 工具才会找到对应库文件的pc文件,形式如下: ./configure xxx \ xxx \ PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:
Missing open brace for subscript
Missing open brace for subscript
sudo systemctl start php-fpm.service [sudo] password for devuser: Job for php-fpm.service failed because the control process exited with error code. See "systemctl status php-fpm.service" and "journalctl -xe" for details. [devuser@linux php-8.2.22]$ 解决: 查看服务状态 systemctl status php-fpm.service 显示如下信息 ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Sun 2024-08-04 16:07:51 CST; 3min 27s ago Process: 591211 ExecStart=/usr/local/php/8.2.22/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/8.2.22/etc/php-fpm.conf (code=exited, status=78) Main PID: 591211 (code=exited, status=78) Aug 04 16:07:51 linux systemd[1]: Starting The PHP FastCGI Process Manager... Aug 04 16:07:51 linux php-fpm[591211]: [04-Aug-2024 16:07:51] ERROR: failed to open error_log (/usr/local/php/8.2.22/var/log/php-fpm.log): Read-only file system (30) Aug 04 16:07:51 linux php-fpm[591211]: [04-Aug-2024 16:07:51] ERROR: failed to post process the configuration Aug 04 16:07:51 linux php-fpm[591211]: [04-Aug-2024 16:07:51] ERROR: FPM initialization failed Aug 04 16:07:51 linux systemd[1]: php-fpm.service: Main process exited, code=exited, status=78/CONFIG Aug 04 16:07:51 linux systemd[1]: php-fpm.service: Failed with result 'exit-code'. Aug 04 16:07:51 linux systemd[1]: Failed to start The PHP FastCGI Process Manager. 其中关键字 Read-only file system 很特殊,大概率不是文件权限问题,经过查阅资料,发现这是编译生成的 systemd 脚本中一个参数值引起的,查看脚本可以看到如下信息 # Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit. ProtectSystem=full 看下该字段的解释,引用自https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#ProtectSystem= ProtectSystem= Takes a boolean argument or the special values "full" or "strict". If true, mounts the /usr/ and the boot loader directories (/boot and /efi) read-only for processes invoked by this unit. If set to "full", the /etc/ directory is mounted read-only, too. If set to "strict" the entire file system hierarchy is mounted read-only, except for the API file system subtrees /dev/, /proc/ and /sys/ (protect these directories using PrivateDevices=, ProtectKernelTunables=, ProtectControlGroups=). This setting ensures that any modification of the vendor-supplied operating system (and optionally its configuration, and local mounts) is prohibited for the service. It is recommended to enable this setting for all long-running services, unless they are involved with system updates or need to modify the operating system in other ways. If this option is used, ReadWritePaths= may be used to exclude specific directories from being made read-only. Similar, StateDirectory=, LogsDirectory=, … and related directory settings (see below) also exclude the specific directories from the effect of ProtectSystem=. This setting is implied if DynamicUser= is set. This setting cannot ensure protection in all cases. In general it has the same limitations as ReadOnlyPaths=, see below. Defaults to off. Added in version 214. 当设置为 full 时,php-fpm进程将 /usr、/boot、/etc 目录以只读模式挂载,所以此时出现了该问题,将其修改为 off 即可解决。 sudo vi /usr/lib/systemd/system/php-fpm.service 参数修改为如下 ProtectSystem=off 重新加载修改后的 systemd 脚本 sudo systemctl daemon-reload 重新启动 php-fpm 即可 sudo systemctl start php-fpm.service
2024年08月06日
237 阅读
0 评论
0 点赞