lamp环境搭建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamp环境搭建相关的知识,希望对你有一定的参考价值。

    作为php开发人员,我们必须要懂得linux的相关操作。其中最重要的就是lamp环境的编译和搭建。本文以源代码的安装来演示lamp环境的搭建。

     一、编译前的准备工作

       1、确保linux系统中已经安装了 gcc、gcc-c++、make;

            # rpm -q make

            # rpm -q gcc

            # rpm -q gcc-c++

        2、检查系统中是否已经安装了 apache、mysql、php

            # rpm -qa | grep httpd

            # rpm -qa | grep mysql

            # rpm -qa | grep php

            停止所有这些服务

            # service httpd status

            # service mysql status

        3、关闭SELinux服务和防火墙

            # vi /etc/sysconfig/selinux   ==> 设置 SELINUX=disabled

            # iptables -F  关闭防火墙

        4、创建解压缩文件的 tar.sh脚本

            ----  执行脚本,解压所需要的源代码包文件。所有源代码包统一放在/lamp/文件下。

            源代码包文件下载请访问 : http://pan.baidu.com/s/1ntVy0QH    密码: 5tkp

            tar.sh文件的内容  

            =============begin        

             cd /lamp

             ls *.tar.gz > ls.list

             for TAR IN ` cat ls.list`

            do

                    tar -zxf $TAR

            done

            ==============end

            执行脚本:  # sh -x tar.sh


    二、编译lamp环境

            总览步骤:

            1) 解压缩包   .tar.gz     tar -zxf

            2) ./configure 配置

            3) make  安装   源代码编译成可执行文件

            4) make install  安装、拷贝

            ****** 查看帮助信息  ./configure --help | grep zlib


========================================begin

*******安装编译php用到的库文件

# cd /lamp/libxml2-2.6.30
# ./configure --prefix=/usr/local/libxml2/
# make
# make install
# ls /usr/local/libxml2   检测源代码包是否安装成功
若出错则:1) rm -rf /usr/local/libxml2
       2)  rm -rf /lamp/libxml2-2.6.30
      3)  重新解压编译安装

# cd ../libmcrypt-2.5.8
# ./configure --prefix=/usr/local/libmcrypt/
# make
# make install
========================================
# cd /lamp/libmcrypt-2.5.8/libltdl/
# ./configure --enable-ltdl-install
# make
# make install

# cd ../zlib-1.2.3
# ./configure            // 不指定安装路径
# make
# make install > /backup/zlib_20160122.install.log   //将安装的过程写入到日志文件当中,方便以后查找

# cd ../libpng-1.2.31
# ./configure --prefix=/usr/local/libpng/
# make
# make install

# cd ../jpeg-6b
# 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
# ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
# make
# make install

# cd ../freetype-2.3.5
# ./configure --prefix=/usr/local/freetype/
# make
# make install

# cd ../autoconf-2.61
# ./configure ; make ; make install > /backup/autoconf_20160122.install.log

# cd ../gd-2.0.35
# ./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
# make
# make install


*******安装编译apache

# cd ../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
# make
# make install
# ls /usr/local/apache2
# /usr/local/apache2/bin/apachectl start
# ps -le | grep httpd  检测apache相应的进程
# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit   添加自启动httpd
***** 没有权限或无法载入文件的错误则
# chcon -t texrel_shlib_t filename
如: # chcon -t texrel_shlib_t /usr/local/apache2/mod_rewrite.so


*******安装编译mysql

# cd ../mysql-5.0.41
# cd ../ncurses-5.6
# ./configure --with-shared --without-debug --without-ada --enable-overwrite
# make
# make install

# groupadd mysql
# useradd -g mysql mysql
# cd ../mysql-5.0.41
# ./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
# make
# make install
# cp support-files/my-medium.cnf /etc/my.cnf
# /usr/local/mysql/bin/mysql_install-db --user=mysql  授权用户
# chown -R root /usr/local/mysql
# chown -R mysql /usr/local/mysql/var
# chgrp -R mysql /usr/local/mysql
# /usr/local/mysql/bin/mysqld_safe  --user=mysql &  启动mysql
# ps -le | grep mysqld 检测mysqld进程
# netstat -an | grep 3306
# /usr/local/mysql/bin/mysqladmin version  查看mysql版本信息
# /usr/local/mysql/bin/mysqladmin variables  查看mysql版本信息
设定root登录密码
# /usr/local/mysql/bin/mysql -u root
mysql> SET PASSWORD FOR ‘root‘@‘localhost‘=PASSWORD(‘98374toor‘) ;
mysl>  FLUSH PRIVILEGES;
mysql> quit
====================添加mysql自启动
# cp /lamp/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


*******安装编译php

# cd ../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-jpeg-dir=/usr/local/jpeg6/ --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
# make
# make install
# cp php.ini-dist /usr/local/php/etc/php.ini
# echo "Addtype application/x-httpd-php .php .phtml" >> /etc/httpd/httpd.conf
# /usr/local/apache2/bin/apachectl restart

# vi /usr/local/apache2/htdocs/info.php  新建文件  
<?
    phpinfo();
?>

ZendOptimizer脚本安装
# cd ../ZendOptimizer-3.2.6-linux-glibc21-i386
# sh -x install.sh
改变php配置文件存放目录  /usr/local/php/etc

phpadmin安装
# cp -a /lamp/phpMyAdmin-3.0.0-rc1-all-languages /usr/local/apache2/htdocs/phpadmin
# cd /usr/local/apache2/htdocs/phpadmin
# cp config.sample.inc.php config.inc.php 生成配置文件
# vi config.inc.php
$cfg[Servers‘‘][$i][‘auth_type‘] = ‘cookie‘;改成 $cfg[Servers‘‘][$i][‘auth_type‘] = ‘http‘; // 改写认证方式

========================================end


****************备注其他apache和mysql的相关命令

=============启动和关闭mysql数据库
/etc/init.d/mysqld start
/etc/init.d/mysqld restart
/etc/init.d/mysqld stop

===========启动和关闭apache
/etc/init.d/httpd start
/etc/init.d/httpd restart
/etc/init.d/httpd stop
基本的操作方法:
本文假设你的apahce安装目录为/usr/local/apache2,这些方法适合任何情况
apahce启动命令:
推荐/usr/local/apache2/bin/apachectl start 启动
apache停止命令:
/usr/local/apache2/bin/apachectl stop   停止
apache重新启动命令:
/usr/local/apache2/bin/apachectl restart 重启
要在重启 Apache 服务器时不中断当前的连接,则应运行:
/usr/local/sbin/apachectl graceful

如果apache安装成为linux的服务的话,可以用以下命令操作:
service httpd start 启动
service httpd restart 重新启动
service httpd stop 停止服务

本文出自 “dongdongのhome” 博客,请务必保留此出处http://autophp.blog.51cto.com/8062337/1743153

以上是关于lamp环境搭建的主要内容,如果未能解决你的问题,请参考以下文章

LAMP环境搭建

LAMP 环境搭建

怎么在linux 里搭建LAMP环境

Linux手动搭建LAMP环境

源码编译搭建LAMP环境

搭建LAMP环境