LAMP WEB环境配置 (Windows & Linux )

WEB环境配置LAMP

 

 

 

操作系统:Windows
//下载 baidu 查Appserv 2.5.9 自行下载即可
安装 Appserv 2.5.9  (Appache,Mysql,PHP 三合一)
安装完成后在 桌面选上“我的电脑”右键管理-服务和应用程序-服务 里面可以见到Apache2.2和Mysql的服务,如未显示已启动,可选上该服务 点击启动,如启动不成功,需重启电脑。

如需加扩展,去掉php.ini相应库 extension前面的";"号,再重启appache即可。
例:
#php 开启curl函数库的步骤
1.去掉windows/php.ini 文件里;extension=php_curl.dll前面的;    /*用 echo phpinfo();查看php.ini的路径*/
2.把php5/libeay32.dll,ssleay32.dll复制到系统目录windows/下
3.重启apache


操作系统:Linux 版本 CentOS release 5.5 (Final)
Web服务器:Apache 2.2.16
数据库:MySQL 5.1.45
脚本语言:PHP 5.3.3
数据库管理:phpMyAdmin3.3.7

 

1.安装Apache 2.2.16
------------------下载软件包httpd-2.2.16.tar.gz 或更新版本,地址 http://httpd.apache.org/--------------------
# tar zvxf httpd-2.2.16.tar.gz
# cd httpd-2.2.16
# ./configure --prefix=/usr/local/apache --enable-module=most --enable-shared=max
# make
# make install
# /usr/local/apache/bin/apachectl start //启动Apache服务
# /usr/local/apache/bin/apachectl stop //关闭Apache服务

备注:
# cp /usr/local/apache/bin/apachectl /etc/init.d/
/etc/init.d/apachectl start(或stop) 即可控制Apache服务开关
配置Apache请见附录一

 

2.安装MySQL 5.1.45
-------------下载软件包mysql-5.1.45.tar.gz 或更新版本,地址 http://www.mysql.com/downloads/mysql/ 选用source下载-------------
//创建mysql用户
# groupadd mysql
# useradd -g mysql mysql -M
# tar zvxf mysql-5.1.45.tar.gz //解压缩
# cd mysql-5.1.45 //进入解压缩后的文件目录
# ./configure --prefix=/mysql --enable-thread-safe-client --without-debug  --with-extra-charsets=complex --with-innodb     //不加--with-extra-charsets   SET NAMES GBK 会出现 Unknown character set: 'GBK'的错误。
# make //编译
# make install //安装
# /mysql/bin/mysql_install_db //初始化授权
# chown -R root:root /mysql //文件所属改为root
# chown -R mysql:mysql /mysql/var //数据所属改为mysql所有
# cp /mysql/share/mysql/my-huge.cnf /etc/my.cnf //复制配置文件 可选 my-small.cnf 、my-medium.cnf、my-large.cnf、my-huge.cnf
# /mysql/bin/mysqld_safe --user=root & //启动MySQL
# /mysql/bin/mysqladmin -uroot password yourpassword //把yourpassword改为你要设置的密码
# /mysql/bin/mysqladmin -uroot -pyourpassword shutdown //关闭MySQL

备注:
# cp /mysql/share/mysql/mysql.server /etc/init.d/
/etc/init.d/mysql.server start(或stop) 即可控制MySQL服务开关

 

启动失败 及 搬数据库后乱码问题 可查看附件四。

 

如果想開機自動運行
# chkconfig --add mysql.server

 

3.安装PHP 5.3.3
-------------------下载软件包php-5.3.3.tar.gz,或更新版本,地址 http://www.php.net/downloads.php -----------------------
1).基础的安装,只包括Apache和Mysql,不包含任何库 (一般不会出错,但缺少常用库,不建议使用这种方法,如要用到缺少库,需先添加库再重新编译PHP,建议用扩展安装)
# tar zvxf php-5.3.3.tar.gz
# cd php-5.3.3
# ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/mysql 
# make
# make install
# cp php.ini-development /usr/local/lib/php.ini
# vi /usr/local/lib/php.ini   
改 short_open_tag = On  register_globals = On  其他设置可自己研究
只有short_open_tag改为On才认<??>是php标签,要不只认标准的<?php ?>,找得我这苦啊

 

2).扩展安装,包含zlib、freetype、libpng 、jpeg-6b、curl //说明:zlib为压缩库,gz*相关函数依赖此库。freetype、libpng 、jpeg-6b为gd库所需,image*相关函数(如生成验证码)依赖此库。curl为取网库,curl*相关函数依赖此库
a.安装zlib库  //http://www.zlib.net/   找到zlib source code, version 1.2.5, tar.gz 或更高版本
tar zxvf zlib-1.2.5.tar.gz
cd zlib-1.2.5
./configure
make install

64位下编译方法:
./configure完之后
vi Makefile
找到 CFLAGS=-O3 -DUSE_MMAP
在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC
make
make install clean

 

b.安装freetype库  //下载http://www.freetype.org/download.html
tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure
make
make install clean

 

c.安装libpng库   //下载http://www.libpng.org/pub/png/libpng.html
tar zxvf libpng-1.2.34.tar.gz  
cd libpng-1.2.34
./configure
make
make install clean


d.安装jpeg-6b库  //下载 http://download.chinaunix.net/download.php?id=10021&ResourceID=5095
tar zxvf jpegsrc.v6b.tar.gz 
cd jpeg-6b
./configure
make
make install-lib
64位下编译方法:
libtool是一个库,你看看有没有安装:
rpm -qa | grep libtool
本人安装时是显示,如果没有请先安装
# libtool-1.5.22-6.1

然后进入jpeg-6b的源码目录,然后执行以下步骤,切记!
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure --enable-shared --enable-static
make
mkdir -p /usr/local/man/man1
make install-lib
make install

 

e:安装curl库  //下载http://curl.haxx.se/download.html
tar xvf curl-7.18.0.tar.bz2
cd curl-7.18.0
./configure
make
make install

安装完以上库,我们现在可以安装PHP了,和基础安装差不多只是configure多了些参数
# tar zvxf php-5.3.3.tar.gz
# cd php-5.3.3
# ./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/mysql --with-gd --with-zlib-dir=/usr/local --with-jpeg-dir=/usr/local  --with-mysqli=/mysql/bin/mysql_config --enable-mbstring --with-curl=/usr/lib    //更多参数可查看./configure --help 或上网查询
# make
# make install
# cp php.ini-development /usr/local/lib/php.ini

如make的过程中出现错误请参考附录二
如以后需要添加更多的库请参考附录三
===================== 至此 Apache+Mysql+PHP已全部安装成功。======================

以下安装phpMyAdmin    //下载phpMyAdmin-3.3.7-all-languages.tar.gz  --http://www.phpmyadmin.net/home_page/downloads.php 
# tar zvxf phpMyAdmin-3.3.7-all-languages.tar.gz
# mv phpMyAdmin-3.3.7-all-languages phpMyAdmin
# cp -R phpMyAdmin /www
# cd /www/phpMyAdmin
# cp config.sample.inc.php config.inc.php
# vi config.inc.php
$cfg['Servers'][$i]['auth_type'] = 'cookie';
改為
$cfg['Servers'][$i]['auth_type'] = 'http';


最后,测试安装情况即可。请保证Apache为已start,serverIP为服务器所在ip *
#vi /www/phpinfo.php
<? echo phpinfo(); ?>

#vi /www/phptest.php
<?
$arr=array('gzopen'=>'zlib','curl_init'=>'curl','imagecreatefromjpeg'=>'gd');
foreach($arr as $k=>$v){
 if(function_exists($k))
  echo "$v ok<br>";
 else
  echo "$v install fail<br>";
}
?>
在浏览器上打开网址
http://serverIP/phpinfo.php
http://serverIP/phptest.php
http://serverIP/phpMyAdmin

 

#linux php mysql 时区 时差问题
php.ini   date.timezone = Etc/GMT+4

ln -sf /usr/share/zoneinfo/Etc/GMT+4 /etc/localtime  

重启mysql,apache

 

 

如无意外,一切OK,如有意外,请google。


附录一:
Apache配置
5.配置Apache服务的httpd.conf文件
*在LoadModule处添加 LoadModule php5_module module/libphp5.so  //好像是默认就已经有了
*在DirectoryIndex处添加 index.php
*在AddType application处添加
AddType application/x-httpd-php .php .phtml
AddType applicatoin/x-httpd-php-source .phps
*改虚拟目录
DocumentRoot "/www"
<Directory "/www">

 

附录二:
安装PHP过程中常见错误
1).configure的时候出现 configure: error: libjpeg.(a|so) not found.
解决办法:
cd /usr/src/jpeg-6b
./configure
vi Makefile
找到 CFLAGS= -O2 -I$(srcdir)
在后面加入-fPIC,即变成CFLAGS= -O2 -I$(srcdir) –fPIC
make
make install-lib  ****重要!
make install

2).make的时候出现 make: *** [sapi/cli/php] 错误 1
解决方法:  make clean  然后重新make

3).make的时候出现  /usr/bin/ld: /usr/local/lib/libz.a(compress.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1
原因:没有按64位下编译方法
解决方法:重新安装 zlib-1.2.3.tar.gz
tar -zxvf zlib-1.2.3.tar.gz 
cd zlib-1.2.3 
./configure
vi Makefile
找到 CFLAGS=-O3 -DUSE_MMAP
在后面加入-fPIC,即变成CFLAGS=-O3 -DUSE_MMAP -fPIC
接下面步骤
make
make install

4).make的时候出现  /usr/bin/ld: /usr/local//lib/libjpeg.a(jcapimin.o): relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local//lib/libjpeg.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [libphp5.la] Error 1
原因:没有按64位下编译方法
解决方法:重新安装 jpeg-6b
然后进入jpeg-6b的源码目录,然后执行以下步骤,切记!
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure --enable-shared --enable-static
make
mkdir -p /usr/local/man/man1
make install

 

附录三:
PHP添加库
通过访问
http://serverIP/phpinfo.php
phpinfo.php 内容只为<? echo phpinfo();?>

可以查看到当时编译时的命令
Configure Command   './configure' '--with-mysql=/mysql' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-curl' '--with-zlib' '--enable-mbstring'

将Configure Command的内容复制到word将'替换为空白

如果是php自带的 直接加上参数即可 如:--enable-mbstring
如果安装扩展库,需要自己先下载安装库 然后在 Command 后面加上对应参数即可 如 --with-"库名"=/usr/lib ,如果不知道参数可以在PHP源码目录里面 ./configure --help
如: ./configure --with-mysql=/mysql --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --with-jpeg-dir=/usr/local --with-curl --with-zlib --enable-mbstring

 

 

附录四:
1).Mysql启动失败
Starting MySQL......Manager of pid-file quit without updati[FAILED]
解决方法:
# chown -R mysql:mysql /mysql/var

 

2).搬数据库后,数据库查询出现乱码问题可试以下几种方法
修改/etc/my.cnf (修改后记得重启)
方法1:
[client]后加上
Server characterset: latin1
Db characterset: latin1
Client characterset: latin1
Conn. characterset: latin1

 

方法2:
[client]后加上
loose-default-character-set=latin1

 

方法3:
[client]后加上
default-character-set = utf8
character_set_server = utf8

查看字集可用:


SHOW VARIABLES LIKE 'character_set_%';
SHOW VARIABLES LIKE 'collation_%';

 

============ THE  END =============

 

 

PS:欲想写程序,先配服务器。希望本文对读者有帮助,如文中有错,望能留言指正。

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值