全新以最小化包安装了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-1.17.0]# cd /usr/local/nginx
[root@localhost nginx]# mkdir -p /www/html
[root@localhost nginx]# mkdir -p /www/php
[root@localhost nginx]# mkdir -p /www/java
[root@localhost nginx]# vi /www/php/info.php
# info.php中加入以下内容,保存退出
<?php phpinfo(); ?>
[root@localhost nginx]# chown -R www.www /www
配置nginx整合php
修改nginx.conf文件,整合php
[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'。
在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的配置讲解全部结束!