LAMP环境搭建

Apache安装: 

                官网地址 http://www.apache.org

      #  cd  /usr/local/src

      #  wget  http://apache.fayea.com/httpd/httpd-2.2.31.tar.gz

       #  tar  zxvf  httpd-2.2.31.tar.gz

       #  cd   httpd-2.2.31

安装LAMP之前必备安装包

       # yum install wget gcc gcc-c++ make re2c curl curl-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel libmcrypt libmcrypt-devel zlib zlib-devel openssl openssl-devel freetype freetype-devel gd gd-devel perl perl-devel ncurses ncurses-devel bison bison-devel libtool gettext gettext-devel cmake bzip2 bzip2-devel pcre pcre-devel 


编译安装:/usr/local/apache2/bin/apachectl -M:查看安装了哪些模块                           /usr/local/apache2/bin/apachectl -t:检查语法错误                                 /usr/local/apache2/bin/apachectl -l:查看安装的库文件                             /usr/local/apache2/bin/apachectl graceful:重新加载配置                           /usr/local/apache2/htcocs            主页存放目录                                 /usr/local/apache2/bin/apachectl     启动文件目录                                 /usr/local/apache2/conf              配置文件路径

编译安装apr,apr-util:

          # cd /usr/local/src/                

          # wget http://mirrors.cnnic.cn/apache/apr/apr-1.5.2.tar.gz 

          # wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.5.4.tar.gz

编译apr:   

    [root@localhost src]# tar zxf apr-1.5.2.tar.gz  

    [root@localhost src]# cd apr-1.5.2 

    [root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr 

     [root@localhost apr-1.5.2]# make && make install

编译apr-util

    [root@localhost src]# tar zxf apr-util-1.5.4.tar.gz  

    [root@localhost src]# cd apr-util-1.5.4 

    [root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

    [root@localhost apr-util-1.5.4]# make && make install

编译apache

    [root@localhost src]# tar zxf httpd-2.2.31.tar.gz   

    [root@localhost src]# cd httpd-2.2.31

    [root@localhost httpd-2.2.31]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre --enable-mods-shared=most --enable-so

mysql安装:

    # cd /usr/local/src

    # wget http://www.lishiming.net/data/attachment/forum/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz               (免编译二进制文件)


初始化:

    # tar zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz 

    # mv mysql-5.1.40-linux-x86_64-icc-glibc23 /usr/local/mysql

    # useradd -s /sbin/nologin mysql 

    # mkdir -p /data/mysql  

    # chown -R mysql:mysql /data/mysql

    # cd /usr/local/mysql   

    # ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

配置mysql:

    # cp support-files/my-large.cnf /etc/my.cnf

    # cp support-files/mysql.server /etc/init.d/mysqld

    # chmod 755 /etc/init.d/mysqld

编辑mysqld启动脚本,找到basedir和datadir添加路径:

    # vi /etc/init.d/mysqld 

      basedir=/usr/local/mysql 

      datadir=/data/mysql

    # chkconfig --add mysqld    增加mysql服务

    # chkconfig mysqld on       启动mysql服务

    # service mysqld  start         启动mysql

    # ps aux |grep mysqld       检查mysql是否启动成功

设置mysql环境变量:

       [root@master1 ~]# echo 'PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile                  [root@master1 ~]# source /etc/profile


登录数据库时出现

                [root@wwwww mysql]# mysql

                -bash: mysql: command not found       

                 错误,是因为没有设置环境变量

解决:① [root@master1 ~]# echo 'PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile                    [root@master1 ~]# source /etc/profile

                         # service mysqld  start

                          #mysql 

      ②# cp /usr/local/mysql/bin*  /usr/local/sbin

     ③# vim  /etc/profile 下面加一行

             PATH=/usr/local/mysql/bin:$PATH

 

php安装:

    # cd /usr/local/src

    # xshell本地传输 rz -y 加入php包

    # tar zxvf php-5.3.28.tar.gz

    # cd php-5.3.28

    # ./configure   --prefix=/usr/local/php   --with-apxs2=/usr/local/apache2/bin/apxs   --with-config-file-path=/usr/local/php/etc   --with-mysql=/usr/local/mysql   --with-libxml-dir   --with-gd   --with-jpeg-dir   --with-png-dir   --with-freetype-dir   --with-iconv-dir   --with-zlib-dir   --with-bz2   --with-openssl   --with-mcrypt   --enable-soap   --enable-gd-native-ttf   --enable-mbstring   --enable-sockets   --enable-exif   --disable-ipv6

出错 

解决:yum install -y  libxml2-devel --openssl openssl-devel --bzip2 bzip2-devel --libpng libpng-devel --libjpeg libjpeg-devel --freetype freetype-devel --libmcrypt-devel

(centos6默认的yum源没有libmcrypt-devel这个包,

      下载:rpm -ivh http://www.lishiming.net/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm )

   # make && make install

   # cp /usr/local/src/php-5.3.28/php.ini-production /usr/local/php/etc/php.ini

apache 结合 php:

   apache 主配置文件为 /usr/local/apache2/conf/httpd.conf

   # vim /usr/local/apache2/conf/httpd.conf

   找到:AddType application/x-gzip .gz .tgz 

   在该行下面添加:AddType application/x-httpd-php .php 

    找到:      <IfModule dir_module>           DirectoryIndex index.html       </IfModule> 

   将该行改为:      <IfModule dir_module>           DirectoryIndex index.html index.htm                         index.php      </IfModule> 

   找到:#ServerName www.example.com:80 

   修改为:ServerName localhost:80

测试配置文件是否正确

    # /usr/local/apache2/bin/apachectl -t  检查语法

    # /usr/local/apache2/bin/apachectl start

    # netstat -lnp |grep httpd             检查apache是否启动

    # curl localhost

      <html><body><hl>It Works!</hl></body></html>    说明成功

测试apache是否正确解析php

    # vim /usr/local/apache2/htdocs/1.php   写入

      <?

       php echo "PHP解析正常\n";  

      ?>  

    # curl localhost/1.php       测试

  显示 php解析正常   说明成功!

   

  

    

你可能感兴趣的:(local)