溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

如何編譯安裝nginx和php

發(fā)布時(shí)間:2022-12-27 13:41:30 來(lái)源:億速云 閱讀:108 作者:iii 欄目:編程語(yǔ)言

這篇文章主要介紹“如何編譯安裝nginx和php”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“如何編譯安裝nginx和php”文章能幫助大家解決問(wèn)題。

編譯安裝nginx和php的方法:1、通過(guò)yum install命令安裝依賴(lài)包;2、下載源碼包并解壓編譯;3、修改虛擬主機(jī)配置文件;4、啟動(dòng)nginx并配置systemctl啟動(dòng);5、下載php并解壓編譯即可。

nginx和php編譯安裝

nginx編譯安裝

安裝依賴(lài)包

yum install -y gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel

下載源碼包并解壓

[root@web03 ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
[root@web03 ~]# tar xf nginx-1.18.0.tar.gz
[root@web03 ~]# cd nginx-1.18.0/

編譯源碼

[root@web03 nginx-1.18.0]# ./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
[root@web03 nginx-1.18.0]#  make && make install
[root@web03 nginx-1.18.0]# cd /usr/local/nginx/
[root@web03 nginx]# tree
.
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html
│   ├── 50x.html
│   └── index.html
├── logs
└── sbin
    └── nginx

基本配置

[root@web03 nginx]# useradd -s /sbin/nologin -M www
[root@web03 conf]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
[root@web03 nginx]# mkdir conf/conf.d
# 拆分默認(rèn)配置和虛擬主機(jī)
user  www;
worker_processes  auto;
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    tcp_nopush     on;
    server_tokens off;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    gzip  on;
    include conf.d/*.conf;   
}
#虛擬主機(jī)配置文件
[root@web03 conf]# vim conf.d/www.conf
server {
    listen       80;
    server_name  localhost;
    charset utf-8;
    location / {
        root   html;
        index  index.html index.htm;
    }
    error_page  404              /404.html;
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
    location ~ \.php$ {
        proxy_pass   http://127.0.0.1;
    }
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME      
        $document_root$fastcgi_script_name;
        include        fastcgi_params;
        proxy_set_header   Referer           $http_referer;
        proxy_set_header   Cookie            $http_cookie;
        proxy_set_header   X-Real-IP         $remote_addr;
        proxy_set_header   X-Forwarded-For   
       $proxy_add_x_forwarded_for;
    }
}

啟動(dòng)nginx

nginx
nginx -s reload 重啟

配置systemctl啟動(dòng)

[root@web03 conf]# cat /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /usr/local/nginx/logs/nginx.pid 
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
[Install]
WantedBy=multi-user.target

php二進(jìn)制

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php71w

php編譯安裝

依賴(lài)包

源碼下載

[root@web03 ~]# wget http://hk1.php.net/get/php-7.2.33.tar.gz
[root@web03 ~]# tar xf php-7.2.33.tar.gz
[root@web03 ~]# cd php-7.2.33/

編譯

yum install bzip2 bzip2-devel -y
yum install  curl curl-devel -y
yum install php-mcrypt  libmcrypt  libmcrypt-devel -y
yum install readline-devel -y 
./configure --prefix=/usr/local/php7 --enable-fpm \
--with-zlib \
--enable-inline-optimization \
 --disable-debug \
--disable-rpath \
 --enable-shared \
--enable-opcache \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline 
make && make install

配置

ln -s /usr/local/php/bin/php /usr/bin/php
php -i | grep ini
Configuration File (php.ini) Path => /usr/local/php/lib
Scan this dir for additional .ini files => (none)
# 移動(dòng)php.ini, 從源碼拷貝
[root@web03 ~]# cp php-7.2.33/php.ini-production /usr/local/php/lib/php.ini
php -i | grep ini
Loaded Configuration File => /usr/local/php/lib/php.ini 已經(jīng)加載配置文件
# php-fpm
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
# 更改www.conf
sed -i 's#nobody#www#g' www.conf

system啟動(dòng)

[root@web03 conf]# cat /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -INT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 啟動(dòng)
[root@web03 etc]# systemctl daemon-reload
[root@web03 etc]# systemctl start php-fpm.service

測(cè)試nginx

[root@web03 sbin]# cd /usr/local/nginx/html/
[root@web03 html]# cat index.php 
<?php
phpinfo()
?>
systemctl restart nginx

測(cè)試mysql

<?php 
$link=mysql_connect("172.25.90.14","root","redhat"); 
if(!$link) echo "FAILD!連接錯(cuò)誤,用戶(hù)名密碼不對(duì)"; 
else echo "OK!可以連接"; 
?>

關(guān)于“如何編譯安裝nginx和php”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI