CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)环境
一、简介
什么是LAMP
LAMP是一种Web网络应用和开发环境,是Linux, Apache, MySQL, Php/Perl的缩写,每一个字母代表了一个组件,每个组件就其本身而言都是在它所代表的方面功能非常强大的组件。
LAMP这个词的由来最早始于德国杂志“c't Magazine”,Michael Kunze在1990年最先把这些项目组合在一起创造了LAMP的缩写字。这些组件并不是开始就设计为一起使用的,但是,这些软件都是开源的,可以很方便的随时获得并免费使用,这就导致了这些组件经常在一起使用。这些组件的兼容性也在不断完善,为了改善不同组件之间的协作,已经创建了某些扩展功能,在一起的应用情形变得非常普便,因而成为目前最流行的web应用基础架构。
LAMP的组件
平台由四个组件组成,呈分层结构,每一层都提供了整个架构的一个关键部分:
Linux:Linux 处在最底层,提供操作系统。它的灵活性和可定制化的特点意味着它能够产生一种高度定制的平台,让其它组件在上面运行。其它组件运行于Linux 之上,但是并不一定局限于 Linux,也可以在 Microsoft Windows, Mac OS X 或 UNIX上运行。
Apache:Apache位于第二层,它是一个Web 服务平台,提供可让用户获得 Web 页面的机制。Apache 是一款功能强大、稳定、可支撑关键任务的Web服务器,Internet 上超过 50% 的网站都使用它作为 Web 服务器。
MySQL:MySQL 是最流行的开源关系数据库管理系统,是LAMP的数据存储端。在 Web 应用程序中,所有帐户信息、产品信息、客户信息、业务数据和其他类型的信息都存储于数据库中,通过 SQL 语言可以很容易地查询这些信息。
PHP/Perl:Perl是一种灵活的语言,特别是在处理文本要素的时候,这种灵活性使Perl很容易处理通过 CGI接口提供的数据,灵活地运用文本文件和简单数据库支持动态要素。PHP 是一种被广泛应用的开放源代码的多用途脚本语言,它可嵌入到 HTML中,尤其适合 web 开发。可以使用 PHP 编写能访问 MySQL 数据库中的数据和 Linux 提供的一些特性的动态内容。
二、系统环境
系统平台:CentOS release 5.8 (Final)
Apache版本:httpd-2.2.9.tar.gz
Mysql 版本:mysql-5.0.41.tar.gz
Php版本:php-5.2.6.tar.gz
三、安装前准备
1、库文件准备
在安装PHP之前,应先安装PHP5需要的最新版本库文件,例如libxml2、libmcrypt以及GD2库等文件。安装GD2库是为了让PHP5支 持GIF、PNG和JPEG图片格式,所以在安装GD2库之前还要先安装最新的zlib、libpng、freetype和jpegsrc等库文件。而且中间还会穿插安装一些软件,读者可以按照本节提供的顺序安装。
autoconf-2.61.tar.gz
freetype-2.3.5.tar.gz
gd-2.0.35.tar.gz
jpegsrc.v6b.tar.gz
libmcrypt-2.5.8.tar.gz
libpng-1.2.31.tar.gz
libxml2-2.6.30.tar.gz
zlib-1.2.3.tar.gz
ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
2、安装gcc、gcc-c++编译器
用gcc -v 命令检查安装时使用的编译工作是否存在
如系统未安装,在系统联网的情况下使用yum install gcc和yum install gcc-c++安装
3、卸载默认的低版本环境
目前发行的Linux操作系统版本中,如果选择默认全部安装,就已经安装了LAMP环境,但是版本相对都比较低。我们可以再安装一个LAMP环境和原来的并存,但是这样做没有必要,因为同时只能开启一个LAMP环境。所要我们要在安装之前,先应检查一下系统中是否已经安装了低版本的环境,如果已经安装过了,停止原来的服务运行,或者把原来的环境卸载掉。
a. 卸载Apache
# rpm -qa | grep httpd
说明:检查是否安装了httpd软件包
# rpm -e httpd-2.2.3-63.el5.centos --nodeps
说明:卸载软件包, --nodeps 如果有连带关系,也强制卸载
# cd /etc/httpd/
# rm -rf *
说明:到原来的apache安装目录下,将其所有的安装目录和文件都删掉
b. 卸载Mysql
# rpm -qa | grep mysql
# rpm -e mysql-5.0.77-4.el5_4.2 --nodeps
说明:卸载mysql
c. 卸载Php
# rpm -qa | grep php
# rpm -e php-common-5.1.6-27.el5 --nodeps
# rpm -e php-ldap-5.1.6-27.el5 --nodeps
# rpm -e php-cli-5.1.6-27.el5 --nodeps
# rpm -e php-5.1.6-27.el5 --nodeps
说明:卸载PHP
4、关闭selinux,清空防火墙规则
5、使用ssh shell将windows下的13个源码包上传到/usr/local/src
6、解包
编写一个shell脚本tar.sh进行解包。
#!/bin/sh cd /usr/local/srcls *.tar.gz > ls.list for TAR in `cat ls.list` dotar -zxvf $TARdone
执行脚本tar.sh进行解包
7、将源码包*.tar.gz全都删除
四、安装LAMP
1、安装libxml2
# cd /usr/local/src/libxml2-2.6.30
# ./configure --prefix=/usr/local/libxml2
# make && make install
2、安装libmcrypt
# cd /usr/local/src/libmcrypt-2.5.8
# ./configure --prefix=/usr/local/libmcrypt
# make && make install
3、安装zlib
# cd /usr/local/src/zlib-1.2.3
# ./configure
# make && make install
4、安装libpng
# cd /usr/local/src/libpng-1.2.31
# ./configure --prefix=/usr/local/libpng
# make && make install
5、安装jpeg6
这个软件包安装有些特殊,其它软件包安装时如果目录不存在,会自动创建,但这个软件包安装时需要手动创建。
# 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 /usr/local/src/jpeg-6b
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make && make install
6、安装freetype
# cd /usr/local/src/freetype-2.3.5
# ./configure --prefix=/usr/local/freetype
# make
# make install
7、安装autoconf
# cd /usr/local/src/autoconf-2.61
# ./configure
# make && make install
8、安装GD库
# cd /usr/local/src/gd-2.0.35
# ./configure \
--prefix=/usr/local/gd2/ \
--enable-m4_pattern_allow \
--with-zlib=/usr/local/zlib/ \
--with-jpeg=/usr/local/jpeg6/ \
--with-png=/usr/local/libpng/ \
--with-freetype=/usr/local/freetype/
# make
出现错误:
make[2]: *** [gd_png.lo] Error 1
make[2]: Leaving directory `/usr/local/src/gd-2.0.35'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/gd-2.0.35'
make: *** [all] Error 2
分析:这个问题是因为gd库中的gd_png.c这个源文件中包含png.h时,png.h没有找到导致的。
解决:
在编译文件里
# vi gd_png.c
将include “png.h” 改成 include “/usr/local/libpng/include/png.h”
其中/usr/local/libpng/为libpng安装路径。
# make install
9、安装Apache
# cd /usr/local/src/httpd-2.2.9
# ./configure \
--prefix=/usr/local/apache2 \
--sysconfdir=/etc/httpd \
--with-z=/usr/local/zlib \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--enable-static-support
# make && make install
10、配置Apache
启动Apache
# /usr/local/apache2/bin/apachectl start
关闭Apache
# /usr/local/apache2/bin/apachectl stop
查看80端口是否开启
# netstat -tnl|grep 80
访问Apache服务器
添加自启动
# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
11、安装Mysql
添加一个mysql标准组
# groupadd mysql
添加mysql用户并加到mysql组中
# useradd -g mysql mysql
# cd /usr/local/src/mysql-5.0.41
# ./configure \
--prefix=/usr/local/mysql/ \
--with-extra-charsets=all
出现错误:
checking for tgetent in -lncurses... no
checking for tgetent in -lcurses... no
checking for tgetent in -ltermcap... no
checking for tgetent in -ltinfo... no
checking for termcap functions library... configure: error: No curses/termcap library found
分析:缺少ncurses安装包
解决:
# yum install ncurses-devel
# make && make install
12、配置Mysql
创建MySQL数据库服务器的配置文件
# cp support-files/my-medium.cnf /etc/my.cnf
用mysql用户创建授权表,创建成功后,会在/usr/local/mysql目录下生成一个var目录
# /usr/local/mysql/bin/mysql_install_db --user=mysql
将文件的所有属性改为root用户
# chown -R root /usr/local/mysql
将数据目录的所有属性改为mysql用户
# chown -R mysql /usr/local/mysql/var
将组属性改为mysql组
# chgrp -R mysql /usr/local/mysql
启动数据库
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
查看3306端口是否开启
# netstat -tnl|grep 3306
简单的测试
# /usr/local/mysql/bin/mysqladmin version
查看所有mysql参数
# /usr/local/mysql/bin/mysqladmin variables
设置Mysql开机自启动
# cp /usr/local/src/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld
# chown root.root /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld
# chkconfig --levels 245 mysqld off
13、Mysql安全性设置
没有密码可以直接登录本机服务器
# /usr/local/mysql/bin/mysql -u root
查看mysql用户权限信息
mysql> select * from mysql.user;
删除非localhost的主机
mysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='';
刷新授权表
mysql> FLUSH PRIVILEGES;
为root用户添加密码
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('abc123');
再次进入Mysql客户端
# /usr/local/mysql/bin/mysql -u root -h localhost -p
关闭MySQL数据库
# /usr/local/mysql/bin/mysqladmin -u root -p shutdown
14、安装PHP
# cd /usr/local/src/php-5.2.6
# ./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql/ \
--with-libxml-dir=/usr/local/libxml2/ \
--with-png-dir=/usr/local/libpng/ \
--with-jpeg-dir=/usr/local/jpeg6/ \
--with-freetype-dir=/usr/local/freetype/ \
--with-gd=/usr/local/gd2/ \
--with-zlib-dir=/usr/local/zlib/ \
--with-mcrypt=/usr/local/libmcrypt/ \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-soap \
--enable-mbstring=all \
--enable-sockets
# make && make install
15、配置PHP
创建配置文件
# cp php.ini-dist /usr/local/php/etc/php.ini
使用vi编辑apache配置文件
# vi /etc/httpd/httpd.conf
添加这一条代码
Addtype application/x-httpd-php .php .phtml
重启Apache
# /usr/local/apache2/bin/apachectl restart
以上安装步骤可以写成一个shell script,详细参考http://files.cnblogs.com/mchina/lamp.rar
16、安装Zend加速器
# cd /usr/local/src/ZendOptimizer-3.2.6-linux-glibc21-i386/
# ./install.sh
17、安装phpMyAdmin
拷贝目录到指定位置并改名为phpmyadmin
# cp -a phpMyAdmin-3.0.0-rc1-all-languages /usr/local/apache2/htdocs/phpmyadmin
# cd /usr/local/apache2/htdocs/phpmyadmin/
# cp config.sample.inc.php config.inc.php
18、配置phpMyAdmin
# vi /usr/local/apache2/htdocs/phpmyadmin/config.inc.php
将auth_type 改为http
$cfg['Servers'][$i]['auth_type'] = 'http';
五、测试
1、编写info.php文件,查看php配置详细
# vi /usr/local/apache2/htdocs/info.php
<?phpphpinfo();?>
通过浏览器访问http://10.0.0.154/info.php,获得php的详细配置信息
2、Zend加速器信息
3、访问phpMyAdmin
至此LAMP环境配置完毕。
关于LNMP(linux+nginx+mysql+php)服务器环境配置,请参考:
http://www.cnblogs.com/mchina/archive/2012/05/17/2507102.html
David Camp
技术交流,请加QQ群:系统运维技术分享:296513821
业务合作,请联系作者QQ:562866602 我的微信号:mchina_tang 给我写信:mchina_tang@qq.com 我的地址:江苏·苏州我们永远相信,分享是一种美德 | We Believe, Great People Share Knowledge...

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Alipay PHP...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
