lamp环境配置apache2.2.27+mysql-5.1.42+php-5.2.17

标题是我本地机器装得版本,以下教程改下版本就可以用


(一)如果你的服务器没有链接网络可以先挂载本地光盘。设置yum源。


挂载光盘:

[root@delphi ~]# mkdir /mnt/cdrom     #新建挂载点
[root@delphi ~]# mount /dev/cdrom /mnt/cdrom/     #挂载本地光盘
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@delphi ~]#

 


配置yum源:

复制代码
[root@delphi ~]# cd /etc/yum.repos.d/
[root@delphi yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[root@delphi yum.repos.d]# vi CentOS-Media.repo 
# CentOS-Media.repo
#
# This repo can be used with mounted DVD media, verify the mount point for
# CentOS-6. You can use this repo and yum to install items directly off the
# DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
# yum --enablerepo=c6-media [command]
#
# or for ONLY the media repo, do this:
#
# yum --disablerepo=\* --enablerepo=c6-media [command]

[c6-media]
name=CentOS-$releasever - Media    
baseurl=file:///mnt/cdrom/     #指定了三个光盘有可能挂载的路径。
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=1     #enabled=0 这里的0代表缺省源不存在,1代表启用。
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

# wq保存退出。
复制代码

 

如果你的linux能够上互联网,那么备份Base这个配置文件。

[root@delphi yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak

 

 

(二)保证你的电脑里安装了gcc gcc-c++ make,如果没有应该先安装

[root@delphi ~]# yum install gcc -y
[root@delphi ~]# yum install gcc-c++ -y

 

 

(三)卸载apache php mysql rpm软件包。我的系统里没有装。方法很多,不一一罗列。

查看服务有没有启动:

复制代码
[root@delphi ~]# service httpd status
httpd: 未被识别的服务
[root@delphi ~]# service mysqld status
mysqld: 未被识别的服务

[root@delphi ~]# rpm -qa httpd
[root@delphi ~]# rpm -qa mysql
[root@delphi ~]# rpm -qa mysqld
[root@delphi ~]# rpm -qa | grep php
复制代码

 

如果你的系统里有这些包,那么rpm -e packagename或者yum remove packagename(解决依赖卸载)。

 

(四)关闭SElinux 允许iptables相关端口

1.关闭selinux的两种方法。--永久关闭。(需要重启系统)

复制代码
[root@delphi ~]# vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled     # 把SELINUX=enforcing 更改为SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
复制代码

 


2.临时关闭(不需要重启系统)

[root@delphi ~]# setenforce 0

 


(五)准备源码部署需要安装的所有源代码包

libxml2-2.6.30.tar.gz
libmcrypt-2.5.8.tar.gz
zlib-1.2.3.tar.gz
libpng-1.2.31.tar.gz
jpegsrc.v6b.tar.gz
freetype-2.3.5.tar.gz
autoconf-2.61.tar.gz
gd-2.0.35.tar.gz
httpd-2.2.9.tar.gz
ncurses-5.6.tar.gz
mysql-5.0.41.tar.gz
php-5.2.6.tar.gz
ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
phpMyAdmin-3.0.0-rc1-all-languages.tar.gz

复制代码
[root@delphi ~]# cd /root/lamp
[root@delphi lamp]# ls
autoconf-2.61.tar.gz libmcrypt-2.5.8.tar.gz php-5.2.6.tar.gz
freetype-2.3.5.tar.gz libpng-1.2.31.tar.gz phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
gd-2.0.35.tar.gz libxml2-2.6.30.tar.gz ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
httpd-2.2.9.tar.gz mysql-5.0.41.tar.gz zlib-1.2.3.tar.gz
jpegsrc.v6b.tar.gz ncurses-5.6.tar.gz
复制代码

 


这里写一个解压源码包的脚本。

#!/bin/bash
cd /root/lamp
ls * > lamp.list
for i in $(cat lamp.list)
do
tar zxf $i
done

运行脚本:

[root@delphi ~]# sh lamp.sh


查看解压:

复制代码
[root@delphi lamp]# ls
autoconf-2.61 jpeg-6b libxml2-2.6.30.tar.gz phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
autoconf-2.61.tar.gz jpegsrc.v6b.tar.gz mysql-5.0.41 ZendOptimizer-3.2.6-linux-glibc21-i386
freetype-2.3.5 lamp.list mysql-5.0.41.tar.gz ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
freetype-2.3.5.tar.gz libmcrypt-2.5.8 ncurses-5.6 zlib-1.2.3
gd-2.0.35 libmcrypt-2.5.8.tar.gz ncurses-5.6.tar.gz zlib-1.2.3.tar.gz
gd-2.0.35.tar.gz libpng-1.2.31 php-5.2.6
httpd-2.2.9 libpng-1.2.31.tar.gz php-5.2.6.tar.gz
httpd-2.2.9.tar.gz libxml2-2.6.30 phpMyAdmin-3.0.0-rc1-all-languages
复制代码

 


(六)开始搭建lamp环境
安装三步走configure ---make ---make install

configure 检测系统配置,检测软件安装所需要的软件。
make 编译二进制文件为可执行文件。
make install 安装软件。


1.编译安装xml2

[root@delphi lamp]#cd libxml2-2.6.30
[root@delphi libxml2-2.6.30]# ./configure --prefix=/usr/local/libxml2/
[root@delphi libxml2-2.6.30]# make && make install

 

2.同样的方法安装libmcrpyt

[root@delphi lamp]# cd libmcrypt-2.5.8
[root@delphi libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt/
[root@delphi libmcrypt-2.5.8]# make && make install

 

3.编译安装zlib (zlib是个库文件,这里为了防止后期出错,不用指定路径,如果是64位系统,请参见安装libpng排错的方法安装。)

[root@delphi lamp]# cd zlib-1.2.3
[root@delphi zlib-1.2.3]# ./configure
[root@delphi zlib-1.2.3]# make && make install

 

编译安装libpng如果出现如下错误,是应为你的环境是64位系统,匹配不了zlib库。
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [libpng12.la] 错误 1
make[1]: Leaving directory `/root/packget/libpng-1.2.31'
make: *** [all] 错误 2
解决办法:重新新安装 zlib

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.编译安装libpng

[root@delphi lamp]# cd libpng-1.2.31
[root@delphi libpng-1.2.31]# ./configure -prefix=/usr/local/libpng/
[root@delphi libpng-1.2.31]# make && make install

 

5.安装jpeg6

这源码包的安装相对复杂一点。因为其不会自动创建对应的目录,首先我们自己手动建立目录

/usr/local/jpeg6/ #创建安装目录
/usr/local/jpeg6/bin/ #创建可执行文件目录
/usr/local/jpeg6/lib/ #创建库文件爱你存放目录
/usr/local/jpeg6/include #创建头文件存放目录
/usr/local/jpeg6/man/man1 #创建man手册中的命令帮助,man1指的是命令帮助, man5配置文件的帮助。

复制代码
[root@delphi lamp]# cd jpeg-6b/
[root@delphi jpeg-6b]# mkdir /usr/local/jpeg6/ && mkdir /usr/local/jpeg6/bin/ && mkdir /usr/local/jpeg6/lib/ && mkdir /usr/local/jpeg6/include
[root@delphi jpeg-6b]# mkdir -p /usr/local/jpeg6/man/man1

[root@delphi jpeg-6b]# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
[root@delphi jpeg-6b]# make && make install
复制代码

 

*************************************************************************
./libtool --mode=compile gcc -O2 -I. -c ./jcapimin.c
make: ./libtool:命令未找到
make: *** [jcapimin.lo] 错误 127
出现以上错误的解决办法:
[root@delphi jpeg-6b]# cp /usr/share/libtool/config/config.sub /root/packget/jpeg-6b/
[root@delphi jpeg-6b]# cp /usr/share/libtool/config/config.guess /root/packget/jpeg-6b/
然后:
[root@delphi jpeg-6b]# make clean
再执行:
[root@delphi jpeg-6b]# make
[root@delphi jpeg-6b]# make install
************************************************************************

 

6.编译安装freetype

[root@delphi lamp]# cd freetype-2.3.5
[root@delphi freetype-2.3.5]# ./configure --prefix=/usr/local/freetype/
[root@delphi freetype-2.3.5]# make && make install

 

7.编译安装autoconf

[root@delphi lamp]# cd autoconf-2.61
[root@delphi autoconf-2.61]# ./configure
[root@delphi autoconf-2.61]# make && make install

 

8.编译安装gd库:

[root@delphi lamp]# cd gd-2.0.35
[root@delphi gd-2.0.35]# ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
#备注一下:这里如果你的zlib库是指定路径,那么可以--with-zlib=/$PATH
[root@delphi gd-2.0.35]# make && make install

 

9.编译安装apache:

复制代码
[root@delphi lamp]# cd httpd-2.2.9
[root@delphi httpd-2.2.9]# ./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support 
[root@delphi httpd-2.2.9]# make && make install

[root@delphi httpd-2.2.9]# /usr/local/apache2/bin/apachectl start
[root@delphi httpd-2.2.9]# pgrep httpd
27652
27653
27654
27655
27656
27657
复制代码

 

如果没有禁止selinux
那么使用如下命令开启模块权限:
[root@delphi ~]# chcon -t texrel_shlib_t modulename
通过浏览器访问服务器,如果反回It‘s works ! 表示安装成功。

 

10.编译安装mysql之前需要安装编译nourses:

[root@delphi lamp]# cd ncurses-5.6
[root@delphi ncurses-5.6]# ./configure --with-shared --without-debug --without-ada --enable-overwrite
[root@delphi ncurses-5.6]# make && make install

 

11.编译安装mysql:

首先创建mysql用户以及用户组:

复制代码
[root@delphi lamp]# cd mysql-5.0.41
[root@delphi mysql-5.0.41]# groupadd mysql
[root@delphi mysql-5.0.41]# grep mysql /etc/group
mysql:x:501:
[root@delphi mysql-5.0.41]# useradd -g mysql mysql

[root@delphi mysql-5.0.41]# ./configure --prefix=/usr/local/mysql --with-extra-charsets=all
[root@delphi mysql-5.0.41]# make && make instal
make报错的话就用
make ZEND_EXTRA_LIBS='-liconv' && make install

复制代码

 

配置mysql:把源码包中的my-medium.cnf拷贝的/etc/下命名为my.cnf

[root@delphi mysql-5.0.41]# cp support-files/my-medium.cnf /etc/my.cnf

启动用户的授权表:

[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysql_install_db --user=mysql

改变目录权限:

[root@delphi mysql-5.0.41]# chown -R root /usr/local/mysql     #改变mysql所属用户
[root@delphi mysql-5.0.41]# chown -R mysql /usr/local/mysql/var     #改变mysql下var这个目录所属用户
[root@delphi mysql-5.0.41]# chgrp -R mysql /usr/local/mysql     #改变mysql的所属组,这里的-R是权限继承到子目录

启动:mysql

[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[1] 25856
[root@delphi mysql-5.0.41]# nohup: 忽略输入重定向错误到标准输出端
Starting mysqld daemon with databases from /usr/local/mysql/var     #表示数据存放路径。回车既可。

查看mysql是否启动:

[root@delphi mysql-5.0.41]# pgrep mysql

查看mysql的版本:

[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysqladmin version

查看mysql配置参数:

[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysqladmin variables

 

设置mysql的用户密码:

复制代码
[root@delphi mysql-5.0.41]# /usr/local/mysql/bin/mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.41-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> set password for 'root'@'localhost'=PASSWORD('123456');
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
复制代码

 

把apache和mysql 加入启动项

[root@delphi mysql-5.0.41]# echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.d/rc.local
[root@delphi mysql-5.0.41]# echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.d/rc.local

 

或者:

复制代码
[root@delphi ~]# cd lamp/mysql-5.0.41
[root@delphi mysql-5.0.41]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@delphi mysql-5.0.41]# chown root.root /etc/rc.d/init.d/mysqld
[root@delphi mysql-5.0.41]# chmod 755 /etc/rc.d/init.d/mysqld 
[root@delphi mysql-5.0.41]# chkconfig --add mysqld
[root@delphi mysql-5.0.41]# chkconfig --list mysqld
mysqld 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[root@delphi mysql-5.0.41]# chkconfig --levels 245 mysqld off #设置运行级别启动项的方法.
[root@delphi mysql-5.0.41]# chkconfig --list mysqld 
mysqld 0:关闭1:关闭2:关闭3:启用4:关闭5:关闭6:关闭
[root@delphi mysql-5.0.41]# chkconfig --levels 245 mysqld on #更改回原来的运行级别
复制代码

 

12.安装php:

复制代码
[root@delphi lamp]# cd php-5.2.6
[root@delphi php-5.2.6]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg8/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config –with-curl=/usr/local/curl 
--with-zlib-dir=/usr/local/zlib/ --with-png-dir=/usr/local/libpng/ --enable-soap --enable-mbstring=all--enable-sockets
或者
直接生成curl,后面就不用重新编译生成了
./configure --prefix=/usr/local/php/ --with-apxs2=/usr/local/apache/bin/apxs --with-curl=/usr/local/curl/bin --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg/ --with-freetype-dir=/usr/local/freetype/--with-gd-dir=/usr/local/gd/--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
 [root@delphi php-5.2.6]# make && make install
这边make instal后回报错,原作者没给我给个答案
类似以下错误
/opt/php-5.2.17/ext/dom/node.c -o ext/dom/node.lo
/opt/php-5.2.17/ext/dom/node.c: In function â€کdom_canonicalization’:
/opt/php-5.2.17/ext/dom/node.c:1953: error: dereferencing pointer to incomplete type
/opt/php-5.2.17/ext/dom/node.c:1955: error: dereferencing pointer to incomplete type
make: *** [ext/dom/node.lo] Error 1 可用 # curl -o php-5.2.17.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
# cd php-5.2.17
# patch -p0 -b < ./php-5.2.17.patch 
   patching file ext/dom/node.c
   patching file 
   ext/dom/documenttype.c
   patching file ext/simplexml/simplexml.c 然后重新编译,安装,记得make clean 一下 出现
make: *** [sapi/cli/php] 错误 1
在make时改为 make ZEND_EXTRA_LIBS='-liconv' && make install
  [root@delphi php-5.2.6]# cp php.ini-dist /usr/local/php/etc/php.ini[root@delphi php-5.2.6]# echo "Addtype application/x-httpd-php .php .phtml" >> /etc/httpd/httpd.conf[root@delphi php-5.2.6]# /usr/local/apache2/bin/apachectl restart
cp php.ini-dist /usr/local/php/etc/php.ini

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


     AddType application/x-compress .Z
     AddType application/x-gzip .gz .tgz
 后面添加
     Addtype application/x-httpd-php .php .phtml
     Addtype application/x-httpd-php-source .phps

13.安装Zend加速器

[root@delphi lamp]# cd ZendOptimizer-3.2.6-linux-glibc21-i386
[root@delphi ZendOptimizer-3.2.6-linux-glibc21-i386]# ./install.sh 

 

安装过程选择正确的 php.ini 文件所在目录 和 apache控制命令所在目录

 

14.安装 phpmyadmin 方便管理mysql数据库

[root@delphi lamp]# mv phpMyAdmin-3.0.0-rc1-all-languages /usr/local/apache2/htdocs/phpmyadmin

转自http://www.cnblogs.com/zhxlsuyu/archive/2013/09/14/3320960.html

你可能感兴趣的:(Linux,php,lamp,服务器,互联网)