系统:CentOS release 6.7(Final)64位
目标: Nginx 1.6 + MySQL 5.6 + PHP 7
可能出现的bug解决方法:https://blog.csdn.net/Vourn/article/details/81869797
编译工具及库文件安装
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
首先安装pcre
下载安装包并解压
[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz [root@bogon src]# tar zxvf pcre-8.35.tar.gz
进入安装包并编译安装
[root@bogon src]# cd pcre-8.35 [root@bogon pcre-8.35]# ./configure [root@bogon pcre-8.35]# make && make install
查看版本
[root@bogon pcre-8.35]# pcre-config --version [root@bogon pcre-8.35]# pcre-config --version 8.35 //此行为查看版本命令返回内容
安装Nginx
下载Nginx安装包并解压
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz [root@bogon src]# tar zxvf nginx-1.6.2.tar.gz
进入安装包并编译安装
[root@bogon src]# cd nginx-1.6.2 [root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 [root@bogon nginx-1.6.2]# make [root@bogon nginx-1.6.2]# make install
查看版本
[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v [root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v nginx version: nginx/1.6.2 //此行为查看版本命令返回内容
Nginx配置
创建Nginx运行用户
[root@bogon conf]# /usr/sbin/groupadd www [root@bogon conf]# /usr/sbin/useradd -g www www
配置/usr/local/webserver/nginx/conf/nginx.conf文件 (nginx.conf文件为以下内容)
user www www; worker_processes 2; #设置值和CPU核心数一致 error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别 pid /usr/local/webserver/nginx/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } 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'; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; #下面是server虚拟主机的配置 server { listen 80;#监听端口 server_name localhost;#域名 index index.html index.htm index.php; root /usr/local/webserver/nginx/html;#站点目录 location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$ { expires 30d; # access_log off; } location ~ .*\.(js|css)?$ { expires 15d; # access_log off; } access_log off; } }
检查配置文件正确性命令
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t
启动Nginx
[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx
访问站点
编译工具及库文件安装
yum -y install gcc gcc-c++ make autoconf libtool-ltdl-devel gd-devel freetype-devel libxml2-devel libjpeg-devel libpng-devel openssl-devel curl-devel bison patch unzip libmcrypt-devel libmhash-devel ncurses-devel sudo bzip2 flex libaio-devel
以上文件包部分在Nginx已安装,可不必重复
cmake编辑器安装
下载并解压
[root@bogon src]# wget http://www.cmake.org/files/v3.1/cmake-3.1.1.tar.gz [root@bogon src]# tar zxvf cmake-3.1.1.tar.gz
进入安装包目录并编译安装
[root@bogon src]# cd cmake-3.1.1 [root@bogon cmake-3.1.1]# ./bootstrap [root@bogon cmake-3.1.1]# make && make install
MySQL安装
下载并解压
[root@bogon src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.15.tar.gz [root@bogon src]# tar zxvf mysql-5.6.15.tar.gz
进入安装包目录并编译安装
[root@bogon src]# cd mysql-5.6.15 [root@bogon mysql-5.6.15]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/webserver/mysql/ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_INNODB_MEMCACHED=1 -DWITH_DEBUG=OFF -DWITH_ZLIB=bundled -DENABLED_LOCAL_INFILE=1 -DENABLED_PROFILING=ON -DMYSQL_MAINTAINER_MODE=OFF -DMYSQL_DATADIR=/usr/local/webserver/mysql/data -DMYSQL_TCP_PORT=3306 [root@bogon mysql-5.6.15]# make && make install
查看mysql版本
[root@bogon mysql-5.6.15]# /usr/local/webserver/mysql/bin/mysql --version
MySQL配置
创建mysql用户
[root@bogon src]# /usr/sbin/groupadd mysql [root@bogon src]# /usr/sbin/useradd -g mysql mysql
创建binlog并赋予用户权限
[root@bogon src]# mkdir -p /usr/local/webserver/mysql/binlog /www/data_mysql [root@bogon src]# chown mysql.mysql /usr/local/webserver/mysql/binlog/ /www/data_mysql/
配置my.cnf文件 (/etc/my.cnf配置为以下内容)
[client] port = 3306 socket = /tmp/mysql.sock [mysqld] replicate-ignore-db = mysql replicate-ignore-db = test replicate-ignore-db = information_schema user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /usr/local/webserver/mysql datadir = /www/data_mysql log-error = /usr/local/webserver/mysql/mysql_error.log pid-file = /usr/local/webserver/mysql/mysql.pid open_files_limit = 65535 back_log = 600 max_connections = 5000 max_connect_errors = 1000 table_open_cache = 1024 external-locking = FALSE max_allowed_packet = 32M sort_buffer_size = 1M join_buffer_size = 1M thread_cache_size = 600 #thread_concurrency = 8 query_cache_size = 128M query_cache_limit = 2M query_cache_min_res_unit = 2k default-storage-engine = MyISAM default-tmp-storage-engine=MYISAM thread_stack = 192K transaction_isolation = READ-COMMITTED tmp_table_size = 128M max_heap_table_size = 128M log-slave-updates log-bin = /usr/local/webserver/mysql/binlog/binlog binlog-do-db=oa_fb binlog-ignore-db=mysql binlog_cache_size = 4M binlog_format = MIXED max_binlog_cache_size = 8M max_binlog_size = 1G relay-log-index = /usr/local/webserver/mysql/relaylog/relaylog relay-log-info-file = /usr/local/webserver/mysql/relaylog/relaylog relay-log = /usr/local/webserver/mysql/relaylog/relaylog expire_logs_days = 10 key_buffer_size = 256M read_buffer_size = 1M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 64M myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 myisam_recover interactive_timeout = 120 wait_timeout = 120 skip-name-resolve #master-connect-retry = 10 slave-skip-errors = 1032,1062,126,1114,1146,1048,1396 #master-host = 192.168.1.2 #master-user = username #master-password = password #master-port = 3306 server-id = 1 loose-innodb-trx=0 loose-innodb-locks=0 loose-innodb-lock-waits=0 loose-innodb-cmp=0 loose-innodb-cmp-per-index=0 loose-innodb-cmp-per-index-reset=0 loose-innodb-cmp-reset=0 loose-innodb-cmpmem=0 loose-innodb-cmpmem-reset=0 loose-innodb-buffer-page=0 loose-innodb-buffer-page-lru=0 loose-innodb-buffer-pool-stats=0 loose-innodb-metrics=0 loose-innodb-ft-default-stopword=0 loose-innodb-ft-inserted=0 loose-innodb-ft-deleted=0 loose-innodb-ft-being-deleted=0 loose-innodb-ft-config=0 loose-innodb-ft-index-cache=0 loose-innodb-ft-index-table=0 loose-innodb-sys-tables=0 loose-innodb-sys-tablestats=0 loose-innodb-sys-indexes=0 loose-innodb-sys-columns=0 loose-innodb-sys-fields=0 loose-innodb-sys-foreign=0 loose-innodb-sys-foreign-cols=0 slow_query_log_file=/usr/local/webserver/mysql/mysql_slow.log long_query_time = 1 [mysqldump] quick max_allowed_packet = 32M
初始化数据库
[root@bogon src]# /usr/local/webserver/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql
显示如下信息:
Installing MySQL system tables...2018-08-20 10:57:51 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). OK Filling help tables...2018-08-20 10:57:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). OK ...
创建开机启动脚本
[root@bogon src]# cd /usr/local/webserver/mysql/ [root@bogon mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [root@bogon mysql]# chkconfig --add mysqld [root@bogon mysql]# chkconfig --level 35 mysqld on
启动mysql服务器
[root@bogon mysql]# service mysqld start
连接MySQL(密码默认为空)
[root@bogon mysql]# /usr/local/webserver/mysql/bin/mysql -u root -p
修改MySQL用户密码
mysql>use mysql; mysql>update user set password=password(“新密码”) where user=’root’; mysql>Flush privileges; mysql>quit mysql>service mysqld restart
编译工具及库文件安装
yum -y install libxml2 libxml2-devel curl-devel libpng-devel freetype-devel libmcrypt-devel libjpeg-devel
以上文件包部分在Nginx、MySQL已安装,可不必重复
PHP 7 编译安装
[root@bogon src]# wget http://cn2.php.net/distributions/php-7.0.14.tar.gz [root@bogon src]# tar xzf php-7.0.14.tar.gz
下载并解压
进入相应目录并编译安装
[root@bogon src]# cd php-7.0.14 [root@bogon php-7.0.14]# ./configure --prefix=/usr/local/webserver/php --enable-fpm --enable-opcache --with-config-file-path=/usr/local/webserver/php/etc --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-static --enable-sockets --enable-wddx --enable-zip --enable-calendar --enable-bcmath --enable-soap --with-zlib --with-iconv --with-freetype-dir --with-gd --with-jpeg-dir --with-xmlrpc --enable-mbstring --with-sqlite3 --with-curl --enable-ftp --with-mcrypt --with-openssl --with-gettext --enable-pcntl [root@bogon php-7.0.14]# make && make install
PHP 7 配置
修改配置内容
[root@bogon php-7.0.14]# cp /usr/local/src/php-7.0.14/php.ini-development /usr/local/webserver/php/etc/php.ini [root@bogon php-7.0.14]# cp /usr/local/webserver/php/etc/php-fpm.conf.default /usr/local/webserver/php/etc/php-fpm.conf [root@bogon php-7.0.14]# cp /usr/local/webserver/php/etc/php-fpm.d/www.conf.default /usr/local/webserver/php/etc/php-fpm.d/www.conf
修改配置文件php-fpm.conf (把最后一行改为自己的实际路径)
修改配置文件www.conf (把user和group改为nginx的用户名组)
启动php-fpm服务并查看端口情况(9000端口正常使用)
修改nginx.conf相应配置
默认注释的把注释符#去掉,修改完退出重启nginx
访问站点
出现以上信息,安装成功~