当前位置: 首页 > news >正文

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/nginxmkdir -p /usr/local/src/nginxcd /usr/local/src/nginxwget -c http://nginx.org/download/nginx-1.22.1.tar.gz

解压

tar -zxvf nginx-1.22.1.tar.gzcd /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,如果未创建成功,一般是因为缺失依赖包,根据提示安装依赖包。​​​​​​​

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

makemake 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 serverDocumentation=http://nginx.org/en/docs/After=network-online.target remote-fs.target nss-lookup.targetWants=network-online.target[Service]Type=forkingPIDFile=/var/run/nginx.pidExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s TERM $MAINPIDExecStartPost=/bin/sleep 0.1[Install]WantedBy=multi-user.target

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

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

会出现systemd[1]: 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 nginxsystemctl status nginx
http://www.lryc.cn/news/506639.html

相关文章:

  • linux CentOS系统上卸载docker
  • css中相对定位的应用场景
  • Android 获取屏幕物理尺寸
  • C缺陷与陷阱 — 8 编译与链接
  • 知识分享第三十天-力扣343.(整数拆分)
  • Springboot 整合DL4J 打造智能写作助手(文本生成)
  • SPL06 基于stm32F103 HAL库驱动(软件模拟IIC)
  • 【C#】List求并集、交集、差集
  • YOLOv8目标检测——详细记录使用ONNX Runtime进行推理部署C++/Python实现
  • mfc140u.dll是什么文件?如何解决mfc140u.dll丢失的相关问题
  • Redis篇-19--运维篇1-主从复制(主从复制,读写分离,配置实现,实战案例)
  • 【Elasticsearch入门到落地】4、Elasticsearch的安装
  • 计算无人机俯拍图像的地面采样距离(GSD)矩阵
  • 牛客网 SQL37查找多列排序
  • el-tabs标签过多
  • 如何制作搞笑配音视频?操作方法
  • [Unity]Unity跨平台开发之针对Android开发
  • ELK部署
  • ELK系列-(四)轻量级的日志收集助手-Beat家族
  • NodeJs-包管理工具
  • AWR microwave office 仿真学习(二)使用多层结构天线/超表面的S参数确定层间距
  • 【zlm】 webrtc源码讲解三(总结)
  • Springboot+Druid(可切换Hikari)+Mybatis-plus+mysql+hive的多数据源项目配置
  • Git使用步骤
  • Python+OpenCV系列:AI看图识人、识车、识万物
  • springboot449教学资源共享平台(论文+源码)_kaic
  • 类OCSP靶场-Kioptrix系列-Kioptrix Level 4
  • 贪心算法在背包问题上的运用(Python)
  • POD 存储、PV、PVC
  • C中strlen和sizeof的区别