安装环境说明:
(软件下载地址在文末附录)
- Linux : CentOS release 6.9 (最小化安装)
- Apache : httpd-2.4.33.tar.bz2
- MariaDB : mariadb-10.2.14-linux-x86_64.tar.gz
- PHP : php-7.1.17.tar.bz2
- libmemcached : libmemcached-1.0.18.tar.gz
- php-memcached : memcached-3.0.4.tgz
- Apr : apr-1.6.3.tar.gz
- Apr-util : apr-util-1.6.1.tar.gz
安装的顺序:
Apache --> MariaDB --> PHP
1.关闭SELinux,防火墙
1# vim /etc/selinux/config 2 SELINUX=disabled 3# setenforce 0 4# service iptables stop 5# chkconfig iptables off
2.配置aliyun Yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
3.安装开发工具组和依赖包
1# yum -y groupinstall "development tools" 2# yum -y install pcre pcre-devel openssl-devel expat-devel
4.编译安装apr-1.4和apr-1.5
1最新版的httpd2.4需要依赖apr-1.4以上版本和apr-1.5以上版本 2# tar vxf apr-1.6.3.tar.gz 3# cd apr-1.6.3 4# ./configure --prefix=/usr/local/apr 5# make 6# make install 7 8# tar vxf apr-util-1.6.1.tar.gz 9# cd apr-util-1.6.1 10# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 11# make 12# make install
5.编译安装httpd2.4.33
1# tar vxf httpd-2.4.33.tar.bz2 2编译httpd之前把上一步解压出来的apr和apr-util文件复制到httpd-2.4.33/srclib/文件夹下,再进行httpd编译 3# mv apr-1.6.3 httpd-2.4.33/srclib/apr 4# mv apr-util-1.6.1 httpd-2.4.33/srclib/apr-util 5# cd httpd-2.4.33 6# ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork 7# make 8# make install 9 10配置以支持chkconfig控制 11# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd 12# vim /etc/rc.d/init.d/httpd 13 在第二行加入如下三行(前面的#号不能省略) 14 # Comments to support chkconfig on RedHat Linux 15 # chkconfig: 35 85 15 16 # description: Apache is a World Wide Web server. 17# chkconfig --add httpd 18# chkconfig httpd on 19# service httpd restart 20# vim /etc/profile.d/httpd.sh 21 export PATH=$PATH:/usr/local/apache/bin 22# source /etc/profile.d/httpd.sh 23 24 25打开http://192.168.10.10/ 可以看到httpd已经工作
6.编译安装Mariadb10.2.14
1# yum install libaio 2解压安装并指定解压路径/usr/local,创建软连接 3# tar xvf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local 4# cd /usr/local 5# ln -s mariadb-10.2.14-linux-x86_64/ mysql 6创建mysql用户,并指定家目录。 7# mkdir /mysql 8# useradd -r -m -s /sbin/nologin -d /mysql/data mysql 9生成mysql数据库 10# /usr/local/mysql/scripts/mysql_install_db --datadir=/mysql/data --basedir=/usr/local/mysql --user=mysql 11 12配置mysql的配置文件 13# cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf 14# vim /etc/my.cnf ## 在[mysqld]节点下追加如下三行 15 [mysqld] 16 datadir = /mysql/data 17 innodb_file_per_table = ON 18 skip_name_resolve = ON 19 20配置以支持chkconfig控制 21# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 22# chkconfig --add mysqld 23# chkconfig mysqld on 24# service mysqld restart 25执行安全初始化数据库脚本 26# /usr/local/mysql/bin/mysql_secure_installation 27 28# vim /etc/profile.d/mysqld.sh 29 export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache/bin 30# source /etc/profile.d/mysqld.sh
7.编译安装PHP7.1.17
1解决依赖 2# yum install -y epel-release 3# yum -y install php-mcrypt libmcrypt libmcrypt-devel libxml2-devel 4 5编译安装 6# tar xvf php-7.1.17.tar.bz2 7# cd php-7.1.17 8# ./configure --prefix=/usr/local/php --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo 9注意: php-7.0以上版本使用 –enable-mysqlnd –with-mysqli=mysqlnd ,原–with-mysql不再支持 10# make 11# make install 12 13提供php配置文件 14# cp php.ini-production /etc/php.ini 15 16编辑apache配置文件httpd.conf,以使apache支持php 17# vim /usr/local/apache/conf/httpd.conf 18 添加如下两行 19 AddType application/x-httpd-php .php 20 AddType application/x-httpd-php-source .phps 21 找到如下行并追加index.php 结果如下 22 DirectoryIndex index.html index.php 23 重启httpd服务以使配置生效 24# service httpd restart 25 26测试httpd、mariadb、php是否能够协同工作 27# rm -rf /usr/local/apache/htdocs/index.html 28# vim /usr/local/apache/htdocs/index.php 29 <?php 30 $mysqli=new mysqli("localhost","root","123456"); 31 if(mysqli_connect_errno()){ 32 echo "连接数据库失败!"; 33 $mysqli=null; 34 exit; 35 } 36 echo "连接数据库成功!"; 37 $mysqli->close(); 38 ?> 39 40 41打开http://192.168.10.10/ 能看到"连接数据库成功!"即可,否则请检查错误。
8.编译安装php-memcached扩展
1最新版Xcache3.2最高只支持到PHP 5.6,所以PHP7不在支持列表里,我以这里我们使用memcached来提供缓存功能 2这个扩展需要 libmemcached 客户端库(版本大于等于 1.0.0)。链接memcached服务器时使用SASL认证,需要libmemcached 必须开启SASL选项。 3官方教程http://php.net/manual/zh/memcached.installation.php 4 5编译安装libmemcached 6# yum -y install cyrus-sasl-devel 7# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz 8# tar vxf libmemcached-1.0.18.tar.gz 9# cd libmemcached-1.0.18 10# ./configure --prefix=/usr/local/libmemcached --with-memcached --enable-sasl 11# make 12# make install 13 14编译安装php-memcached 15# tar xvf memcached-3.0.4.tgz 16# cd memcached-3.0.4 17# /usr/local/php/bin/phpize 18 Configuring for: 19 PHP Api Version: 20160303 20 Zend Module Api No: 20160303 21 Zend Extension Api No: 320160303 22# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached 23# make 24# make install 25# echo "extension=memcached.so" >> /etc/php.ini 26# service httpd restart
附录:软件下载地址
- CentOS 6.9 : http://mirrors.sohu.com/centos/6/isos/x86_64/CentOS-6.9-x86_64-LiveDVD.iso
- httpd-2.4.33.tar.bz2 : http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.33.tar.bz2
- mariadb-10.2.14-linux-x86_64.tar.gz : https://downloads.mariadb.org/interstitial/mariadb-10.2.14/bintar-linux-x86_64/mariadb-10.2.14-linux-x86_64.tar.gz
- php-7.1.17.tar.bz2 : http://cn2.php.net/get/php-7.1.17.tar.bz2/from/this/mirror
- libmemcached-1.0.18.tar.gz : https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
- memcached-3.0.4.tgz : http://pecl.php.net/get/memcached-3.0.4.tgz
- apr-1.6.3.tar.gz : http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.gz
- apr-util-1.6.1.tar.gz : http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.gz