php官網:https://www.php.net
進入官網后點擊downloads選擇需要下載的版本即可

本文以php 7.3.10版本為例
安裝包存放路徑 /usr/local/src/

下載:

[root@linux src]# wget https://www.php.net/distributions/php-7.3.10.tar.bz2

解壓:

[root@linux src]# tar -jxvf php-7.3.10.tar.bz2

編譯安裝:
進入目錄 cd php-7.3.10.tar.bz2

配置編譯參數:
./configure –prefix=/usr/local/php-fpm –with-config-file-path=/usr/local/php-fpm/etc –enable-fpm –with-fpm-user=php-fpm –with-fpm-group=php-fpm –with-mysql=/usr/local/Mysql –with-MYSQLi=/usr/local/mysql/bin/mysql_config –with-pdo-mysql=/usr/local/mysql –with-mysql-sock=/tmp/mysql.sock –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-ftp –enable-mbstring –enable-exif –with-pear –with-curl –with-openssl

編譯: make

安裝:make install

拷貝配置文件php.ini-development到php程序安裝目錄:

[root@linux php-7.3.10]# cp php.ini-development /usr/local/php-fpm/etc/php.ini

拷貝啟動腳本到/etc/init.d/目錄:

[root@linux php-7.3.10]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

進入php安裝目錄下的/etc目錄重命名配置文件:

[root@linux php-7.3.10]# cd /usr/local/php-fpm/etc/
[root@linux etc]# cp php-fpm.conf.default php-fpm.conf
[root@linux etc]# cd php-fpm.d/
[root@linux php-fpm.d]# cp www.conf.default www.conf

添加php啟動腳本到系統服務:

[root@linux php-fpm.d]# chkconfig --add php-fpm
[root@linux php-fpm.d]# chkconfig php-fpm on
[root@linux php-fpm.d]# chmod 755 /etc/init.d/php-fpm

創建php用戶:

[root@linux php-fpm.d]# useradd php-fpm

啟動php:

[root@linux php-fpm.d]# service php-fpm start

編譯安裝php報錯解決方法:

報錯1:checking for gcc… no
解決:yum -y install gcc

報錯2:error: libxml2 not found
解決:yum install -y libxml2-devel

報錯3:error: Cannot find OpenSSL\\\’s
解決:yum install -y openssl-devel

報錯4:error: cURL version 7.15.5 or later is required
解決:yum install -y libcurl-devel

報錯5:configure: error: jpeglib.h not found
解決:yum install -y libjpeg-turbo-devel

報錯6:configure: error: png.h not found
解決:yum install -y libpng-devel

報錯7:configure: error: freetype-config not found
解決:yum install -y freetype-devel

報錯8:configure: error: wrong mysql library version or lib not found

該錯誤表示當前安裝的MySQL/MariaDB版本過高,下載個低版本的MySQL包將編譯參數含有MySQL/MariaDB的路徑改為低版本MySQL程序目錄即可,無需安裝低版本MySQL

解決:
1.下載MySQL5.6二進制包:

[root@linux ~]# cd /usr/local/src/
[root@linux src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz

2.解壓:

[root@linux src]# tar -zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz 

3.移動到/usr/local/目錄下重命名為mysql5.6:

[root@linux src]# mv mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz /usr/local/mysql5.6

4.更改編譯參數中 – -with-mysql,- -with-mysqli,- -with-pdo-mysql指向的路徑為MySQL5.6目錄:
./configure –prefix=/usr/local/php-fpm –with-config-file-path=/usr/local/php-fpm/etc –enable-fpm –with-fpm-user=php-fpm –with-fpm-group=php-fpm –with-mysql=/usr/local/mysql5.6 –with-mysqli=/usr/local/mysql5.6/bin/mysql_config –with-pdo-mysql=/usr/local/mysql5.6 –with-mysql-sock=/tmp/mysql.sock –with-libxml-dir –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv-dir –with-zlib-dir –with-mcrypt –enable-soap –enable-gd-native-ttf –enable-ftp –enable-mbstring –enable-exif –with-pear –with-curl –with-openssl

報錯9:ERROR: [pool www] cannot get uid for user \\\’php-fpm\\\’
創建編譯參數中指定的php用戶即可
解決:useradd php-fpm


nginx官網:http://nginx.org/

編譯安裝nginx:

安裝包存放路徑/usr/local/src

下載:

[root@linux src]# wget http://nginx.org/download/nginx-1.16.1.tar.gz

解壓:

[root@linux src]# tar -zxvf nginx-1.16.1.tar.gz 

進入nginx源碼包目錄:

[root@linux src]# cd nginx-1.16.1/

配置編譯參數:

[root@linux nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module

編譯安裝:

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

啟動nginx:

[root@linux ~]# /usr/local/nginx/sbin/nginx 
[root@linux ~]# netstat -lntp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      11494/nginx: master

補充:
如果不想使用絕對路徑啟動nginx,可以將nginx啟動腳本軟連接到環境變量目錄下:

[root@linux ~]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

啟動nginx:

[root@linux ~]# nginx 
[root@linux ~]# ps -ef|grep nginx
root     11580     1  0 21:58 ?        00:00:00 nginx: master process nginx
nobody   11581 11580  0 21:58 ?        00:00:00 nginx: worker process
root     11584  7705  0 21:59 pts/0    00:00:00 grep --color=auto nginx

關閉nginx:

[root@linux ~]# nginx -s stop

yum安裝nginx:

官方說明:http://nginx.org/en/linux_packages.html

配置nginx倉庫:

[root@linux ~]# vi /etc/yum.repos.d/nginx.repo

添加以下內容:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

yum安裝nginx:

[root@linux ~]# yum -y install nginx

配置文件路徑:

[root@linux ~]# ls /etc/nginx/
conf.d          koi-utf  mime.types  nginx.conf   uwsgi_params
fastcgi_params  koi-win  modules     scgi_params  win-utf

啟動腳本路徑:

[root@linux ~]# which nginx
/usr/sbin/nginx

啟動nginx:

[root@linux ~]# systemctl start nginx
[root@linux ~]# ps -ef|grep nginx
root     12410     1  0 22:42 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/ngin/nginx.conf
nginx    12411 12410  0 22:42 ?        00:00:00 nginx: worker process
root     12413  7705  0 22:42 pts/0    00:00:00 grep --color=auto nginx

關閉nginx:

[root@linux ~]# systemctl stop nginx

通過修改nginx配置文件配置nginx虛擬主機,一臺nginx服務器(web服務器)可以通過虛擬主機配置多個站點

配置單個虛擬主機:

編輯nginx虛擬主機配置文件,由于上一篇文章使用的是yum安裝的nginx,所以nginx虛擬主機配置文件路徑為:/etc/nginx/conf.d/default.conf

編輯配置文件:

[root@linux ~]# vi /etc/nginx/conf.d/default.conf 

定義server_name項對應的站點域名

驗證配置文件:

[root@linux ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

重新加載nginx使其生效:

[root@linux ~]# nginx -s reload

由于www.test.com為測試使用的自定義域名,并不能解析到測試的nginx服務器,需要修改Windows配置文件hosts:

打開配置文件:C:\\\\Windows\\\\System32\\\\drivers\\\\etc\\\\hosts

添加web服務器地址和對應的域名

在瀏覽器訪問www.test.com即可:

配置多個虛擬主機:

拷貝虛擬主機配置文件:

[root@linux ~]# cd /etc/nginx/conf.d/
[root@linux conf.d]# ls
default.conf
[root@linux conf.d]# cp default.conf testbaidu.conf

#虛擬主機文件命名為需要配置的域名便于維護

編輯文件:

[root@linux conf.d]# vi testbaidu.conf 

定義server_name項對應的站點域名和root項對應的站點目錄:

驗證并重載nginx:

[root@linux ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@linux ~]# nginx -s reload

創建站點對應目錄以及index.html文件:

[root@linux conf.d]# mkdir -p /tmp/testbaidu
[root@linux conf.d]# touch /tmp/testbaidu/index.html
[root@linux conf.d]# echo nginx_test > $?

修改Windows系統host文件:

訪問www.testbaidu.com即可:

默認虛擬主機:

默認虛擬主機的作用就是:如果有多個訪問的域名指向這臺web服務器,但某個域名未添加到nginx虛擬主機中,就會訪問默認虛擬主機(泛解析)

查看虛擬主機配置文件目錄:/etc/nginx/conf.d/

[root@linux conf.d]# ls
default.conf  testbaidu.conf

#當該目錄中存在多個虛擬主機配置文件時,排在最前面的就是默認虛擬主機

上文修改Windows系統hosts文件時,多添加了一個域名www.abc.com,該域名未配置虛擬主機,訪問就會訪問默認虛擬主機

測試:

#加載的結果為默認虛擬主機default.conf指向的頁面

設置testbaidu.conf為默認虛擬主機,編輯testbaidu.conf:

[root@linux conf.d]# vi testbaidu.conf 

在端口號后面添加default即可:

驗證并重啟nginx:

[root@linux conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@linux conf.d]# nginx -s reload

再次訪問www.abc.com:

#顯示結果為testbaidu.conf的虛擬主機頁面

禁用nginx默認虛擬主機:

#在默認虛擬主機配置文件中添加一行:deny all; 即可

禁用nginx默認虛擬主機后,訪問的域名如未在nginx虛擬主機配置文件server_name項定義的話就會提示403錯誤:

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:m.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » 編譯安裝php/nginx/nginx虛擬主機

登錄

找回密碼

注冊

主站蜘蛛池模板: 国产精品欧美福利久久| 成人午夜大片免费看爽爽爽| 成人精品色一区二区三区| 人人妻人人狠人人爽天天综合网| 无码人妻一区二区三区AV| 国产AV无码专区亚洲AV漫画| 国产成人亚洲精品自产在线| 亚洲中文字幕无码爆乳| 99久久国产综合精品成人影院| 69精品丰满人妻无码视频a片| 少妇愉情理伦片丰满丰满午夜| 人妻少妇偷人作爱av| 日本高清成本人视频一区| 97夜夜澡人人爽人人模人人喊| 色婷婷日日躁夜夜躁| 亚洲午夜香蕉久久精品| 亚洲日韩图片专区第1页| 营口市| 国产成人精品2021欧美日韩| 亚洲激情视频一区二区三区| 久久精品国产亚洲夜色AV网站| 国产又色又爽又黄刺激视频 | 五月国产综合视频在线观看| 中文字幕无码免费久久99| 札达县| 亚洲这里只有久热精品伊人| 日韩乱码人妻无码中文字幕视频 | 欧美人与性动交ccoo| 国产区精品福利在线熟女| 国产精品三级爽片免费看| 永久免费在线观看蜜桃视频| 久久永久视频| 精品人妻码一区二区三区| 久久99久国产精品66| XXXXXHD亚洲日本HD| 国产乱码精品一区二区三| 卡一卡2卡3卡精品网站| 永城市| 国产乱对白刺激视频| 国产迷姦播放在线观看| 桐城市|