centos6.5+Nginx1.14+MySQL8.0+php7.0
一, Nginx 编译安装 (nginx-1.14.2.tar.gz)
1, 下载 Nginx 源码
下载地址 http://nginx.org/en/download.html
有三个版本 Mainline version(开发版),Stable version(最新稳定版) 和 Legacy versions(老版稳定版)
3, 安装前准备
安装 pcre-devel 包, Additional Development,Development Tools,openssl 与 openssl-devel 等依赖工具
- yum -y groupinstall "Development Tools" "Additional Development"
- yum -y install pcre-devel openssl openssl-devel
创建用户与组
#groupadd -r nginx #useradd -r -g nginx nginx
创建目录
#mkdir -p /var/tmp/nginx/{proxy,client,fcgi}
4, 解压与安装
- #tar -zxvf nginx-1
- #cd nginx-1.14.2
- #./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
- #make && make install
5, 为 Nginx 提供服务启动脚本
- VIM /etc/rc.d/init.d/nginx
- #!/bin/sh
- #nginx - this script starts and stops the nginx daemon
- #chkconfig: - 85 15
- #description: Nginx is an HTTP(S) server, HTTP(S) reverse \
- #proxy and IMAP/POP3 proxy server
- #processname: nginx
- #config: /etc/nginx/nginx.conf
- #config: /etc/sysconfig/nginx
- #pidfile: /var/run/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/sbin/nginx"
- prog=$(basename $nginx)
- NGINX_CONF_FILE="/etc/nginx/nginx.conf"
- [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
- lockfile=/var/lock/subsys/nginx
- make_dirs() {
- #make required directories
- user=
- nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -
- options=
- $nginx -V 2>&1 | grep 'configure arguments:'
- for opt in $options; do
- if [
- echo $opt | grep '.*-temp-path'
- ]; then
- value=
- echo $opt | cut -d "=" -f 2
- if [ ! -d "$value" ]; then
- echo "creating" $value
- mkdir -p $value && chown -R $user $value
- fi
- fi
- done
- }
- start() {
- [ -x $nginx ] || exit 5
- [ -f $NGINX_CONF_FILE ] || exit 6
- make_dirs
- 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
- sleep 1
- 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
为启动脚本添加权限
- #chmod +x /etc/rc.d/init.d/nginx
- #chkconfig --add nginx
- #chkconfig nginx on
- #service nginx restart
启动中可能会遇到的问题
nginx: [emerg] getpwnam("nginx") failed #未建立 nginx 用户和用户组
查看端口是否监听
- #netstat -tlunp |grep nginx
- tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN 6431/nginx
可以网页测试 浏览器输入 IP 地址 看到 welcome to nginx 则表示成功
二, MySQL 二进制安装 (MySQL-8.0.13-Linux-glibc2.12-x86_64.tar.xz)
1, 先卸载之前版本的 MySQL 组件 #rpm -e
2, 安装新版的 MySQL 组件
- #rpm -ivh MySQL-community-client-8.0.13-1.el6.x86_64.rpm
- #rpm -ivh MySQL-community-common-8.0.13-1.el6.x86_64.rpm
- #rpm -ivh MySQL-community-devel-8.0.13-1.el6.x86_64.rpm
- #rpm -ivh MySQL-community-libs-8.0.13-1.el6.x86_64.rpm
3, 新建数据文件夹
#mkdir -p /mydata/data
4, 新建 MySQL 用户与组
- #groupadd -r MySQL
- #useradd -g MySQL -r -s /sbin/nologin -M -d /mydata/data MySQL
- #chown MySQL:MySQL /mydata/data
5, 安装 MySQL8.0.13
- #tar -Jxvf MySQL-8.0.13-Linux-glibc2.12-x86_64.tar.xz -C /usr/local
- #cd /usr/local
- #ln -sv MySQL-5.5.24-linux2.6-i686 MySQL
- #cd MySQL
- #chown -R MySQL:MySQL .
- #/usr/local/MySQL/bin/mysqld --user=MySQL --basedir=/usr/local/MySQL --datadir=/mydata/data --initialize-insecure
- #chown -R root .
6, 为 MySQL 提供主配置文件
- #vi /etc/my.cnf
- [mysqld]
- server-id = 1
- port = 3306
- mysqlx_port = 33060
- mysqlx_socket = /mydata/data/mysqlx.sock
- datadir = /mydata/data
- socket = /mydata/data/MySQL.sock
- pid-file = /mydata/data/mysqld.pid
- log-error = /mydata/data/error.log
- slow-query-log = 1
- slow-query-log-file = /mydata/data/slow.log
- long_query_time = 0.2
- log-bin = /mydata/data/bin.log
- relay-log = /mydata/data/relay.log
- binlog_format =ROW
- relay_log_recovery = 1
- character-set-client-handshake = FALSE
- character-set-server = utf8mb4
- collation-server = utf8mb4_unicode_ci
- init_connect ='SET NAMES utf8mb4'
- innodb_buffer_pool_size = 1G
- join_buffer_size = 128M
- sort_buffer_size = 2M
- read_rnd_buffer_size = 2M
- log_timestamps = SYSTEM
- lower_case_table_names = 0
- default-authentication-plugin =mysql_native_password
- sql_mode =NO_ENGINE_SUBSTITUTION
7, 提供启动服务脚本
- #cp /usr/local/MySQL/support-files/MySQL.server /etc/rc.d/init.d/mysqld
- #vi /etc/rc.d/init.d/mysqld #更改一下几项
- basedir=/usr/local/MySQL
- datadir=/mydata/data
- mysqld_pid_file_path=/mydata/data/mysqld.pid
为启动脚本添加权限
- #chmod +x /etc/rc.d/init.d/mysqld
- #chkconfig --add mysqld
- #chkconfig mysqld on
- #service mysqld restart
8, 添加 MySQL 的 man 手册
- #vi /etc/man.conf
- MANPATH /usr/local/MySQL/man
9, 输出 MySQL 的头文件至系统头文件路径 / usr/include
#ln -sv /usr/local/MySQL/include /usr/include/MySQL
10, 输出 MySQL 的库文件给系统库
- #echo '/usr/local/mysql/lib'> /etc/ld.so.conf.d/MySQL.conf
- #ldconfig
11, 修改 PATH 环境变量, 让系统可以直接使用 MySQL 的相关命令
12, 常见报错
- 1251--Client does not support authentication protocol requested by server
- # 卸载之前的 MySQL 版本
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket'/var/lib/MySQL/MySQL.sock' (2) #无套接字文件
- ln -s /mydata/data/MySQL.sock /var/lib/MySQL/MySQL.sock
三, PHP 安装 (PHP-7.0.33.tar.bz2)
1, 安装前准备 -- 解决软件依赖关系
安装 mcrypt,mcrypt-devel,mhash,mhash-devel,libevent,libevent-devel 与 yum -y groupinstall "X Software Development"
2, 解压并安装 PHP
- #tar -jxvf PHP-7.0.33.tar.bz2
- #cd PHP-7.0.33
- ./configure --prefix=/usr/local/PHP --with-pdo-MySQL=/usr/local/MySQL --with-openssl --enable-fpm --enable-sockets --enable-sysvshm --with-mysqli=/usr/local/MySQL/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-PNG-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-mhash --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/PHP.d --with-bz2 --with-curl --enable-mysqlnd --with-mysqli --with-pdo_mysql --enable-bcmath
- #make
- #make test
- #make install
3, 为 PHP 提供配置文件
#cp /usr/local/PHP.INI-production /etc/PHP.INI
4, 为 PHP-fpm 提供配置文件
#cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf
5, 为 PHP-FPM 提供服务脚本文件
#cp sapi/fpm/init.d.PHP-fpm /etc/rc.d/init.d/PHP-fpm
为启动脚本添加权限
- #chmod +x /etc/rc.d/init.d/PHP-fpm
- #chkconfig --add PHP-fpm
- #chkconfig PHP-fpm on
- #service PHP-fpm restart
常用报错
1,configure: error: mcrypt.h not found. Please reinstall libmcrypt.
# 安装 libmcrypt
2,/usr/local/src/PHP-5.6.38/ext/mysqli/php_mysqli_structs.h:63:23: 致命错误: my_global.h: 没有那个文件或目录
./configure 加上 --enable-mysqlnd --with-mysqli
3,usr/local/src/PHP-5.6.38/ext/pdo_mysql/php_pdo_mysql_int.h:138:2: 错误: 未知的类型名'my_bool' my_bool in_null;./configure 加上 --with-pdomysql
4,configure: error: xml2-config not found. Please check your libxml2 installation
安装 libxml2-devel
5,configure: error: Please reinstall the BZip2 distribution
安装 bzip2-devel
6,configure: error: jpeglib.h not found
安装 libjpeg-turbo-devel
7,configure: error: PNG.h not found
安装 libpng-devel
8,configure: error: freetype-config not found
安装 freetype-devel9,WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/.conf' from /usr/local/PHP/etc/PHP-fpm.conf at line 125
- #cp /usr/local/PHP/etc/PHP-fpm.d/www.conf.default /usr/local/PHP/etc/PHP-fpm.d/www.conf 复制 *
- 10,ERROR: failed to open configuration file '/usr/local/php/etc/php-fpm.conf': No such file or directory
- cp /usr/local/PHP/etc/PHP-fpm.conf.default /usr/local/PHP/etc/PHP-fpm.conf
四, 整合 nginx 与 PHP
1, 编辑 / etc/nginx/nginx.conf, 启用如下选项:
- location ~ .PHP$ {
- root HTML;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.PHP;
- fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
- include fastcgi_params;
- }
- location / {
- root HTML;
- index index.PHP index.HTML index.htm;
- }
2, 编辑 / etc/nginx/fastcgi_params, 将其内容更改为如下内容:
- fastcgi_param GATEWAY_INTERFACE CGI/1.1;
- fastcgi_param SERVER_SOFTWARE nginx;
- fastcgi_param QUERY_STRING $query_string;
- fastcgi_param REQUEST_METHOD $request_method;
- fastcgi_param CONTENT_TYPE $content_type;
- fastcgi_param CONTENT_LENGTH $content_length;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- fastcgi_param SCRIPT_NAME $fastcgi_script_name;
- fastcgi_param REQUEST_URI $request_uri;
- fastcgi_param DOCUMENT_URI $document_uri;
- fastcgi_param DOCUMENT_ROOT $document_root;
- fastcgi_param SERVER_PROTOCOL $server_protocol;
- fastcgi_param REMOTE_ADDR $remote_addr;
- fastcgi_param REMOTE_PORT $remote_port;
- fastcgi_param SERVER_ADDR $server_addr;
- fastcgi_param SERVER_PORT $server_port;
- fastcgi_param SERVER_NAME $server_name;
而后重新载入 nginx 的配置文件: # service nginx reload
3, 在 / usr/HTML 新建 index.PHP 的测试页面, 测试 PHP 是否能正常工作:
- #cat> /usr/HTML/index.PHP <<EOF
- <?PHP
- phpinfo();
?> 接着就可以通过浏览器访问此测试页面了.