帮助中心

这里有最新的使用文档和教程

< 返回

Centos7 手动安装nginx+php环境

2022-11-05 13:32 作者:31IDC 阅读量:527 所属分类:Linux系统

我们以安装nginx1.8+php7.2版本为例进行手动安装,具体安装流程如下:

一、Nginx安装:

1、安装相关依赖包

yum -y install gcc gcc-c++ autoconf automake make

yum -y install zlib zlib-devel openssl 

yum -yinstallopenssl-devel pcre pcre-devel

2、下载nginx安装包,也可以到nginx官网找到你想要安装的版本进行下载

nginx官网下载:http://nginx.org/download/

1)进入目录: cd /usr/local

2)下载文件: wget http://nginx.org/download/nginx-1.8.0.tar.gz

3)解压文件: tar -zxvf nginx-1.8.0.tar.gz

4)进入解压后目录: cd nginx-1.8.0

5)执行命令编译安装:

. /configure 

make && make install

3,安装完成之后在/usr/local文件夹下面会多出一个nginx的文件夹

1)进入/usr/local/nginx 目录下:

cd /usr/local/nginx

2)执行 ./sbin/nginx   #启动nginx服务

4,将nginx 加入服务项

1)创建服务文件:

vi /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

 

:wq    #保存退出

5,测试启动服务

systemctl start nginx.service

6,查看是否启动

ps -ef | grep nginx

7,设置开机自启动

systemctl enable nginx.service

到此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

2,进入到/usr/local目录下,下载php安装包:

cd /usr/local

wget http://tz1.php.net/distributions/php-7.2.10.tar.gz

也可以进入到php官网去下载:http://php.net/downloads.php

3,解压

tar -zxvf php-7.2.10.tar.gz

4,进入解压出来的php目录

cd php

注:如果解压出来的不是php目录,可以改名,比如解压出来的目录为php-7.2 ,需要执行mv php-7.2 php ,修改成php

5,编译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

6,安装php:

make && make install

7,安装完成后可以通过php -v 可看php是否安装成功。

8,如果php -v 无法执行,可以将php加入到环境变量:

编辑环境变量文件: vi /etc/profile

文件末尾加上 export PATH="/usr/local/php/bin:$PATH"

其中"/usr/local/php/bin"为你安装的具体路径,保存退出后,执行以下更改即可,执行命令:

source /etc/profile

这个时候我们再次执行php -v 就可以看到所安装的版本号了。

 

到此安装完成。

31IDC - 12 年深耕海外 IDC 高端资源