源码编译搭建LAMP架构

简介 源码编译搭建LAMP架构

 

源码编译搭建LAMP架构


LAMP=Linux + Apache + MySQL + PHP 

源码安装和rpm安装对比

rpm:安装、部署管理比较方便运行稳定版本较低,功能和性能较差

源码:安装、部署、管理比较麻烦,运行相对不稳定;版本较新,功能和性能较高 

Apache官网

http://httpd.apache.org/ 

需要源码编译安装的软件包

httpd-2.4.25.tar.gz #Apache主程序包

apr-1.5.2.tar.gz #Apache依赖  可移植运行库

apr-util-1.5.4.tar.gz #Apache依赖包  可移植运行库

pcre-8.38.zip #Apache依赖包  是一个Perl库,包括 perl 兼容的正则表达式库

下载源码安装包

http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.25.tar.gz

http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz

http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz

https://sourceforge.net/projects/pcre/files/pcre/8.38/pcre-8.38.tar.gz

 

安装之前请先安装make、gccopenssl等编译工具开发包

 

安装之前确定已经配置好 网络yum源、epel源

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

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

 

[[email protected]wuwuseo ~]# yum -y install make gcc gcc-c++ openssl openssl-devel

编译安装依赖包apr-1.5.2.tar.gz

[[email protected]wuwuseo ~]# tar zxvf apr-1.5.2.tar.gz

[[email protected]wuwuseo ~]# cd apr-1.5.2

[[email protected]wuwuseo apr-1.5.2]# ./configure --prefix=/usr/local/apr

#有报错编辑configureRM='$RM'改为RM='$RM  -f'

[[email protected]wuwuseo apr-1.5.2]# make && make install 

扩展  查看CPU数cat /proc/cpuinfo| grep "processor"| wc -l

编译安装依赖包apr-util-1.5.4.tar.gz

[[email protected]wuwuseo ~]# tar zxvf apr-util-1.5.4.tar.gz

[[email protected]wuwuseo ~]# cd apr-util-1.5.4

[[email protected]wuwuseo apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util/ \

--with-apr=/usr/local/apr/bin/apr-1-config

安装apr-util之前必须安装apr。

     如在已经安装apr的前提下安装apr-util,进入apr-util的解压目录然后执行以下命令:

     ./configure  --prefix=你要安装的目录  --with-apr=你的apr安装的目录

[[email protected]wuwuseo apr-util-1.5.4]# make && make install

 

编译安装依赖包pcre-8.38. tar.gz

[[email protected]wuwuseo ~]# tar zxf pcre-8.38.tar.gz

[[email protected]wuwuseo ~]# cd pcre-8.38

[[email protected]wuwuseo pcre-8.38]# ./configure --prefix=/usr/local/pcre

报错:configure: error: You need a C++ compiler for C++ support.需要C++支持

安装yum y install gcc-c++

[[email protected]wuwuseo pcre-8.38]# make -j 4 && make install

 

编译安装Apache

[[email protected]wuwuseo httpd-2.4.25]# tar zxvf httpd-2.4.25.tar.gz -C /usr/local/src/

[[email protected]wuwuseo httpd-2.4.25]# cd /usr/local/src/httpd-2.4.25/

[[email protected]wuwuseo httpd-2.4.25]# ./configure

 --prefix=/usr/local/apache

 --enable-so --enable-rewrite

 --enable-ssl

 --with-apr=/usr/local/apr

 --with-apr-util=/usr/local/apr-util/

 --with-pcre=/usr/local/pcre/

 

[[email protected]wuwuseo httpd-2.4.25]# make && make install

 

注:

--enable-so #支持动态加载模块

--enable-rewrite #支持网站地址重写

--enable-ssl #支持ssl加密

--with-apr=/usr/local/apr #关联apr

--with-apr-util=/usr/local/apr-util #关联apr-util

--with-pcre=/usr/local/pcre #关联pcre

配置文件

[[email protected]wuwuseo ~]# ls /usr/local/apache/conf/httpd.conf

/usr/local/apache/conf/httpd.conf

网站根目录

[[email protected]wuwuseo ~]# ls /usr/local/apache/htdocs/

index.html

生成启动脚本

[[email protected]wuwuseo ~]# cp /usr/local/apache/bin/apachectl /etc/init.d/

[[email protected]wuwuseo ~]# chmod +x /etc/init.d/apachectl

[[email protected]wuwuseo ~]# vim !$

写入

#!/bin.sh

# chkconfig:345 64 36

# description:man apache server

345是启动级别;64是启动优先级;36是关闭的优先级;

两行是必不可少的,后面是描述信息

服务添加到系统启动列表中

[[email protected]wuwuseo ~]# chkconfig --add apachectl

[[email protected]wuwuseo ~]# chkconfig apachectl on

[[email protected]wuwuseo ~]# chkconfig --list apachectl

apachectl       0:off  1:off 2:on   3:on 4:on 5:on   6:off

启动服务

[[email protected]wuwuseo ~]# service apachectl start 

源码编译mysql     

下载地址

https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-boost-5.7.18.tar.gz 

MySQL5.7版本之后,boost是必须的,建议把系统自带的boost库卸载源码编译安装高版本

Boost库是为C++语言标准库提供扩展的一些C++程序库的总称

[[email protected]wuwuseo ~]# yum -y remove boost-*

卸载系统自带mysql

[[email protected]wuwuseo ~]# yum -y remove mysql 

安装必要的资源包

建议使用网络yum源,RHEL6.5光盘中自带的软件包版本不够,mysql-boost-5.7.18.tar.gz的编译对软件包的版本要求比较,其中cmake的版本要不低于2.8

安装依赖包

yum install -y cmake make gcc gcc-c++ bison ncurses ncurses-devel 

添加用户和组

[[email protected]wuwuseo ~]# groupadd mysql

[[email protected]wuwuseo ~]# useradd -M -s /sbin/nologin -r -g mysql mysql

创建安装目录和数据存放目录

[[email protected]wuwuseo ~]# mkdir -p /server/mysql/

生产环境添加一块新的硬盘创建分区sdb1并分配所有的空间

[[email protected]wuwuseo ~]# mkdir /server

[[email protected]wuwuseo ~]# mount /dev/sdb1 /server/

开机自动挂载

[[email protected]wuwuseo ~]# echo "/dev/sdb1 /server ext4 defaults 0 0"  >> /etc/fstab

上传源码 并解压源码

[[email protected]wuwuseo]# tar zxf mysql-boost-5.7.18.tar.gz

boost移到/server/mysql

[[email protected]wuwuseo server]# mv boost/ /server/mysql/

[[email protected]wuwuseo ~]# cd mysql-5.7.18

[[email protected]wuwuseo mysql-5.7.11]#cmake -DCMAKE_INSTALL_PREFIX=/server/mysql \

-DMYSQL_DATADIR=/server/mysql/data \

-DSYSCONFDIR=/etc \

-DMYSQL_UNIX_ADDR=/server/mysql/mysql.sock \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_MEMORY_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DMYSQL_UNIX_ADDR=l \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/server/mysql/boost

这些编译参数的帮助寻找方法:

http://www.mysql.com→→Documentation→→选择对应的版本(5.7)Installation & Upgrades→→Installing MySQL from Source →→MySQL Source-Configuration Options

最终的URL https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html               

 

DCMAKE_INSTALL_PREFIX:指定MySQL程序的安装目录,默认/usr/local/mysql
DEFAULT_CHARSET:指定服务器默认字符集,默认latin1
DEFAULT_COLLATION:指定服务器默认的校对规则,默认latin1_general_ci
ENABLED_LOCAL_INFILE:指定是否允许本地执行LOAD DATA INFILE,默认OFF
WITH_COMMENT:指定编译备注信息
WITH_xxx_STORAGE_ENGINE:指定静态编译到mysql的存储引擎,MyISAM,MERGE,MEMBER以及CSV四种引擎默认即被编译至服务器,不需要特别指定。
WITHOUT_xxx_STORAGE_ENGINE:指定不编译的存储引擎
SYSCONFDIR:初始化参数文件目录
MYSQL_DATADIR:数据文件目录
MYSQL_TCP_PORT:服务端口号,默认3306
MYSQL_UNIX_ADDR:socket文件路径,默认/tmp/mysql.sock

 

编译

mysql-5.7.18.tar.gz编译时会占用大量的系统资源建议使用个核心同时进行编译,否则可能会编译失败

[[email protected]wuwuseo mysql-5.7.11]# make

make -j 4   #注:-j 用来指定CPU核心数,可加快编译速度。 加 -j 4我用4核心来编译的,可以提高编译速度;当然你要确定CPU多少核心

查看服务器CPU核心数

[[email protected]wuwuseo ~]# grep processor /proc/cpuinfo | wc -l

安装

[[email protected]wuwuseo mysql-5.7.18]# make install

修改目录权限

[[email protected]wuwuseo ~]# chown -R mysql:mysql  /server/mysql/

 

生成配置文件

[[email protected]wuwuseo ~]# mv /etc/my.cnf{,.bak}

新版本没有这项#[[email protected]wuwuseo ~]# cp /server/mysql/support-files/my-default.cnf  /etc/my.cnf

我们写一个my.cnf文件 vim /etc/my.cnf

[mysqld]

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#default

user = mysql

basedir = /server/mysql

datadir = /server/mysql/data

port = 3306

pid-file = /server/mysql/data/mysql.pid

socket = /server/mysql/mysql.sock

character-set-server=utf8

[client]

socket = /server/mysql/mysql.sock

 

生成服务启动脚本

[[email protected]wuwuseo ~]#

cp /server/mysql/support-files/mysql.server /etc/init.d/mysqld

[[email protected]wuwuseo ~]# chmod +x /etc/init.d/mysqld

[[email protected]wuwuseo ~]# chkconfig --add mysqld

[[email protected]wuwuseo ~]# chkconfig mysqld on

[[email protected]wuwuseo ~]# chkconfig --list mysqld

mysqld          0:off 1:off 2:on 3:on 4:on 5:on 6:off

 

初始化数据库

[[email protected]wuwuseo ~]# /server/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/server/mysql --datadir=/server/mysql/data 

 

启动服务

[[email protected]wuwuseo ~]# service mysqld start

Starting MySQL                                             [  OK  ]

 

添加path路径: vim /etc/profile 添加下面2行 在文件的结尾

export MYSQL_HOME=/server/mysql

export PATH=$PATH:$MYSQL_HOME/bin

使修改生效

source /etc/profile

[[email protected]wuwuseo ~]# ln -s /server/mysql/bin/* /usr/local/bin/

 

排错:pid错 sock错,vim  /etc/my.cnf

[mysqld]

 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

#default

user = mysql

basedir = /server/mysql

datadir = /server/mysql/data

port = 3306

#pid-file = /server/mysql/data/mysql.pid

socket = /server/mysql/mysql.sock

character-set-server=utf8

[client]

socket = /server/mysql/mysql.sock


修改mysql密码

[[email protected]wuwuseo ~]# mysqladmin -u root password "123456"

[[email protected]wuwuseo ~]# mysql

mysql> set password=password('123456');

 

源码编译安装php7.1.4

官网地址:http://php.net/

源码包下载地址

http://cn.php.net/distributions/php-7.1.4.tar.gz

安装epel扩展yum源

[[email protected]wuwuseo ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

[[email protected]wuwuseo ~]# yum clean all

[[email protected]wuwuseo ~]# yum list

RHEL光盘CentOS源少很多软件包,建议使用扩展源进行安装依赖包

如果扩展源不能用,用本地yum源

 

安装所需依赖包

[[email protected]wuwuseo ~]# yum -y install php-mcrypt libmcrypt libmcrypt-devel  autoconf  freetype gd libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel


修复 rpm freetype 没起作用

安装freetype

下载地址:http://ring.u-toyama.ac.jp/archives/graphics/freetype/freetype2/ 

[[email protected]wuwuseo]# cd freetype-2.7.1

[[email protected]wuwuseo freetype-2.7.1]#./configure --prefix=/usr/local/freetype --enable-shared

 [[email protected]wuwuseo freetype-2.7.1]# make

[[email protected]wuwuseo freetype-2.7.1]# make install

 

配置相关参数

[[email protected]wuwuseo php-7.1.4]#./configure --prefix=/server/php7/ \

--with-apxs2=/usr/local/apache/bin/apxs \

--enable-mbstring \

--with-curl \

--with-gd \

--enable-fpm \

--enable-mysqlnd  \

--with-pdo-mysql=mysqlnd \

--with-config-file-path=/server/php7/etc/ \

--with-mysqli=mysqlnd \

--with-freetype-dir=/usr/local/freetype/ \

--with-mysql-sock=/server/mysql/mysql.sock

 

注:

--with-apxs2 #将php编译为Apache的一个模块进行使用

--enable-mbstring #多字节字符串的支持

--with-curl #支持cURL

--with-gd #支持gd库

--enable-fpm #支持构建fpm

--enable-mysqlnd   #启用mysqlnd

--with-pdo-mysql #支持pdo:MySQL支持

--with-config-file-path #设置配置文件路径

--with-mysqli #支持MySQLi

--with-mysql-sock #关联mysql的socket文件 

编译

[[email protected]wuwuseo php-7.1.4]# make

安装

[[email protected]wuwuseo php-7.1.4]# make install

生成配置文件

[[email protected]wuwuseo php-7.1.4]# cp php.ini-production /server/php7/etc/php.ini

 

添加Apache支持

[[email protected]wuwuseo php-7.1.4 vim /usr/local/apache/conf/httpd.conf

Addtype application/x-httpd-php .php .phtml

 

创建测试页面

[[email protected]wuwuseo php-7.1.4]# cd /usr/local/apache/htdocs/

[[email protected]wuwuseo htdocs]# vim a.php

<?php

        phpinfo();

?>

 


 


文章评论