!
也想出现在这里? 联系我们
广告位
当前位置:首页>教程分享>服务器教程>Centos7 手动安装nginx+php环境

Centos7 手动安装nginx+php环境

我们以安装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/

Centos7 手动安装nginx+php环境

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的文件夹

执行 ./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加入到环境变量:

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

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

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

source /etc/profile

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

 

到此安装完成。

给TA打赏
共{{data.count}}人
人已打赏
服务器教程

IIS7.5:未在本地计算机上注册“Microsoft.Jet.OleDb.4.0”提供程序解决办法

2021-4-17 19:15:43

服务器教程

Windows系统重新注册 .NET 4.0

2021-4-17 19:15:45

声明 本站上的部份代码及教程来源于互联网,仅供网友学习交流,若您喜欢本文可附上原文链接随意转载。无意侵害您的权益,请发送邮件至 [email protected] 或点击右侧 私信:吉吉国王 反馈,我们将尽快处理。
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索
OneEase