首页 > 系统教程 > LINUX > 正文

Centos7 手动安装nginx+php环境

舞夢輝影
发布: 2025-01-17 19:36:14
原创
1040人浏览过

本文以nginx 1.8和php 7.2为例,详细讲解手动安装过程。

一、Nginx安装

  1. 安装依赖包:
yum -y install gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre pcre-devel
登录后复制
  1. 下载Nginx: 从Nginx官网 (https://www.php.cn/link/06b44f22bf01b4bad31391ffe00009c4) 下载您需要的版本。

Centos7 手动安装nginx+php环境

  1. 解压并安装:
cd /usr/local
wget https://www.php.cn/link/06b44f22bf01b4bad31391ffe00009c4nginx-1.8.0.tar.gz  # 请替换为您的下载链接
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure
make && make install
登录后复制
  1. 启动Nginx:
cd /usr/local/nginx
./sbin/nginx
登录后复制
  1. 将Nginx添加到系统服务:

创建文件 /usr/lib/systemd/system/nginx.service,并写入以下内容:

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
登录后复制

保存后执行:

立即学习PHP免费学习笔记(深入)”;

systemctl start nginx.service
systemctl enable nginx.service
登录后复制
  1. 验证安装:
ps -ef | grep nginx
登录后复制

二、PHP安装

  1. 安装依赖包:
yum install -y gcc gcc-c++ libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel freetype freetype-devel
登录后复制
  1. 下载PHP: 从PHP官网 (https://www.php.cn/link/4ea01965a7b1b4359cdabed6e3e6936b) 下载PHP 7.2.10 (或您需要的版本)。

  2. 解压并安装:

cd /usr/local
wget http://tz1.php.net/distributions/php-7.2.10.tar.gz # 请替换为您的下载链接
tar -zxvf php-7.2.10.tar.gz
cd php  # 如果解压后目录名不同,请调整
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql --enable-maintainer-zts -with-mcrypt=/usr/include --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-ftp --enable-session --with-gettext --with-jpeg-dir --with-freetype-dir --enable-fastcgi --without-gdbm --disable-fileinfo
make && make install
登录后复制
  1. 验证PHP安装:
php -v
登录后复制

如果 php -v 命令无法执行,请将PHP添加到环境变量 /etc/profile 文件中,添加 export PATH="/usr/local/php/bin:$PATH" (替换 /usr/local/php/bin 为您的实际路径),然后执行 source /etc/profile。

完成以上步骤后,Nginx和PHP 7.2就安装完成了。 请根据您的实际情况调整路径和版本号。

以上就是Centos7 手动安装nginx+php环境的详细内容,更多请关注php中文网其它相关文章!

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号