CentOS7编译安装LAMP(CentOS7、httpd-2.4、php-7.1、mariadb-10.2、memcached-3.0.4)
2018-05-02 23:31
1051 查看
安装环境说明:
(软件下载地址在文末附录)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,防火墙
禁用SELinux # vim /etc/selinux/config SELINUX=disabled # setenforce 0 配置防火墙放行http和https # firewall-cmd --permanent --zone=public --add-service=http # firewall-cmd --permanent --zone=public --add-service=https # firewall-cmd --reload
2.配置aliyun Yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3.安装开发工具组和依赖包
# yum -y groupinstall "development tools" # 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以上版本# tar vxf apr-1.6.3.tar.gz # cd apr-1.6.3 # ./configure --prefix=/usr/local/apr # make # make install # tar vxf 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
5.编译安装httpd2.4.33
# tar vxf httpd-2.4.33.tar.bz2 编译httpd之前把上一步解压出来的apr和apr-util文件复制到httpd-2.4.33/srclib/文件夹下,再进行httpd编译 # mv apr-1.6.3 httpd-2.4.33/srclib/apr # mv apr-util-1.6.1 httpd-2.4.33/srclib/apr-util # cd httpd-2.4.33 # ./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 # make # make install 配置以支持chkconfig控制 # cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd # vim /etc/rc.d/init.d/httpd 在第二行加入如下三行(前面的#号不能省略) # Comments to support chkconfig on RedHat Linux # chkconfig: 35 85 15 # description: Apache is a World Wide Web server. # chkconfig --add httpd # chkconfig httpd on # systemctl restart httpd # vim /etc/profile.d/httpd.sh export PATH=$PATH:/usr/local/apache/bin # source /etc/profile.d/httpd.sh
打开 http://192.168.10.10/ 可以看到httpd已经工作
6.编译安装Mariadb10.2.14
解压安装并指定解压路径/usr/local,创建软连接 # tar xvf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local # cd /usr/local # ln -s mariadb-10.2.14-linux-x86_64/ mysql 创建mysql用户,并指定家目录。 # mkdir /mysql # useradd -r -m -s /sbin/nologin -d /mysql/data mysql 生成mysql数据库 # /usr/local/mysql/scripts/mysql_install_db --datadir=/mysql/data --basedir=/usr/local/mysql --user=mysql 配置mysql的配置文件 # cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf # vim /etc/my.cnf ## 在[mysqld]节点下追加如下三行 [mysqld] datadir = /mysql/data innodb_file_per_table = ON skip_name_resolve = ON 配置以支持chkconfig控制 # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld # chkconfig --add mysqld # chkconfig mysqld on # systemctl restart mysqld 执行安全初始化数据库脚本 # /usr/local/mysql/bin/mysql_secure_installation # vim /etc/profile.d/mysqld.sh export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache/bin # source /etc/profile.d/mysqld.sh
7.编译安装PHP7.1.17
解决依赖 # yum install -y epel-release # yum -y install php-mcrypt libmcrypt libmcrypt-devel libxml2-devel 编译安装 # tar xvf php-7.1.17.tar.bz2 # cd php-7.1.17 # ./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 注意: php-7.0以上版本使用 –enable-mysqlnd –with-mysqli=mysqlnd ,原–with-mysql不再支持 # make # make install 提供php配置文件 # cp php.ini-production /etc/php.ini 编辑apache配置文件httpd.conf,以使apache支持php # vim /usr/local/apache/conf/httpd.conf 添加如下两行 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps 找到如下行并追加index.php 结果如下 DirectoryIndex index.html index.php 重启httpd服务以使配置生效 # systemctl restart httpd 测试httpd、mariadb、php是否能够协同工作 # rm -rf /usr/local/apache/htdocs/index.html # vim /usr/local/apache/htdocs/index.php <?php $mysqli=new mysqli("localhost","root","123456"); if(mysqli_connect_errno()){ echo "连接数据库失败!"; $mysqli=null; exit; } echo "连接数据库成功!"; $mysqli->close(); ?>
打开http://192.168.10.10/ 能看到"连接数据库成功!"即可,否则请检查错误。
8.编译安装php-memcached扩展
最新版Xcache3.2最高只支持到PHP 5.6,所以PHP7不在支持列表里,我以这里我们使用php-memcached来提供缓存功能编译安装libmemcached # yum -y install cyrus-sasl-devel # wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz # cd libmemcached-1.0.18 # ./configure --prefix=/usr/local/libmemcached --with-memcached --enable-sasl # make # make install 编译安装php-memcached # tar xvf memcached-3.0.4.tgz # cd memcached-3.0.4 # /usr/local/php/bin/phpize Configuring for: PHP Api Version: 20160303 Zend Module Api No: 20160303 Zend Extension Api No: 320160303 # ./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached # make # make install # echo "extension=memcached.so" >> /etc/php.ini # systemctl restart httpd
附录:软件下载地址
CentOS 7.4.1708 : http://mirrors.sohu.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.isohttpd-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
相关文章推荐
- CentOS6编译安装LAMP(CentOS6、httpd-2.4、php-7.1、mariadb-10.2、memcached-3.0.4)
- CentOS6 编译安装LAMP(Apache-httpd2.4,Mariadb,php)_2015092001
- CentOS6.8 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装
- LAMP组合的编译安装(httpd 2.4+mysql 5.5+php 5.4)
- Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.0 + Mariadb 10.1.9 + Nginx 1.9.9 + PHP 7.0.2)
- centos7 编译安装lamp php-7.1.0 +mysql-5.7.16 + httpd-2.4.23
- LAMP架构之编译安装httpd+(php-fpm)+mariadb
- 一台主机部署lamp(CentOS-7,httpd2.4,mariaDB,php-fpm)
- 基于fcgI编译安装LAMP实现层次化:httpd 2.4.9 + mysql-5.5.33 + php-5.4.26
- centos 6.2 ubuntu 12.04 上安装apache(httpd2.4) nginx1.2 php5.3.10 mysql5.3
- 安装潮流组合--LAMP+NFS(编译php-fpm模块与apache2.4结合)
- 编译安装LAMP之配置httpd以FastCGI方式与php整合
- CentOS 7.0 安装配置LAMP服务器方法(Apache+PHP+MariaDB)
- Centos5.9下编译安装LAMP(apache 2.4.4 mysql 5.6.10 php 5.4.12) 推荐
- CentOS6.8 x64+Nginx1.3.8/Apache-httpd 2.4.3+PHP5.4.8(php-fpm)+MySQL5.5.28+CoreSeek4.1源码编译安装
- CentOS 7.0安装配置LAMP服务器(Apache+PHP+MariaDB)
- CentOS 7.0系统安装配置LAMP服务器(Apache+PHP+MariaDB)
- httpd-2.4编译安装及新特性详解 --LAMP
- linux命令:编译安装httpd、mysql、php等LAMP环境xcache缓存PHP
- CentOS 7.0 安装配置LAMP服务器方法(Apache+PHP+MariaDB)