CentOS7源码编译安装nginx+php+mysql

1.安装nginx

安装依赖

复制代码
yum -y install gcc gcc-c++ wget automake autoconf libtool libxml2-devel libxslt-devel perl-devel perl-ExtUtils-Embed pcre-devel openssl  openssl-devel

创建一个不能登录的nginx运行用户

复制代码
groupadd www-data
useradd -s /sbin/nologin -g www-data www-data

创建源码保存目录和运行时的临时文件夹,下载nginx源码,当前稳定版为nginx-1.22.1

复制代码
mkdir -p /var/cache/nginx

mkdir -p /usr/local/src/nginx

cd /usr/local/src/nginx

wget -c http://nginx.org/download/nginx-1.22.1.tar.gz

解压

复制代码
tar -zxvf nginx-1.22.1.tar.gz

cd /usr/local/src/nginx/nginx-1.22.1

编译前配置检查​​​​​​​

复制代码
./configure \

--prefix=/usr/local/nginx \

--sbin-path=/usr/local/nginx/sbin/nginx \

--conf-path=/usr/local/nginx/conf/nginx.conf \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--pid-path=/var/run/nginx.pid \

--lock-path=/var/run/nginx.lock \

--http-client-body-temp-path=/var/cache/nginx/client_temp \

--http-proxy-temp-path=/var/cache/nginx/proxy_temp \

--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \

--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \

--http-scgi-temp-path=/var/cache/nginx/scgi_temp \

--user=www-data \

--group=www-data \

--with-pcre \

--with-http_v2_module \

--with-http_ssl_module \

--with-http_realip_module \

--with-http_addition_module \

--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_random_index_module \

--with-http_secure_link_module \

--with-http_stub_status_module \

--with-http_auth_request_module \

--with-mail \

--with-mail_ssl_module \

--with-file-aio \

--with-http_v2_module \

--with-threads \

--with-stream \

--with-stream_ssl_module

配置检查完毕,查看是否创建了Makefile,如果未创建成功,一般是因为缺失依赖包,根据提示安装依赖包。​​​​​​​

编译,安装​​​​​​​

复制代码
make

make install

启动nginx

复制代码
/usr/local/nginx/sbin/nginx

查看进程

复制代码
ps aux|grep nginx

杀掉进程

复制代码
pkill -9 nginx

配置服务

复制代码
vim /usr/lib/systemd/system/nginx.service

输入如下配置​​​​​​​

复制代码
[Unit]

Description=nginx - high performance web server

Documentation=http://nginx.org/en/docs/

After=network-online.target remote-fs.target nss-lookup.target

Wants=network-online.target


[Service]

Type=forking

PIDFile=/var/run/nginx.pid

ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/bin/kill -s HUP $MAINPID

ExecStop=/bin/kill -s TERM $MAINPID

ExecStartPost=/bin/sleep 0.1


[Install]

WantedBy=multi-user.target

注意:如果你是单核服务器,需要加ExecStartPost=/bin/sleep 0.1

否则在执行systemctl start nginx之后,在执行systemctl status nginx时

会出现systemd1: Failed to read PID from file /var/run/nginx.pid: Invalid argument

这是因为nginx还未启动完成,systemctl就去寻找pid进程文件了,这是一个已知的bug

重新载入 systemd

复制代码
systemctl daemon-reload

开启开机启动

复制代码
systemctl enable nginx.service

启动和查看nginx状态

复制代码
systemctl start nginx

systemctl status nginx
相关推荐
梦梦代码精22 分钟前
基于ThinkPHP6 + Vue3的家政预约系统全解析:从LBS定位到自动派单的完整实现
java·docker·开源·php·代码规范
BelongPanda41 分钟前
Linux Nginx 纯手动 Let‘s Encrypt 泛域名证书配置教程
linux·nginx
郑州光合科技余经理1 小时前
家政O2O平台解析:从0搭建上门预约小程序解决方案
android·java·开发语言·前端·小程序·架构·php
lxw18449125142 小时前
PHP后端(CI框架方向)面试题库,分为基础必问、MySQL、Redis、工程运维、高阶加分、场景实操六大模块,适配该JD全部考点,附带标准答案
ci/cd·面试·php
Mico183 小时前
MySQL 8.0.35 基于GTID 主从复制安装增强半同步复制
android·mysql·adb
郝亚军11 小时前
nginx的三个基础库:PCRE、OpenSSL、Zlib的安装
linux·服务器·nginx
CodexDave14 小时前
MySQL事务隔离级别与MVCC机制解析
前端·数据库·mysql·nginx·性能优化·负载均衡
王琦031817 小时前
生产环境中使用通用二进制包安装
mysql
weixin_4080996718 小时前
2026 图片去水印 API 接口完全指南:一键去除图片水印(附 Python/Java/PHP/C# 示例)
java·python·php·图片处理·api调用·图片去水印·石榴智能
蓝田~20 小时前
MySQL慢查询怎么优化?B+Tree索引原理+MVCC读不阻塞写+EXPLAIN执行计划,从5秒到0.05秒
数据库·mysql