千家信息网

源码包搭建LAMP环境

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,第一步1、安装编译工具 gcc*安装数据库编译工具 cmake bisonyum -y install gcc* cmake bison2、下载LAMP压缩包:lamp.zip ,使用脚本批量解压 t
千家信息网最后更新 2026年11月01日源码包搭建LAMP环境

第一步

1、安装编译工具 gcc*

安装数据库编译工具 cmake bison

yum -y install gcc* cmake bison

2、下载LAMP压缩包:lamp.zip ,使用脚本批量解压 tar.sh

3、关闭防火墙、Selinux

第二步

分别编译安装各个源码包(共有17个包)

1、可以直接安装的源码包

2.1、 # 安装libxml2

先安装 yum -yinstall python-devel

mkdir /usr/local/libxml2/

cd /lamp/libxml2-2.9.1

./configure--prefix=/usr/local/libxml2/ && make&& make install

2.2、# 安装libmcrypt

mkdir /usr/local/libmcrypt/

cd /lamp/libmcrypt-2.5.8

./configure --prefix=/usr/local/libmcrypt/ && make && make install

2.3、# 安装libltdl

也在libmcrypt源码目录中

cd/lamp/libmcrypt-2.5.8/libltdl

./configure--enable-ltdl-install && make && make install

2.4、# 安装 mhash

cd /lamp/mhash-0.9.9.9

./configure && make && make install

2.5、# 安装mcrypt

cd/lamp/mcrypt-2.6.8

LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib ./configure

--with-libmcrypt-prefix=/usr/local/libmcrypt

make && make install

2.6、# 安装zlib

cd /lamp/zlib-1.2.3

./configure

vi Makefile

将 CFLAGS=-O3 -DUSE_MMAP

修改为CFLAGS=-O3 -DUSE_MMAP -fPIC

make&& make install

2.7、# 安装libpng

mkdir /usr/local/libpng/

cd /lamp/libpng-1.2.31

./configure--prefix=/usr/local/libpng/ && make&& make install

2.8、# 安装jpeg6

必须先安装 yum -y install"libtool*"

mkdir/usr/local/jpeg6

mkdir/usr/local/jpeg6/bin

mkdir/usr/local/jpeg6/lib

mkdir/usr/local/jpeg6/include

mkdir -p /usr/local/jpeg6/man/man1

cd /lamp/jpeg-6b

cp /usr/share/libtool/config/config.sub .

cp /usr/share/libtool/config/config.guess

#复制libtool中的文件,覆盖jpeg-6b中的文件(64位中的问题,32位没有此报错)

cd /lamp/jpeg-6b

./configure--prefix=/usr/local/jpeg6/ --enable-shared --enable-static

make &&make install

2.9、 # 安装freetype

cd/lamp/freetype-2.3.5

./configure--prefix=/usr/local/freetype/ && make && make install

2.10、# 安装ncurses

yum -y install ncurses-devel

注:如果报错,包找不到,是*通配符没有识别,给文件名加双引号 "ncurses*"

cd/lamp/ncurses-5.9

./configure--with-shared --without-debug --without-ada --enable-overwrite

make && make install

2、重量级源码包

2.11、# 安装Apache

configure: error: Bundled APR requested but not found at ./srclib/.Download and unpack the corresponding apr and apr-util packages to ./srclib/.

#如果报错,则:

tar zxvf apr-1.4.6.tar.gz

tar zxvf apr-util-1.4.1.tar.gz 解压过

cp -r /lamp/apr-1.4.6 /lamp/httpd-2.4.7/srclib/apr

cp -r /lamp/apr-util-1.4.1 /lamp/httpd-2.4.7/srclib/apr-util

#解压apr和apr-util,复制并取消版本号

configure: error: pcre-config for libpcre not found. PCRE isrequired and available from

#如果报错,则:

tar zxvf pcre-8.34.tar.gz

cd /lamp/pcre-8.34

./configure && make&& make install

checking whether to enablemod_ssl... configure: error: mod_ssl has been requested but can not be builtdue to prerequisite failures

#如果报错,则:

yum install openssl-devel

安装apache

cd /lamp/httpd-2.4.7

./configure --prefix=/usr/local/apache2/ \

--sysconfdir=/usr/local/apache2/etc/ \

--with-included-apr--enable-so --enable-deflate=shared \

--enable-expires=shared--enable-rewrite=shared

make

make install

* 若前面配置zlib时没有指定安装目录,Apache配置时不要添加--with-z=/usr/local/zlib/参数

启动Apache测试:

/usr/local/apache2/bin/apachectlstart

ps aux| grep httpd

netstat -antp | grep :80

可以使用脚本将apache像httpd一样启动

cat apache.sh

#!/bin/bash

#chkconfig管理apache服务

#chkconfig:- 82 15

#discription:

path=/usr/local/apache2/bin/apachectl

case $1 in

start)

$path start

;;

stop)

$path stop

;;

restart)

$path stop

sleep 3s

$path start

;;

configtest)

$path -t

;;

*)

echo"pleas input start |stop | restart |configtest ."

;;

esac

mv apache.sh /etc/init.d/httpd

chmod 755 httpd

service httpd start

* 若启动时提示/usr/local/apache2/modules/mod_deflate.so无权限,可关闭SELinux或者执行命令chcon -t texrel_shlib_t/usr/local/apache2/modules/mod_deflate.so ,类似此类.so文件不能载入或没有权限的问题,都是SELinux问题,使用命令:"chcon -t texrel_shlib_t 文件名"即可解决,MySQL和Apache也可能有类似问题。

通过浏览器输入地址访问:http://Apache服务器地址,若显示"It works"即表明Apache正常工作

设置Apache系统引导时启动:开机自启动

echo "/usr/local/apache2/bin/apachectlstart" >> /etc/rc.d/rc.local

注:安装完成后,先启动apache进行服务验证,是否安装成功,并且主页是否可以访问。

注:发现启动服务报错:AH00558: httpd: Could not reliably determine the server's fullyqualified domain name, using localhost.localdomain. Set the 'ServerName' directiveglobally to suppress this message

解决办法:打开主配置文件 /usr/local/apache/etc/httpd.conf

搜索ServerName (约在200行左右)

修改为 ServerName localhost:80(并且去掉前面的#注释)

2.12、# 安装MySQL

useradd -r -s /sbin/nologin mysql

mkdir /usr/lo cal/mysql -p

* 创建系统用户mysql

cd /lamp/mysql-5.5.48

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql 安装位置

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 指定socket(套接字)文件位置

-DEXTRA_CHARSETS=all 扩展字符支持

-DDEFAULT_CHARSET=utf8 默认字符集

-DDEFAULT_COLLATION=utf8_general_ci 默认字符校对

-DWITH_MYISAM_STORAGE_ENGINE=1 安装myisam存储引擎

-DWITH_INNOBASE_STORAGE_ENGINE=1 安装innodb存储引擎

-DWITH_MEMORY_STORAGE_ENGINE=1 安装memory存储引擎

-DWITH_READLINE=1 支持readline库

-DENABLED_LOCAL_INFILE=1 启用加载本地数据

-DMYSQL_USER=mysql 指定mysql运行用户

-DMYSQL_TCP_PORT=3306 指定mysql端口

make

make install

makeclean

rmCMakeCache.txt

#如果报错,清除缓存,请使用以上命令

cd/usr/local/mysql/

chown -R root .

chown -R mysql data

#修改mysql目录权限

cp support-files/my-medium.cnf /etc/my.cnf

#复制mysql配置文件

/usr/local/mysql/scripts/mysql_install_db --user=mysql

#创建数据库授权表,初始化数据库

启动MySQL服务:

1.用原本源代码的方式去使用和启动mysql

/usr/local/mysql/bin/mysqld_safe --user=mysql &

2.重启以后还要生效:

vim /etc/rc.local

/usr/local/mysql/bin/mysqld_safe --user=mysql &

3.设定mysql密码

/usr/local/mysql/bin/mysqladmin -urootpassword 123456

清空历史命令 history -c

* 给mysql用户root加密码123

* 注意密码不能写成太简单,做实验随便

/usr/local/mysql/bin/mysql -u root -p

mysql>show databases;

mysql>use test;

mysql>show tables;

mysql>\s #查看字符集是否改为utf8

* 进入mysql以后用set来改密码

mysql> exit

* 登录MySQL客户端控制台设置指定root密码

2.13、# 安装PHP

编译前确保系统已经安装了libtool和libtool-ltdl软件包,安装:

yum -yinstall "libtool*"

mkdir/usr/local/php/etc/ -p

cd/lamp/php-7.0.7

./configure--prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/--with-apxs2=/usr/local/apache2/bin/apxs --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/--with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/--with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config--enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql--with-gd --without-pear

l 若前面配置zlib时没有指定安装目录,PHP配置时不要添加--with-zlib-dir=/usr/local/zlib/参数

选项:

--with-config-file-path=/usr/local/php/etc/ 指定配置文件目录

--with-apxs2=/usr/local/apache2/bin/apxs 指定apache动态模块位置

--with-libxml-dir=/usr/local/libxml2/ 指定libxml位置

--with-jpeg-dir=/usr/local/jpeg6/ 指定jpeg位置

--with-png-dir=/usr/local/libpng/ 指定libpng位置

--with-freetype-dir=/usr/local/freetype/ 指定freetype位置

--with-mcrypt=/usr/local/libmcrypt/ 指定libmcrypt位置

--with-mysqli=/usr/local/mysql/bin/mysql_config 指定mysqli位置

--with-gd 启用gd库

--enable-soap 支持soap服务

--enable-mbstring=all 支持多字节,字符串

--enable-sockets 支持套接字

--with-pdo-mysql=/usr/local/mysql 启用mysql的pdo模块支持

--without-pear 不安装pear(安装pear需要连接互联网。

make

make install

生成php.ini

cp /lamp/php-7.0.7/php.ini-production /usr/local/php/etc/php.ini

测试Apache与PHP的连通性,看Apache是否能解析php文件

vim /usr/local/apache2/etc/httpd.conf

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

AddType application/x-httpd-php-source .phps

(注意大小写)

* .phtml为将.phps做为PHP源文件进行语法高亮显示

重启Apache服务:/usr/local/apache2/bin/apachectl stop

/usr/local/apache2/bin/apachectl start

* Apache无法启动,提示cannot restore segmentprot after reloc: Permission denied错误,为SELinux问题,可关闭SELinux或者执行命令chcon -ttexrel_shlib_t /usr/local/apache2/modules/libphp5.so

测试:vim /usr/local/apache2/htdocs/test.php

phpinfo();

?>

通过浏览器输入地址访问:http://Apache服务器地址/test.php

Rpm包安装的网页默认目录 /var/www/html/

* 有时第一次浏览器测试会失败,关闭浏览器重启再尝试即可,非编译错误

2.14、# 安装openssl

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。

yum-y install openssl-devel 必须安装

cd/lamp/php-7.0.7/ext/openssl

mvconfig0.m4 config.m4 否则报错:找不到config.m4

PATH=$PATH:/usr/local/php/bin/(临时) vi /etc/profile

cd/lamp/php-7.0.7/

./configure--with-openssl --with-php-config=/usr/local/php/bin/php-config

make

makeinstall

2.15、# 编译安装pecl

Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash表,它能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。简单的说就是将数据调用到内存中,然后从内存中读取,从而大大提高读取速度。

https://github.com/websupport-sk/pecl-memcache/archive/php7.zip

unzip pecl-memcache-php7.zip

cd pecl-memcache-php7

/usr/local/php/bin/phpize 这是一个命令 ,用于生成一个配置目录

./configure--with-php-config=/usr/local/php/bin/php-config

make && make install

修改/usr/local/php/etc/php.ini

extension_dir ="/usr/local/php/lib/php/extensions/no-debug-zts-20151012/"

#打开注释,并修改

extension="openssl.so";

extension="memcache.so";

修改位置

#添加

#重启apache,在phpinfo中可以找到这个模块

2.16、#安装memcache源代码

首先安装依赖包libevent

yum -yinstall libevent-devel

#在CentOS 6.3第二张光盘中,请换盘

umount/mnt/cdrom

#放入CentOS 6.3第二张光盘

#mount/dev/sr0 /mnt/cdrom

mkdir /usr/local/memcache

cd/lamp/memcached-1.4.17

./configure--prefix=/usr/local/memcache

make && makeinstall

useradd memcache

#添加memcache用户,此用户不用登录,不设置密码

/usr/local/memcache/bin/memcached-umemcache &

netstat -an | grep:11211

写入自启动:

vi/etc/rc.d/rc.local

/usr/local/memcache/bin/memcached-umemcache &

第三步、项目迁移

1、把php项目拷贝到网站默认目录下: /usr/local/apache2/htdocs/

2、手工建立数据库表结构

第四步、安装phpMyAdmin (给php管理添加用户)

cp -r /lamp/phpMyAdmin-4.1.4-all-languages/usr/local/apache2/htdocs/phpmyadmin

cd/usr/local/apache2/htdocs/phpmyadmin

cpconfig.sample.inc.php config.inc.php

vim config.inc.php

$cfg['Servers'][$i]['auth_type']= 'cookie';

$cfg['Servers'][$i]['auth_type']= 'http';

以上两行都有

* 设置auth_type为http ,即设置为HTTP身份认证模式

通过浏览器输入地址访问:http://Apache服务器地址/phpmyadmin/index.php

用户名为root ,密码为MySQL设置时指定的root密码123456(lampbrother)


文件 位置 密码 服务 数据 目录 配置 用户 命令 地址 支持 编译 字符 数据库 果报 浏览器 问题 测试 浏览 源码 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 喔噻互联网科技有限公司 互联网科技网 中国互联网科技工作委员会毛军 重庆互联网络科技 易互联网科技有限公司 互联网金融 金融科技 互联网 视角下的科技创新 齐家互联网科技有限公司 太原新华互联网科技学校怎么样 山东吉时兔互联网科技有限公司 互联网公司会议桌创意科技软装饰 互联网科技中介 西安小鹰速贷互联网科技有限公司 华夏恒生科技与互联网科技 2021互联网科技公司排名 江苏互联网科技小贷 2021世界互联网领先科技成果发布 版纳互联网科技选哪家 互联网公司属于科技吗 盐城市攀科互联网科技有限公司 科技创新与互联网经济 华宇互联网科技 丰台科技园 互联网 沃里互联网科技 哈尔滨秒房互联网科技有限公司 杭州壁岐互联网科技有限公司 厦门江牛科技互联网 互联网相关科技技术 科技互联网经济论坛 伍佰万互联网科技是干嘛的
0