CENTOS6.9环境下PHP5.6.8+MYSQL5.7.21+APACHE2.4.39编译安装

安装说明:
	APACHE相关安装文件:
		apr-1.6.5.tar.gz
		apr-util-1.6.1.tar.gz
		httpd-2.4.39.tar.gz
		openssl-1.0.2n.tar.gz
		pcre-8.00.tar.gz
	MYSQL相关安装文件:
		boost_1_59_0.tar.gz
		mysql-5.7.21.tar.gz
	PHP相关安装文件:
		libmcrypt-2.5.8.tar.gz
		mcrypt-2.6.8.tar.gz
		mhash-0.9.9.9.tar.gz
		php-5.6.8.tar.gz
		phpMyAdmin-4.8.1-all-languages.zip
  1. 安装APACHE
    1.1 升级系统并安装Linux常用工具

     # yum install epel-release -y
     # yum update -y
     # shutdown -r now
     # yum -y install wget unzip zip cmake vim*
     # yum -y install gcc gcc-c++ autoconf automake make zlib zlib-devel expat-devel
    

    1.2 安装APR

     # tar -zxvf apr-1.6.5.tar.gz
     # cd /usr/local/src/apache/apr-1.6.5
     # vi /usr/local/src/apache/apr-1.6.5/configure
     	打开/usr/local/src/apache/apr-1.6.5/configure,把 $RM "$cfgfile" 行删除或注释掉。
     # ./configure --prefix=/usr/local/apr/
     # make && make install
    

    1.3 安装APR-UTIL

     # cd ..
     # tar -zxvf apr-util-1.6.1.tar.gz
     # cd apr-util-1.6.1
     # ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/
     # make && make install
    

    1.4 安装PCRE

     # cd ..
     # tar -zxvf pcre-8.00.tar.gz
     # cd pcre-8.00
     # ./configure --prefix=/usr/local/pcre
     # make && make install
    

    1.5 安装OPENSSL

     # cd ..
     # tar -zxvf openssl-1.0.2n.tar.gz
     # cd openssl-1.0.2n
     # ./config --prefix=/usr/local/openssl shared
     # make && make install
    

    1.6 安装APACHE

     # cd ..
     # tar -zxvf httpd-2.4.39.tar.gz
     # cd httpd-2.4.39
     # ./configure --prefix=/usr/local/apache/ --with-mpm=prefork --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-ssl=/usr/local/openssl
     # make && make install
    

    1.7 设置APACHE开机自启动

     # cd /usr/local/apache/bin  
     # sudo cp apachectl /etc/init.d/httpd
     # vi /etc/init.d/httpd
     
     添加如下注释内容
     # !/bin/bash
     # chkconfig:345 61 61
     # description:Apache httpd 
     保存退出
     
     # chkconfig --add httpd  (在/etc/rc.d/rc*/ 添加/etc/init.d/httpd这个文件)
     # chkconfig --list |grep httpd  (查看httpd服务是否添加)
     # chkconfig httpd on  (开启开机启动httpd服务)
    

    1.8 httpd.conf 参数配置

     	修改 AllowOverride none 改为AllowOverride all,这样就可以指明Apache服务器是否去找.htacess文件作为配置文件。去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”。
     	更改WEB目录以及端口
     	DocumentRoot "/usr/local/apache//htdocs" 更改为 DocumentRoot "/var/webroot"。
     	创建WEB目录
     		# mkdir /var/webroot
     		# chmod -R 777 /var/webroot
     	其它
     		Options Indexes FollowSymLinks  修改为:Options Includes ExecCGI FollowSymLinks(允许服务器执行CGI及SSI,禁止列出目录)。#AddHandler cgi-script .cgi 修改为:AddHandler cgi-script .cgi .pl (允许扩展名为.pl的CGI脚本运行)。DirectoryIndex index.html index.html.var #在402行 修改为:DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var (设置默认首页文件,增加index.php);ServerName www.example.com:80行去掉注释
    

    1.9 开启WEB端口

     # /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
     # /etc/rc.d/init.d/iptables save
     # /etc/init.d/iptables status  
     # service iptables restart
    
  2. 安装MYSQL

    2.1 安装MYSQL相关组件

     卸载Mariadb数据库:
     	# rpm -qa | grep maria*
     	# yum -y remove mari*
     	# rm -rf /var/lib/mysql/*
     安装ncurses-devel boost_1_59_0.tar.gz:
     	# yum -y install ncurses-devel
     	# cd /usr/local/src/mysql
     	# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
     	# tar -zxvf boost_1_59_0.tar.gz
     	# mv /usr/local/src/mysql/boost_1_59_0 /usr/local/boost
     	# cd /usr/local/boost
     	# ./bootstrap.sh 
    

    2.2 安装MYSQL

     创建MYSQL用户及相关数据路径:
     	# useradd -M -s /sbin/nologin mysql
     	# mkdir -p /data/mysql
     下载解压安装 mysql-5.7.21.tar.gz:
     	# cd /usr/local/src/mysql
     	# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21.tar.gz
     	# tar xf mysql-5.7.21.tar.gz
     	# cd mysql-5.7.21
     	# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DENABLE_DTRACE=0 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1
     	# make 
     	# make install
    

    2.3 MYSQL相关配置

     my.cnf 配置:
     	# vi /etc/my.cnf
     	[client]
     	port = 3306
     	socket = /tmp/mysql.sock
     	default-character-set = utf8mb4
    
     	[mysqld]
     	#skip-grant-tables
     	port = 3306
     	socket = /tmp/mysql.sock
     	basedir = /usr/local/mysql
     	datadir = /data/mysql
     	pid-file = /data/mysql/mysql.pid
     	user = mysql
     	bind-address = 0.0.0.0
     	server-id = 1
     	init-connect = 'SET NAMES utf8mb4'
     	character-set-server = utf8mb4
     	#skip-name-resolve
     	#skip-networking
     	back_log = 300
     	max_connections = 1000
     	max_connect_errors = 6000
     	open_files_limit = 65535
     	table_open_cache = 128
     	max_allowed_packet = 4M
     	binlog_cache_size = 1M
     	max_heap_table_size = 8M
     	tmp_table_size = 16M
     	read_buffer_size = 2M
     	read_rnd_buffer_size = 8M
     	sort_buffer_size = 8M
     	join_buffer_size = 8M
     	key_buffer_size = 4M
     	thread_cache_size = 8
     	query_cache_type = 1
     	query_cache_size = 8M
     	query_cache_limit = 2M
     	ft_min_word_len = 4
     	log_bin = mysql-bin
     	binlog_format = mixed
     	expire_logs_days = 30
     	log_error = /data/mysql/mysql-error.log
     	slow_query_log = 1
     	long_query_time = 1
     	slow_query_log_file = /data/mysql/mysql-slow.log
     	performance_schema = 0
     	explicit_defaults_for_timestamp
     	#lower_case_table_names = 1
     	skip-external-locking
     	default_storage_engine = InnoDB
     	#default-storage-engine = MyISAM
     	innodb_file_per_table = 1
     	innodb_open_files = 500
     	innodb_buffer_pool_size = 64M
     	innodb_write_io_threads = 4
     	innodb_read_io_threads = 4
     	innodb_thread_concurrency = 0
     	innodb_purge_threads = 1
     	innodb_flush_log_at_trx_commit = 2
     	innodb_log_buffer_size = 2M
     	innodb_log_file_size = 32M
     	innodb_log_files_in_group = 3
     	innodb_max_dirty_pages_pct = 90
     	innodb_lock_wait_timeout = 120
     	bulk_insert_buffer_size = 8M
     	myisam_sort_buffer_size = 8M
     	myisam_max_sort_file_size = 10G
     	myisam_repair_threads = 1
     	interactive_timeout = 28800
     	wait_timeout = 28800
    
     	[mysqldump]
     	quick
     	max_allowed_packet = 16M
     	socket = /tmp/mysql.sock
    
     	[myisamchk]
     	key_buffer_size = 8M
     	sort_buffer_size = 8M
     	read_buffer = 4M
     	write_buffer = 4M
     	socket = /tmp/mysql.sock
    
     	[mysqladmin]
     	socket = /tmp/mysql.sock
     初始化MYSQ:
     	# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
     开机自启动设置:
     	# cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
     	# chmod 755 /etc/init.d/mysql
     	# ln -s /usr/local/mysql/bin/mysql /usr/local/bin/
     	# /etc/init.d/mysql start
     	# chkconfig --add mysql
     	# chkconfig mysql on
     	# reboot
     更改密码:
     	# service mysql stop
     	# vi /etc/my.cnf
     	在 [mysqld] 下面第一行 增加 :skip-grant-tables 
     	# service mysql start
     	# mysql -u root
     	# mysql > use mysql;
     	# mysql > update user set authentication_string=PASSWORD("yulong@2020") where user='root';
     	# mysql > exit;
     	# vi /etc/my.cnf
     	在 [mysqld] 下面第一行 删除 skip-grant-tables 
     	# service mysql restart
    
  3. PHP源码安装
    3.1 安装PHP依赖组件

     # yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
    

    3.2 创建PHP用户和组

     # cd /tmp
     # groupadd www
     # useradd -g www www
    

    3.3 PHP下载/解压

     # cd /usr/local/src/php
     # wget http://am1.php.net/distributions/php-5.6.8.tar.gz
     # tar xvf php-5.6.8.tar.gz
     # cd php-5.6.8
    

    3.4 PHP设置变量并源码安装

     # cp -frp /usr/lib64/libldap* /usr/lib/
     # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --with-libmbfl --enable-ftp --with-gd --enable-gd-jis-conv --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --with-pear --enable-maintainer-zts --with-ldap=shared --without-gdbm  --with-apxs2=/usr/local/apache/bin/apxs 
     # make -j 4 && make install
    

    3.5 PHP.ini文件路径配置

     # cp php.ini-development /usr/local/php/etc/php.ini
     # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
    

    3.6 配置 php.ini 相关参数

     # vim /usr/local/php/etc/php.ini
     #我们为了防止黑客获取服务器中php版本的信息,可以关闭该信息斜路在http头中
     expose_php = Off
     #PHP短标签开启
     short_open_tag = On
     #PHP最长执行时间
     max_execution_time = 300
     #以秒为单位对通过POST、GET以及PUT方式接收数据时间进行限制
     max_input_time = 300
     #php的内存限制值
     memory_limit = 1024M
     #POST文件流大小
     post_max_size = 1024M
     #时间戳
     date.timezone = Asia/Shanghai
    

    3.7 创建php-cgi.sock存放目录

     # mkdir /var/run/www/
     # chown -R www:www /var/run/www
    

    3.8 配置php-fpm.conf

     # vi /usr/local/php/etc/php-fpm.conf
     取消以下注释并填写完整路径
     pid = /usr/local/php/var/run/php-fpm.pid
    

    3.9 启动 php-fpm

     # /usr/local/php/sbin/php-fpm
     关闭
     # kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
     重启
     # kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
    

    3.10 查看是否启动及配置 php-fpm 启动脚本 注册为系统服务 设置开机启动

     # ps -ef |grep php-fpm
     # cp /usr/local/src/php/php-5.6.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
     授与可执行权限
     # chmod +x /etc/init.d/php-fpm 
     添加php-fpm至服务列表并设置开机自启
     # chkconfig --add php-fpm
     # chkconfig --list php-fpm
     # chkconfig php-fpm on
     service php-fpm start       # 启动服务
     service php-fpm stop        # 停止服务
     service php-fpm restart     # 重启服务
     service php-fpm reload      # 平滑重启服务
     service php-fpm force-quit  # 强制退出服务
     service php-fpm status      # 查看服务状态
    

    3.11 编辑apache配置文件httpd.conf

     LoadModule php5_module        modules/libphp5.so
     AddType application/x-httpd-php .php
     AddType application/x-httpd-php-source .phps
    

    3.12 安装phpmyadmin

     # cd /usr/local/src/php
     # unzip phpMyAdmin-4.8.1-all-languages.zip
     # mv phpMyAdmin-4.8.1-all-languages /var/webroot/phpMyAdmin
     进入对应的安装目录
     # cd /var/webroot/phpMyAdmin
     添加配置文件
     # cp config.sample.inc.php config.inc.php
     # vim /var/webroot/phpMyAdmin/config.inc.php
     修改配置项 $cfg['blowfish_secret'] = 'hh5987fsns08fdr3560s0f0fsfgvd6785',输入一个较复杂的字符串
     保存退出
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值