在centos6上编译安装LAMP

最近学习到编译安装LAMP写下这篇文章,以总结学习

环境centos6.10,本次编译安装顺序:apache、mariadb、PHP

apache用2.4,mariadb用5.5.43,php用5.5.30,apache要用到apr以及apr-util包,apr包用1.5.0,apr-util包用1.5.3

apr及apr-util下载地址:http://archive.apache.org/dist/apr/

php,apache,mariadb下载地址:ftp://ftp.gufeng123.xyz

apache服务依赖于apr,apr-util模块,我们先编译apr,apr-util模块

安装编译环境:yum groupinstall "Development Tools" "Server Platform Development" -y 

tar xf apr-1.5.0.tar.bz2

cd apr-1.5.0

./configure --prefix=/usr/local/apr建立makefile文件,-prefix指定apr安装目录

make && make install make会依据makefile文件中的默认行为进行编译的行为,make install 会依据makefile文件中关于install的选项,将上一步所编译完成的数据安装到指定的目录中

tar xf apr-util-1.5.3.tar.bz2

cd apr-util-1.5.3

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr--with-apr表示依赖于apr包

make && make install

接下来编译apache:

先解决依赖关系:

yum install -y pcre-devel

tar xf httpd-2.4.10.tar.bz2

cd httpd-2.4.10

./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event --prefix指定安装目录,--sysconfdir指定配置文件目录

创建makefile时遇到上图错误,ls /usr/lcoal/apr-util/bin可以看到存在配置文件,仔细一看上面命令写错了,郁闷

./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=event

make && make install

httpd启动脚本下载地址:ftp.gufeng123.xyz

将启动脚本复制到/etc/init.d/目录下,编辑httpd启动脚本:

指定lockfile文件/var/lock/subsys/httpd

vim /etc/profile将apache相关命令加入环境变量

上面这种对于所有用户都有效,也可以编辑家目录下的.bash_profile文件

然后执行source命令,重新载入环境变量

httpd -t可以看到如下错误:

vim /etc/httpd/httpd.conf将ServerName前面的#号去掉解决

 

chkconfig --add httpd将httpd服务加入脚本

service httpd start

service httpd status 

ss -ntl查看监听端口

iptables -F清空防火墙规则

setenforce 0将selinux设置为permissive

下面开始编译mariadb数据库:

准备工作:

mkdir /mysql/data -p创建mariadb数据目录

groupadd -r -g 306 mysql -r新建系统用户组,-g指定gid

useradd -r -g 306 -u 306 mysql -r创建系统用户,-g指定初始组,-u指定用户uid

tar xf mariadb-5.5.43-linux-x86_64.tar.gz

 mv mariadb-5.5.43-linux-x86_64 /usr/local/mysql

cd /usr

ln -sv local/mysql mysql

cd mysql

chown -R mysql.mysql ./*

scripts/mysql_install_db --datadir=/mysql/data --user=mysql

下面编辑mariadb配置文件

vim /etc/mysql/my.cnf加入如下三项:

datadir表明mariadb到哪儿去找数据文件

innodb_fileper_table表明指定=innodb引擎

skip_name_resolve跳过名称解析

制作mariadb启动脚本

vim /etc/init.d/mysqld

basedir安装目录,datadir数据目录

chkconfig --add mysqld

service mysqld start

service sattus mysqld

ss -ntl

同理将mysql中的bin目录加入环境变量中

最后编译安装php:

1、先安装配置epel源

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

2、解决依赖关系:

yum install –y libxml2 libxml2-devel bzip2-devel

./configure --prefix=/usr/local/php --with-mysql=/usr/mysql/ --with-openssl --with-mysqli=/usr/mysql/bin/mysql_config --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 --with-bz2 --enable-maintainer-zts

--prefix php安装目录

--with-mysql告诉php,mysql安装目录

--with-openssl系统初始安装了openssl不用指定目录,与openssl交互,没有目录表示默认

--with-mbstring让php支持多字节,汉字

--with-freetype-dir让php支持freetype一种字体格式

--with-mysqliphp中的另一个跟mysql交互的接口

--with-jpeg-dir 使php支持jpeg  --with-png-dir同理

--with-zlib压缩库

--with-libxml-dir让php支持xml文件  --enable-xml 启用xml功能

--with-sockets表示php支持用sockets进行通信

--with-apxs2=/usr/local/apache/bin/apxs表示将php编译成apache一个apxs模块

--with-mcrypt加解密库

--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d表示配置文件的目录,以及扩展配置文件目录

--with-bz2以bz2进行加密

--enable-maintainer-zts表示编译成zts模块,worker以及event需要该模块

创建makefile时遇到错误:

yum install -y libmcrypt-devel解决问题

make && make install

这个安装有点久等的我花儿都谢了,为php提供配置文件cp php.ini-production /etc/php.ini

编辑httpd.conf文件,让apache支持php

vim /etc/httpd/httpd.conf加入如下内容

httpd -M查看apache装载的模块

vim /usr/local/apache/htdocs/index.php在网站根目录下编辑测试文件,加入如下内容:

<?php
$conn=mysql_connect('127.0.0.1','root','');
if($conn)
        echo "ok";
        else
        echo "not ok";
phpinfo();
?>

在宿主游览器输入centos6的地址出现如下内容,搭建成功

测试前记得要关闭selinux,清空防火墙,遇到not found的问题,yum安装原包或者在原包后面加上-devel可以解决大多数问题,至于其他问题遇到的可以找我探讨QQ2797731632,本人也是萌新

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值