零起步3-CentOS7.6源碼編譯安裝php-7.3.6、nginx-1.17.0、phpMyAdmin-4.9.0.1

全新以最小化包安裝了64位的CentOS7.6系統,作爲本地的Web服務器使用,現記錄全過程

第三步,安裝php數據庫v7.3.6、nginx-1.17.0、phpMyAdmin-4.9.0.1

 

※ 知悉

1. 從php7.1開始,官方就開始建議用openssl_*系列函數代替Mcrypt_*系列的函數,所以以下參數應該在./configure中去除

--enable-gd-native-ttf --with-mcrypt

否則會報錯

configure: WARNING: unrecognized options: --enable-gd-native-ttf, --with-mcrypt

2. configure配置時,記得將--prefix=/usr/local/php/放置在./configure 的最後面,確保php被正確安裝在/usr/local/php目錄(切記)

3. php7.3.6編譯mysql參數時不要帶路徑,否則會報錯“致命錯誤:my_global.h:沒有那個文件或目錄”

    --with-pdo-mysql=/usr/local/mysql 改爲  --with-pdo-mysql

    --with-mysqli=/usr/local/mysql/bin/mysql_config 改爲 --with-mysqli

4. 編譯時會提示xslt-config not found,預先添加搜索路徑到配置文件

configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution

[root@localhost builder]# yum install libxslt libxslt-devel -y

configure: error: off_t undefined; check your library configuration

# 添加搜索路徑到配置文件

[root@localhost ~]# echo '/usr/local/lib64

                    /usr/local/lib

                    /usr/lib

                    /usr/lib64'>>/etc/ld.so.conf

# 更新配置

[root@localhost ~]# ldconfig -v

5. mysql8.0.11以後caching_sha2_password是默認的身份驗證插件,而不是以往的mysql_native_password,從而導致phpMyAdmin連接mysql時使用mysql_native_password報錯如下:

mysqli_real_connect(): The server requested authentication method unknown to the client  [caching_sha2_password]

兩個解決方案:

1) 修改mysql的登錄設置,將password改爲你數據庫的root密碼

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

2) 或者修改my.cnf,在[mysqld]中加入紅色字體內容

[mysqld]

default_authentication_plugin=mysql_native_password

 

準備工作1:

下載安裝包及相關依賴

[root@localhost ~]# wget https://www.php.net/distributions/php-7.3.6.tar.gz

[root@localhost ~]# wget http://nginx.org/download/nginx-1.17.0.tar.gz

[root@localhost ~]# wget https://nih.at/libzip/libzip-1.2.0.tar.gz

[root@localhost ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.43.tar.gz

[root@localhost ~]# wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.tar.gz

[root@localhost ~]# yum install bzip2 bzip2-devel curl curl-devel openssl \

        openssl-devel libjpeg libjpeg-devel libpng libpng-devel \

        freetype-devel libxslt libxslt-devel -y

安裝net-tools,以執行netstat、ifconfig、route等常用命令

[root@localhost ~]# yum install net-tools -y

 

準備工作2:PHP安裝zip拓展,解決以下安裝問題

1) 報錯:"libzip not found,Please reinstall the libzip distribution"

2) 報錯:zipconf.h:沒有那個文件或目錄(No such file or directory)

[root@localhost ~]# yum remove libzip -y

[root@localhost ~]# tar -zxvf libzip-1.2.0.tar.gz

[root@localhost ~]# cd libzip-1.2.0

[root@localhost libzip-1.2.0]# ./configure

[root@localhost libzip-1.2.0]# make && make install

[root@localhost libzip-1.2.0]# cd ..

[root@localhost ~]# cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/

 

準備工作3:nginx安裝pcre擴展

[root@localhost ~]# tar zxvf pcre-8.43.tar.gz

[root@localhost ~]# cd pcre-8.43

[root@localhost pcre-8.43]# ./configure

[root@localhost pcre-8.43]# make && make install

[root@localhost pcre-8.43] cd ..

準備工作4:添加www的用戶組及用戶

[root@localhost ~]# groupadd www

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

 

準備工作5:安裝目錄及相關說明

安裝目錄

/usr/local/php

/usr/local/nginx

/usr/local/mysql

/www/php/phpMyAdmin

源文件目錄

/root/php-7.3.6

/root/nginx-1.17.0

/root/pcre-8.43

/root/libzip-1.2.0

/root/phpMyAdmin-4.9.0.1-all-languages

配置文件目錄

/usr/local/php/php.ini

/usr/local/nginx/conf/nginx.conf

/www/php/phpMyAdmin/config.inc.php

nginx的web目錄

/www                

/www/java        #java項目的web根目錄

/www/php        #php項目的web根目錄

/www/html       #html靜態文件項目的web根目錄

 

安裝php

[root@localhost ~]# tar zxvf php-7.3.6.tar.gz

[root@localhost ~]# cd php-7.3.6

[root@localhost php-7.3.6]# mkdir builder

[root@localhost php-7.3.6]# cd builder

[root@localhost builder]# ../configure --with-config-file-path=/usr/local/php \

           --with-fpm-user=www --with-fpm-group=www --enable-fpm \

           --with-pdo-mysql --with-pdo-sqlite --with-mysqli \

           --with-freetype-dir=/usr/lib --with-png-dir=/usr/lib \

           --with-libxml-dir=/usr/include/libxml2 --with-jpeg-dir=/usr/lib \

           --with-curl --with-gd --with-gettext --with-iconv-dir --with-kerberos \

           --with-libdir=lib64 --with-openssl --with-pcre-regex --with-pear \

           --with-xmlrpc  --with-xsl --with-zlib --with-bz2 --with-mhash \

           --enable-bcmath --enable-inline-optimization --enable-mbregex \

           --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop \

           --enable-soap --enable-exif --enable-ftp --enable-wddx \

           --enable-sockets --enable-sysvsem --enable-sysvshm --enable-zip \

           --prefix=/usr/local/php/

[root@localhost builder]# make -j 8 && make install

至此,php-7.3.6安裝完畢,屏幕打印信息如下:

Build complete.

Don't forget to run 'make test'.



Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/

Installing PHP CLI binary:        /usr/local/php/bin/

Installing PHP CLI man page:      /usr/local/php/php/man/man1/

Installing PHP FPM binary:        /usr/local/php/sbin/

Installing PHP FPM defconfig:     /usr/local/php/etc/

Installing PHP FPM man page:      /usr/local/php/php/man/man8/

Installing PHP FPM status page:   /usr/local/php/php/php/fpm/

Installing phpdbg binary:         /usr/local/php/bin/

Installing phpdbg man page:       /usr/local/php/php/man/man1/

Installing PHP CGI binary:        /usr/local/php/bin/

Installing PHP CGI man page:      /usr/local/php/php/man/man1/

Installing build environment:     /usr/local/php/lib/php/build/

Installing header files:          /usr/local/php/include/php/

Installing helper programs:       /usr/local/php/bin/

  program: phpize

  program: php-config

Installing man pages:             /usr/local/php/php/man/man1/

  page: phpize.1

  page: php-config.1

Installing PEAR environment:      /usr/local/php/lib/php/

[PEAR] Archive_Tar    - installed: 1.4.7

[PEAR] Console_Getopt - installed: 1.4.2

[PEAR] Structures_Graph- installed: 1.1.1

[PEAR] XML_Util       - installed: 1.4.3

[PEAR] PEAR           - installed: 1.10.9

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf

You may want to add: /usr/local/php/lib/php to your php.ini include_path

/root/php-7.3.6/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

ln -s -f phar.phar /usr/local/php/bin/phar

Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

 

配置php

# 複製php.ini到指定的配置目錄--with-config-file-path=/usr/local/php(開發環境推薦php.ini-development,生產環境推薦php.ini-production)

# 複製 php.ini、php-fpm.conf、www.conf 配置文件

[root@localhost builder]# cd /root/php-7.3.6

[root@localhost php-7.3.6]# cp /root/php-7.3.6/php.ini-development /usr/local/php/php.ini

[root@localhost php-7.3.6]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

[root@localhost php-7.3.6]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf

# 添加軟連接

[root@localhost php-7.3.6]# ln -s /usr/local/php/sbin/php-fpm /usr/local/bin

 

啓動php

[root@localhost php-7.3.6]# cp /root/php-7.3.6/sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm

[root@localhost php-7.3.6]# chmod 755 /etc/init.d/php-fpm

[root@localhost php-7.3.6]# chkconfig php-fpm on

[root@localhost php-7.3.6]# vi /etc/init.d/php-fpm

# 修改內容項如下(紅色字體爲有修改的內容項),可避免以下報錯,懂shell腳本的很容易明白的:

報錯:Starting php-fpm /etc/init.d/php-fpm: line 57: @sbindir@/php-fpm: No such file or directory

prefix=/usr/local/php

exec_prefix=$prefix

 

php_fpm_BIN=$prefix/sbin/php-fpm

php_fpm_CONF=$prefix/etc/php-fpm.conf

php_fpm_PID=$prefix/var/run/php-fpm.pid

[root@localhost php-7.3.6]# service php-fpm restart

[root@localhost php-7.3.6]# ps aux | grep php
root      32183  0.0  0.1 127652  6568 ?        Ss   01:50   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)

nobody    32184  0.0  0.1 127652  6100 ?        S    01:50   0:00 php-fpm: pool www

nobody    32185  0.0  0.1 127652  6100 ?        S    01:50   0:00 php-fpm: pool www
[root@localhost php-7.3.6]# netstat -tunlp |grep 9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      32560/php-fpm: mast

用ps 查看php進程-->正常,netstat查看端口監聽-->正常,php安裝配置到止全部結束。

 

安裝nginx

[root@localhost ~]# tar zxvf nginx-1.17.0.tar.gzip

[root@localhost ~]# cd nginx-1.17.0

[root@localhost nginx-1.17.0]# ./configure \

        --user=www \

        --group=www \

        --prefix=/usr/local/nginx \

        --with-pcre=/root/pcre-8.43 \

        --with-http_ssl_module \

        --with-http_stub_status_module \

        --with-http_realip_module \

        --with-http_flv_module \

        --with-http_v2_module \

        --with-http_gzip_static_module \

        --error-log-path=/var/log/nginx/error.log \

        --http-log-path=/var/log/nginx/access.log \

        --with-threads

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

 

nginx的configure參數官方文檔(也可以./configure --help查看)

http://nginx.org/en/docs/configure.html

 

配置www的網站目錄

建立www運行目錄,並賦予www.www用戶組的執行權限

[root@localhost nginx]# mkdir /www

[root@localhost nginx]# cd /www

[root@localhost www]# mkdir html

[root@localhost www]# mkdir php

[root@localhost www]# mkdir java

[root@localhost www]# vi /www/php/info.php

# info.php中加入以下內容,保存退出

<?php phpinfo(); ?>

[root@localhost www]# chown -R www.www /www

 

配置nginx整合php

修改nginx.conf文件,整合php

[root@localhost www]# cd /usr/local/nginx

[root@localhost nginx]# vi  /usr/local/nginx/conf/nginx.conf

        location ~ \.php$ {

            root           /www/php;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /www/php$fastcgi_script_name;

            include        fastcgi_params;

        }

 

以上紅色字爲有修改的部分(去年#註釋),參數解釋如下:

location 正則匹配到以php結尾的到這裏解析,

root 指明瞭網站目錄

fastcgi_pass 指明瞭用哪裏的php-fpm來解析

fastcgi_index 指明首頁

fastcgi_param 指明的是php動態程序的主目錄,/scripts也就是$fastcgi_script_name前面指定的路徑,我們一般在這裏寫網站根目錄的路徑,比如我們的路徑是 /www/html。

 

# 測試nginx修改並重新加載nginx.conf(下列命令必須要先啓動nginx才能執行

[root@localhost nginx]# sbin/nginx -t

[root@localhost nginx]# sbin/nginx -s reload

 

配置nginx爲系統服務並加入開機啓動

[root@localhost nginx]# vi /etc/init.d/nginx

# 以下爲nginx 文件內容,請複製粘貼保存

#!/bin/sh

#

# nginx - this script starts and stops the nginx daemin

#

# chkconfig:   - 85 15

# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \

#               proxy and IMAP/POP3 proxy server

# processname: nginx

# config:      /usr/local/nginx/conf/nginx.conf

# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"

prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {

    [ -x $nginx ] || exit 5

    [ -f $NGINX_CONF_FILE ] || exit 6

    echo -n $"Starting $prog: "

    daemon $nginx -c $NGINX_CONF_FILE

    retval=$?

    echo

    [ $retval -eq 0 ] && touch $lockfile

    return $retval

}

stop() {

    echo -n $"Stopping $prog: "

    killproc $prog -QUIT

    retval=$?

    echo

    [ $retval -eq 0 ] && rm -f $lockfile

    return $retval

}

restart() {

    configtest || return $?

    stop

    start

}

reload() {

    configtest || return $?

    echo -n $"Reloading $prog: "

    killproc $nginx -HUP

    RETVAL=$?

    echo

}

force_reload() {

    restart

}

configtest() {

  $nginx -t -c $NGINX_CONF_FILE

}

rh_status() {

    status $prog

}

rh_status_q() {

    rh_status >/dev/null 2>&1

}

case "$1" in

    start)

        rh_status_q && exit 0

        $1

        ;;

    stop)

        rh_status_q || exit 0

        $1

        ;;

    restart|configtest)

        $1

        ;;

    reload)

        rh_status_q || exit 7

        $1

        ;;

    force-reload)

        force_reload

        ;;

    status)

        rh_status

        ;;

    condrestart|try-restart)

        rh_status_q || exit 0

            ;;

    *)

        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

        exit 2

esac

 

[root@localhost nginx]# chmod 755 /etc/init.d/nginx

[root@localhost nginx]# chkconfig nginx on

[root@localhost nginx]# chkconfig --list|grep nginx
nginx           0:關    1:關    2:開    3:開    4:開    5:開    6:關
[root@localhost nginx]# service nginx start

[root@localhost nginx]# ps aux |grep nginx
root      17432  0.0  0.0  46180  1180 ?        Ss   23:21   0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

www       17433  0.0  0.0  46572  1968 ?        S    23:21   0:00 nginx: worker process

root      17436  0.0  0.0 112728   992 pts/1    S+   23:21   0:00 grep --color=auto nginx

查看端口監聽情況

[root@localhost nginx]# netstat -antp
Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    

tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      9604/php-fpm: maste

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16946/nginx: master

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      9549/sshd           

tcp        0      0 192.168.154.132:22      192.168.154.1:50204     ESTABLISHED 10148/sshd: root@pt

tcp6       0      0 :::3306                 :::*                    LISTEN      9884/mysqld         

tcp6       0      0 :::22                   :::*                    LISTEN      9549/sshd           

tcp6       0      0 :::33060                :::*                    LISTEN      9884/mysqld  

       

訪問80端口

[root@localhost nginx]# curl 127.0.0.1:80
<!DOCTYPE html>

<html>

<head>

<title>Welcome to nginx!</title>

<style>

    body {

        width: 35em;

        margin: 0 auto;

        font-family: Tahoma, Verdana, Arial, sans-serif;

    }

</style>

</head>

<body>

<h1>Welcome to nginx!</h1>

<p>If you see this page, the nginx web server is successfully installed and

working. Further configuration is required.</p>



<p>For online documentation and support please refer to

<a href="http://nginx.org/">nginx.org</a>.<br/>

Commercial support is available at

<a href="http://nginx.com/">nginx.com</a>.</p>



<p><em>Thank you for using nginx.</em></p>

</body>

</html>

 

 

在防火牆中開啓80端口的遠程訪問

[root@localhost nginx]# firewall-cmd --zone=public --add-port=80/tcp --permanent        

success

[root@localhost nginx]# firewall-cmd --reload

success

[root@localhost nginx]# firewall-cmd --zone=public --list-ports

3306/tcp 80/tcp

 

這樣瀏覽器中就可以用ip來訪問了,假設ip爲192.168.0.10

nginx歡迎頁面

http://192.168.0.10

phpinfo頁面

http://192.168.0.10/info.php

 

至此,nginx+php配置全部結束

 

phpMyAdmin配置

[root@localhost ~]# tar zxvf phpMyAdmin-4.9.0.1-all-languages.tar.gzip

[root@localhost ~]# mv phpMyAdmin-4.9.0.1-all-languages /www/php/phpMyAdmin

[root@localhost ~]# cd /www/php/phpMyAdmin/

[root@localhost phpMyAdmin]# cp config.sample.inc.php config.inc.php

[root@localhost phpMyAdmin]# vi config.inc.php

# 將host設置爲127.0.0.1,blowfish_secret值隨便填入46位長度以內的字符串

$cfg['Servers'][$i]['host'] = '127.0.0.1';

$cfg['blowfish_secret'] = '29*(#*&$KFDJIELFksdie*///'

 

[root@localhost ~]# chown -R www.www /www/php/phpMyAdmin

 

修改mysql的登錄設置,將password改爲你數據庫的root密碼

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

或者修改my.cnf,在[mysqld]中加入紅色字體內容

[mysqld]

default_authentication_plugin=mysql_native_password

原因:在MySQL 8.0+中,默認身份驗證插件已從'mysql_native_password'更改爲'caching_sha2_password','root'@'localhost'管理帳戶默認使用'caching_sha2_password'身份驗證插件。跟phpMyAdmin不兼容,如果希望root帳戶使用之前的默認身份驗證插件'mysql_native_password'。

官網資料: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password

 

在nginx中配置phpMyAdmin訪問

在nginx中建立phpMyAdmion配置文件pma.conf,監聽8081端口

[root@localhost ~]# cd /usr/local/nginx/conf

[root@localhost conf]# mkdir conf.d

[root@localhost conf]# vi conf.d/pma.conf

# 以下爲pma.conf的內容,請複製粘貼保存

    server {

        listen       8081;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        location / {

            root   /www/php/phpMyAdmin;

            index  index.html index.htm index.php;

        }



        error_page  404              /404.html;



        # redirect server error pages to the static page /50x.html

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           /www/php/phpMyAdmin;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /www/php/phpMyAdmin$fastcgi_script_name;

            include        fastcgi_params;

        }

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        location ~ /\.ht {

            deny  all;

        }

    }

 

將配置文件加入nginx.conf中,並reload重新加載nginx配置,使剛設置的立即生效

[root@localhost conf]# vi nginx.conf

# 在文件最後的}之前加入紅色內容,加載剛纔編輯的pma.conf配置文件,如示:

    include conf.d/*.conf;

}

[root@localhost conf]# ../sbin/nginx -s reload

開放防火牆的8081端口訪問

[root@localhost conf]# firewall-cmd --zone=public --add-port=8081/tcp --permanent  

success

[root@localhost conf]# firewall-cmd --reload

success

 

這時,可以直接用http://ip:8081訪問phpMyAdmin(ip請改爲你配置phpMyAdmin服務器的ip)

 

至此,nginx+php+phpMyAdmin的配置講解全部結束!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章