安装环境说明:
(软件下载地址在文末附录)
- Linux : CentOS Linux release 7.4.1708 (Core)(最小化安装)
- 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禁用SELinux 2# vim /etc/selinux/config 3 SELINUX=disabled 4 5# setenforce 0 6 7配置防火墙放行http和https 8# firewall-cmd --permanent --zone=public --add-service=http 9# firewall-cmd --permanent --zone=public --add-service=https 10# firewall-cmd --reload
2.配置aliyun Yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.安装开发工具组和依赖包
1# yum -y groupinstall "development tools" 2# yum -y install pcre pcre-devel-devel openss-devel expat-devel
4.编译安装apr-1.4和apr-1.5
最新版的httpd2.4需要依赖apr-1.4以上版本和apr-1.5以上版本
1# tar vxf apr-1.6.3.tar.gz 2# cd apr-1.6.3 3# ./configure --prefix=/usr/local/apr 4# make 5# make install 6 7# tar vxf apr-util-1.6.1.tar.gz 8# cd apr-util-1.6.1 9# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 10# make 11# 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 18# chkconfig --add httpd 19# chkconfig httpd on 20# systemctl restart httpd 21# vim /etc/profile.d/httpd.sh 22 export PATH=$PATH:/usr/local/apache/bin 23# source /etc/profile.d/httpd.sh 24 25 26打开 http://192.168.10.10/ 可以看到httpd已经工作
6.编译安装Mariadb10.2.14
1解压安装并指定解压路径/usr/local,创建软连接 2 # tar xvf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local 3# cd /usr/local 4# ln -s mariadb-10.2.14-linux-x86_64/ mysql 5创建mysql用户,并指定家目录。 6# mkdir /mysql 7# useradd -r -m -s /sbin/nologin -d /mysql/data mysql 8生成mysql数据库 9# /usr/local/mysql/scripts/mysql_install_db --datadir=/mysql/data --basedir=/usr/local/mysql --user=mysql 10 11配置mysql的配置文件 12# cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf 13# vim /etc/my.cnf ## 在[mysqld]节点下追加如下三行 14 [mysqld] 15 datadir = /mysql/data 16 innodb_file_per_table = ON 17 skip_name_resolve = ON 18 19配置以支持chkconfig控制 20# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 21# chkconfig --add mysqld 22# chkconfig mysqld on 23# systemctl restart mysqld 24执行安全初始化数据库脚本 25# /usr/local/mysql/bin/mysql_secure_installation 26 27# vim /etc/profile.d/mysqld.sh 28 export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache/bin 29# 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 24重启httpd服务以使配置生效 25# systemctl restart httpd 26 27测试httpd、mariadb、php是否能够协同工作 28# rm -rf /usr/local/apache/htdocs/index.html 29# vim /usr/local/apache/htdocs/index.php 30 <?php 31 $mysqli=new mysqli("localhost","root","123456"); 32 if(mysqli_connect_errno()){ 33 echo "连接数据库失败!"; 34 $mysqli=null; 35 exit; 36 } 37 echo "连接数据库成功!"; 38 $mysqli->close(); 39 ?> 40 41 42打开http://192.168.10.10/ 能看到"连接数据库成功!"即可,否则请检查错误。
8.编译安装php-memcached扩展
最新版Xcache3.2最高只支持到PHP 5.6,所以PHP7不在支持列表里,我以这里我们使用php-memcached来提供缓存功能
1编译安装libmemcached 2# yum -y install cyrus-sasl-devel 3# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz 4# cd libmemcached-1.0.18 5# ./configure --prefix=/usr/local/libmemcached --with-memcached --enable-sasl 6# make 7# make install 8 9编译安装php-memcached 10# tar xvf memcached-3.0.4.tgz 11# cd memcached-3.0.4 12# /usr/local/php/bin/phpize 13 Configuring for: 14 PHP Api Version: 20160303 15 Zend Module Api No: 20160303 16 Zend Extension Api No: 320160303 17# ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached 18# make 19# make install 20# echo "extension=memcached.so" >> /etc/php.ini 21# systemctl restart httpd
附录:软件下载地址
- CentOS 7.4.1708 : http://mirrors.sohu.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.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