本文以nginx 1.8和php 7.2为例,详细讲解手动安装过程。
一、Nginx安装
- 安装依赖包:
yum -y install gcc gcc-c++ autoconf automake make zlib zlib-devel openssl openssl-devel pcre pcre-devel
- 下载Nginx: 从Nginx官网 (https://www.php.cn/link/06b44f22bf01b4bad31391ffe00009c4) 下载您需要的版本。
- 解压并安装:
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
- 启动Nginx:
cd /usr/local/nginx ./sbin/nginx
- 将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
保存后执行:
systemctl start nginx.service systemctl enable nginx.service
- 验证安装:
ps -ef | grep nginx
二、PHP安装
- 安装依赖包:
yum install -y gcc gcc-c++ libxml2-devel openssl-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel openldap-devel freetype freetype-devel
-
下载PHP: 从PHP官网 (https://www.php.cn/link/4ea01965a7b1b4359cdabed6e3e6936b) 下载PHP 7.2.10 (或您需要的版本)。
-
解压并安装:
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
- 验证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环境的详细内容,更多请关注知识资源分享宝库其它相关文章!
版权声明
本站内容来源于互联网搬运,
仅限用于小范围内传播学习,请在下载后24小时内删除,
如果有侵权内容、不妥之处,请第一时间联系我们删除。敬请谅解!
E-mail:dpw1001@163.com
发表评论