linux 安裝 nginx+PHP+mysql之安裝nginx

linux 安裝 nginx+PHP+mysql之安裝nginx

1.安裝前的準(zhǔn)備需要安裝 gcc gcc-c++

命令 yum install gcc gcc-c++

2.安裝nginx首先需要下載nginx文件

http://nginx.org/en/download.html

使用ftp命令上傳 或者安裝了lrzsz的可以使用rz命令進(jìn)行上傳

上傳存放路徑 /home/

首先需要設(shè)置一個(gè)用戶組,并在這個(gè)用戶組下邊添加一個(gè)用戶,并且這個(gè)用戶不允許登錄

[root@localhost home]# groupadd www

[root@localhost home]# useradd -g www www -M -s /sbin/nologin

執(zhí)行完成之后輸入以下命令檢查是否添加成功

[root@localhost home]# cat /etc/passwd

在最后一行中出現(xiàn)

www:x:501:501::/home/www:/sbin/nologin

即為創(chuàng)建成功

接下來進(jìn)行安裝nginx

?將剛剛上傳的壓縮文件進(jìn)行解壓

[root@localhost home]# tar xf nginx-1.16.1.tar.gz

解壓完成后 會(huì)出現(xiàn) nginx-1.16.1 這個(gè)目錄

?進(jìn)入到這個(gè)目錄

接下來就是進(jìn)行編譯nginx

--prefix=/usr/local/nginx 存放路徑

--user=www --group=www 用戶和用戶組

--with-http_ssl_module 添加ssl

--with-http_gzip_static_module 添加 gzip

--with-pcre 添加pcre

缺少什么設(shè)置什么

[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --with-pcre

執(zhí)行上邊這段后會(huì)報(bào)如下錯(cuò)誤

./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre=option.

這個(gè)原因是缺少 PCRE庫(kù) 只需要添加上就可以了

直接執(zhí)行

[root@localhost nginx-1.16.1]# yum install pcre-devel -y

再執(zhí)行[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --with-pcre

又會(huì)出現(xiàn)如下錯(cuò)誤

./configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using --with-openssl= option.

這個(gè)是因?yàn)槿鄙賝penssl庫(kù) 同樣

直接執(zhí)行 [root@localhost nginx-1.16.1]# yum install openssl-devel -y

再執(zhí)行 [root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --with-pcre

執(zhí)行完成之后安裝nginx成功

然后再執(zhí)行

[root@localhost nginx-1.16.1]# make && make install

等待最多一分鐘之后安裝完成

然后進(jìn)入/usr/local/nginx/sbin

執(zhí)行命令開啟nginx

?[root@localhost sbin]# ./nginx

未報(bào)錯(cuò)則開啟成功

查看是否開啟成功

[root@localhost sbin]# ps -ef| grep nginx

出現(xiàn)如下則開啟成功

root 17602 1 0 02:31 ? 00:00:00

nginx: master process

./nginx www 17603 17602 0 02:31 ? 00:00:00

nginx: worker process root 17606 11015 0 02:32 pts/0 00:00:00 grep

nginx 查看端口號(hào)命令

[root@localhost sbin]# netstat -nltp

這個(gè)時(shí)候可以在瀏覽器中輸入ip進(jìn)行訪問nginx了

?但是會(huì)出現(xiàn)訪問不到的情況,這個(gè)時(shí)候就需要關(guān)閉防火墻試一下

[root@localhost sbin]# /etc/init.d/iptables stop

?iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ]

這個(gè)時(shí)候再訪問ip 就可以訪問到了!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容