linux源码搭建lamp环境 + 源码包

来源:互联网 发布:xp电脑连接网络打印机 编辑:程序博客网 时间:2024/04/30 03:02


*********************************************************************************************************************

系统平台:CentOS 6.7 

Apache版本:httpd-2.4.7

Mysql 版本:mysql-5.5.23

Php版本:php-5.4.25

**********************************************************************************************************************

注释:一下文章内 #后面代表注释

镜像压缩包连接:   http://pan.baidu.com/s/1o6OrfYE

密码:xld7

废话少说吧,首先gcc编译器

yum -s install gcc*  #的确保你的linux能上网的

清空所有的链接 命令:   

iptables -F

关闭防火墙:

chkconfig iptables off

查看防火墙的状态  getenforce
如果是enforcing模式
那就使用命令 setenforce 0            #设置SELinux成为permissive模式
亦可以使用命令 vim /etc/selinux/config或者vim /etc/sysconfig/selinux
将SELINUX=enfording 改成SELINUX=disabled
然后重启才能生效

分别使用
rpm -q mysqld
rpm -q httpd
rpm -q php
如果有就停用掉  使用命令是      service httpd stop
    service mysqld stop
如果以上命令无法关闭mysql或者httpd
那就是使用 chkconfig  mysql|httpd off关闭
检查是否已经停用mysql httpd使用命令  chkconfig  --list

然后检查可用磁盘
df -hT
使用命令 eject #eject命令用于退出抽取式设备。
mount  /dev/cdrom   /media  
只有提示是
mount: block device /dev/cdrom is write-protected, mounting read-only  
才代表挂载成功
cd /media 你会发现镜像里面的资料
使用命令  cp -rf  /media /usr/src/  #其实只要用 cp -r /media  /usr/src/  就行 我是习惯加上r而已 
然后使用命令 cd /usr/src

使用ls查看

umount  #卸下
eject  #弹出

ok 开始真正安装lamp了

第一个安装是libxml2(用来解析xml文档的函数库)
使用 tar 解压libxml2安装包
之后使命命令
cd /libxml2-2.9.1
./configure --prefix=/usr/local/libxml2/
         make   #如果这一步执行有关于Python的错误 使用yum -y install python-devel
         然后再次使用 make
         make install

第二个软件 libmcrypt(加密算法扩展库)
同理解压,然后依次使用命令
cd /libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt/
         make 
          make install

第三个软件 libltdl  #此软件在第二个软件libmcrypt源码目录中
使用以下命令
cd libltdl
./configure --enable-ltdl-install
         make
         make install


第四个软件 mhash php加密方式扩展库
同意解压,然后依次使用命令
cd mhash-0.9.9.9
./configure
make 
make install

第五个软件 mcrypt(php 里面重要的加密支持扩展库)
同理解压,然后依次使用命令
cd /mcrypt-2.6.8
LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib  \
        ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt#(是一行,\只是换行而已)
make
make install

第六个软件 zlib(提供数据压缩用的函式库)
同理解压,然后依次使用命令
cd zlib-1.2.3
./configure
make
make install

第七个软件 libpng(软件包包含 libpng 库.这些库被其他程式用于解码png图片)
同理解压,然后依次使用命令
cd libpng-1.2.31
./configure  --prefix=/usr/local/libpng
make
make install

第八个软件 jpeg-6b(用于解压jpg和jieg图片
首先需要手动创建以下目录
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  #man1里面的一不是l
同理解压,然后使用命令  # 解压的是 jpeg-6b,如果你是使用lamp.iso,那就解压里面的 jpegsrc.v6b.tar.gz 这个压缩包
cd jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
        make
        make install

第九个软件 freetype  可移植的字体引擎
同理解压,然后使用命令
cd freetype-2.3.5
./configure  --prefix=/usr/local/freetype
        make
        make installi
第十个软件 GD库 是php处理图形的扩展库
mkdir /usr/local/gd2
        cd gd-2.0.35
#png错误,修改方法:vim gd_png.c  把里面的“#include png.h"替换为 ”#include usr/local/libpng/include/png.h"  

第十一个软件apache & apr-1.4.6 && apr-util-1.4.1 && openssl-devel
为什么是并排呢 因为安装apache有可能会需要先安装他去的软件 所以并排来写
使用以下命令
tar -zxf httpd-2.4.7.tar.gz  #如果解压软件的时候提示未来时间 那就需要使用命令date -s 20151122  #不知道你们遇见过这种情况没,我是遇见过了,修改系统时间 ,然后在解压
tar -zxf  apr-1.4.6.tar.gz
tar -zxf  apr-util-1.4.1.tar.gz
tar -zxf  pcre-8.34.tar.gz
cp  -r  apr-1.4.6  httpd-2.4.7/srclib/apr
cp  -r  apr-util-1.4.1  httpd-2.4.7/srclib/apr-util
tar zxvf pcre-8.34.tar.gz
cd pcre-8.34  
./configure 
make
make install
如果报错就使用命令  yum -y install openssl-devel
继续安装apache软件---httpd.2.4.7
cd 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
启动apche测试
netstat -anpt  #查看80端口开启没 
没有开启使用 /usr/local/apache2/bin/apachectl start
netstat -anpt #会有80端口的
/usr/local/apache2/bin/apachectl version
ps –aux | grep httpd
netstat –tlun | grep :80
在浏览器输入localhost 页面会显示 It works!  那就恭喜 apache安装好了
备注:
怎么设置apache开机自启动
vim /etc/rc.d/rc.local
添加 /usr/local/apace2/bin/apachectl start 
保存退出,以后开机apache就会自动启动


apache搞定了!!!!

接下来是安装mysql了 mysql安装需要的时间久一点
首先使用命令    yum -y install ncurses-devel  #如果报错如果报错,包找不到,是*通配符没有识别,给文件名加双引号 "ncurses*"不过我没有用yum -y install ncurses-devel  没有报错
然后同上解压ncurses-5.9.tar.gz  #若不安装ncurses编译MySQL时会报错 其实安装 ncurses-devel之后就不需要安装ncurses-5.9.tar.gz有些网上要求安装这个,这个不懂
cd ncurses-5.9
./configure --with-shared --without-debug --without-ada --enable-overwrite
make 
make install

#安装cmake和bison

mysql在5.5以后,不再使用./configure工具,进行编译安装。而使用cmake工具替代了./configure工具。cmake的具体用法参考文档cmake说明。

bison是一个自由软件,用于自动生成语法分析器程序,可用于所有常见的操作系统

yum -y install cmake

yum -y install bison

安装mysql
创建用户和用户组
groupadd mysql
useradd -g mysql mysql


继续解压mysql 并使用以下命令
cd mysql-5.5.23
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
make 
make install

编译过程如果出错就使用   make clean 于 rm CMakeCache.txt
进入/usr/local/mysql  #切记这个很重要
        然后执行 chown -R mysql .
                chgrp -R mysql .
        如果你没有在/usr/local/mysql/里面执行/usr/local/mysql 当你下面安装好mysql使用以下命

        /usr/local/mysql/scripts/mysql_install_db  --usr=mysql  #初始化数据库
会报以下错误


        FATAL ERROR: Could not find ./bin/my_print_defaults


        If you compiled from source, you need to run 'make install' to
        copy the software into the correct location ready for operation.


        If you are using a binary release, you must either be at the top
        level of the extracted archive, or pass the --basedir option
        pointing to that location.
显示正确的提示是


Installing MySQL system tables...
OK
Filling help tables...
OK


To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
提示两个ok


接下来修改下目录的权限
chown -R root .
chown -R mysql data
接下来拷贝主配置文件
使用命令
cp support-files/my-medium.cnf  /etc/my.cnf  # /etc/my.cnf 是已经存在的,它会提示你是否覆盖/etc/my.cnf  输入 y即可
注释:support-files/my-medium.cnf 里面的是模板文件
使用命令
/usr/local/mysql/scripts/mysql_install_db --user=mysql  
        注释:因为mysql5.5版本有个小问题  需要再次使用/usr/local/mysql/scripts/mysql_instamll_db --user=mysql  初始化数据库
启动Mysql服务器
用原本源代码的方式去使用和启动mysql命令如下
/usr/local/mysql/bin/mysqld_safe --user=mysql & 
执行之后会出现以下页面
[root@localhost mysql]# 151122 12:59:52 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
151122 12:59:52 mysqld_safe Starting mysqld daem with databases from...

记住啊,不要等它自己回到[root@localhost mysql]#  这种页面  刚开始lz不知道就是一直等  还一位报错了呢,你直接enter键就可以了
再次稍等以下  咱们先进入 /tmp
进去看看 有没有一个 mysql.sock的w文件
注释:如果存在你才能成功的往你数据库登陆
登陆mysql
接下来使用命令 /usr/local/mysql/bin/mysql 
直接就进去mysql了  接下来我们可以修改mysql
使用命令
/usr/local/mysql/bin/mysqladmin -uroot password '输入你的密码'
再次登陆
如果你再使用 /usr/local/mysql/bin/mysql 你就会发现报错了,报错如下
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
因为你修改密码  你需要使命命令  /usr/local/mysql/bin/mysql -uroot -p
就会提示你输入密码
输入正确的密码
会进入mysql
 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.23-log Source distribution


Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 


让mysql下次自启动
使用命令  vim /etc/rv.local
写入  /usr/local/mysql/bin/mysqld_safe --user=mysql &
保存退出

mysql至此安装好了!!!!


接下来安装php
安装前先确认系统是否按撞libtool和libtool-ltdl软件包
如果没有安装使用命令  
yum -y install libtool libtool-ltdl
如果出现以下提示
另外一个程序锁定了 yum;等待它退出……
 The other application is: PackageKit
   Memory :  41 M RSS ( 57 MB VSZ)
   Started: Sun Nov 22 13:33:43 2015 - 00:09 ago
   State  : Sleeping, pid: 19051
另外一个程序锁定了 yum;等待它退出……
 The other application is: PackageKit
   Memory :  41 M RSS ( 57 MB VSZ)
   Started: Sun Nov 22 13:33:43 2015 - 00:11 ago
   State  : Sleeping, pid: 19051
那就使用命令 vim /var/run/yum.pid 查看以下 有没有东西
如果有一个数字  那就使用 su  kill 加上那个数字


接下来先修改gd库里面的一个参数
使用命令 vi /usr/local/gd2/include/gd_io.h
typedef struct gdIOCtx
{
        ……
    void (*data);
#加入此句
}
注释:因为php 5.4的bug检测gd库有问题,需要手动修改
接下来安装php了
同理解压php软件包,然后使用以下命令
cd php-5.4.25
./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-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --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 --without-pear
如果出现以下代码提示
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+


Thank you for using PHP.
接下来使用make命令
make
如果make报错 代码如下
/usr/src/lamp1/lamp-php5.4/php-5.4.25/sapi/cli/php: error while loading shared libraries: libltdl.so.3: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] 错误 127
可以执行  ln -s  /usr/local/lib/libltdl.so.3  /lib
          ln -s /usr/local/lib/libltdl.so.3  /usr/lib
注释:使用find / -name libltdl.so.3 虽然存在,但是咱们系统找不到lib 或者是在usr/lib里面执行 所以需要使用链接来 /lib 和 /usr/lib下
然后重新从./configure 一一安装
接下来是生成php.ini
因为/usr/local/php里面是没有php.ini  #不信的话可以使用命令 cd /usr/local/php进去查看
没有吧
使用命令  mkdir /usr/local/php/etc
然后使用命令
cp  php.ini-production  /usr/local/php/etc/php.ini
注释:php.ini.production 实在php-5.4.25里面的
接下来是测试Apache与PHP的连通性,看Apache是否能解析php文件
使用命令 vi /usr/local/apache2/etc/httpd.conf
在AddType application/x-gzip  .gz .tgz后添加一下代码
AddType application/x-httpd-php .php .phtml .phps


注释:(注意大小写)* .phtml为将.phps做为PHP源文件进行语法高亮显示
接下来重启Apache命令如下
/usr/local/apache2/bin/apachectl stop
        /usr/local/apache2/bin/apachectl start
注释:建议不要使用 /usr/local/apache2/bin/apachectl restart 
    貌似这样使用 不起作用
测试:
vi /usr/local/apache2/htdocs/test.php 
写入以下代码
<?php
phpinfo();
 ?>
然后再浏览器上访问 localhost/test.php

注释:rpm安装的话网页默认目录是  /var/www/html

重大注释:有时第一次浏览器测试会失败,关闭浏览器重启再尝试即可,非编译错误,因为这个lz是吃了不少苦头,也难怪,lz智商有限,不会转弯#我刚开始看鸟哥的私房菜搭建服务器架设篇,说的网站默认目录实在、var/www/html里面,我安装的却在/usr/local/apache2/htdocs/里面,为此纠结了很多,各种差,后来才知道怎么原因。


浏览器上你看到了什么?是不是 PHP Version 5.4.25


至此lamp搭建好了

注释:以上是参考网上很多牛人写的代码,我只是收集起来,刚开始安装的时候也是遇见好多问题,相信好多人回合我一样,不过多安装几次就知道了,因为不会的可以各种问,有很多热心的牛人的。他们是很愿意分享他们的知识的。


2015-11-22   作者----漫画

座右铭:对于漫画我有独特的简介!

<完结!>




0 0
原创粉丝点击