当前位置: 首页  >> 行业资讯  >> 帮助支持  >> 查看详情

Centos7 手动安装nginx+php环境

2024-03-12 11:08:50


我们以安装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 就可以看到所安装的版本号了。

到此安装完成。

XIDC作为一家专业的服务器提供商,我们自豪地为您提供香港、美国、日本、韩国、新加坡和台湾等地的服务器接入服务。这些服务器已经成功接入了CN2线路,确保您能够享受到稳定高速的网络连接。

为了满足不同行业客户的需求,我们提供了多样化的配置选择。无论您是个人用户还是企业客户,我们都能为您提供最适合的解决方案。我们的服务器配置涵盖了各种需求,从个人博客到大型企业应用,都能得到满足。

除了优质的服务器接入服务,我们还致力于提供优质的售后服务。我们拥有一支专业的技术团队,他们将全力保障您的服务器稳定运行和数据安全。无论是系统故障还是网络问题,我们都将及时响应并提供解决方案。

为了让您更加放心,我们还提供真机测试服务。如果您对我们的服务器不满意,我们将不收取任何费用。我们相信,只有您满意才是我们最大的成功。

欢迎您访问我们的官网: https://www.xidc.xyz ,了解更多关于我们服务器的信息。无论您是寻找稳定高速的网络连接,还是需要专业的技术支持,XIDC都将是您的最佳选择。让我们携手共创美好未来!

申请测试TG: @AmmKiss