jacky4955 发表于 2015-8-19 09:55:28

redhat 搭建LAMP环境

  1.安装mysql
  这里用rpm包安装,需要一下四个rpm包:

   MySQL-server-5.0.45-0.i386.rpm
 MySQL-devel-5.0.45-0.i386.rpm
 MySQL-client-5.0.45-0.i386.rpm
 MySQL-shared-5.0.45-0.i386.rpm
  直接执行:
   #rpm –ivh Mysql-*.rpm
  设置密码:
   # mysqladmin -u root password 密码。
  配置:
  这部分转自:http://www.iyunv.com/xiaochaohuashengmi/archive/2011/10/18/2216087.html
  /**********************************************************************/


目录



1、数据库目录

   /var/lib/mysql/

2、配置文件

    /usr/share/mysql   (mysql.server命令及配置文件)

3、相关命令

   /usr/bin   (mysqladmin mysqldump等命令)

4、启动脚本

   /etc/rc.d/init.d/   (启动脚本文件mysql的目录)





配置



将/usr/share/mysql/my-medium.cnf复制到/etc/my.cnf,以后修改my.cnf文件来修改mysql的全局设置

将my.cnf文件中的innodb_flush_log_at_trx_commit设成0来优化  后添加添加lower_case_table_names设成1来不区分表名的大小写




设置字符集

MySQL的默认编码是Latin1,不支持中文,要支持需要把数据库的默认编码修改为gbk或者utf8。



1、中止MySQL服务(bin/mysqladmin -u root shutdown)

  2、在/etc/下找到my.cnf,如果没有就把MySQL的安装目录下的support-files目录下的my-medium.cnf复制到/etc/下并改名为my.cnf即可

  3、打开my.cnf以后,在和下面均加上default-character-set=utf8,保存并关闭

  3、打开my.cnf以后,在下面添加default-character-set=utf8,在下面添加character_set_server = utf8


  4、启动MySQL服务(bin/mysqld_safe &)



  出错时要注意查看日志信息:/var/lib/mysql/localhost.localdomain.err

  5、

查询字符集:show variables like '%set%';





增加MySQL用户

格式:



grant select on 数据库.* to 用户名@登录主机 identified by "密码"









grant select,insert,update,delete on *.* to user_1@'%' Identified by '123';
grant all on *.* to user_1@'localhost' Identified by '123';



远程访问



  其一: 







GRANT ALL PRIVILEGES ON *.* TO xoops_root@'%' IDENTIFIED BY '654321';
  允许xoops_root用户可以从任意机器上登入MySQL。



  其二:



  编辑 /etc/mysql/my.cnf



  >skip-networking => # skip-networking



  这样就可以允许其他机器访问MySQL了。     grant all on *.* to 'root'@'ip' identified by 'password';






备份与恢复

备份

进入到库目录,cd /val/lib/mysql





mysqldump -u root -p --opt aaa > back_aaa
恢复



mysql -u root -p ccc < back_aaa  /***********************************************************************************/
  2.安装apache
  这部分转自:http://www.iyunv.com/huzhiwei/archive/2012/07/19/2599854.html
  /***********************************************************************************/
  不知道为什么在安装apache2.2.22版本的时候没有任何问题,直接使用命令
  ./configure --prefix=/usr/local/apache2 –-sysconfdir=/etc/httpd --enable-proxy --enable-so --enable-mods-shared=most --with-mpm=worker --enable-shared=max --enable-module=rewrite --enable-module=so
  没有任何问题,不过在安装新版本2.4.2的时候就会报错。
  解决方案如下:
  #./configure --prefix……检查编辑环境时出现:
checking for APR... no
configure: error: APR not found . Please read the documentation.
  可以用./configure –help | grep apr 查看帮助。
--with-included-apr Use bundled copies of APR/APR-Util
--with-apr=PATH prefix for installed APR or the full path to apr-config
--with-apr-util=PATH prefix for installed APU or the full path to
安装APR(Apache Portable Runtime )
# cd /tmp/52lamp/ //源码存放位置
# tar -zxvf apr-1.4.2.tar.gz //unzip -o apr-1.4.2.zip
# cd apr-1.4.2
# ./configure
# make
# make install
  再次检查编译环境出现
checking for APR-util... no
configure: error: APR-util not found . Please read the documentation.
  # ./configure –help | grep apr-util
--with-apr-util=PATH prefix for installed APU or the full path to
  # tar -zxvf apr-util-1.3.9.tar.gz
# cd apr-util-1.3.9
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
  ./configure仍提示APR-util not found,增加--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util后出现
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
  # ./configure –help | grep pcre
--with-pcre=PATH Use external PCRE library
  # unzip -o pcre-8.10.zip
# cd pcre-8.10
# ./configure --prefix=/usr/local/pcre
# make
# make install
  继续安装Apache/httpd,./configure 时加上参数 --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre,这个问题就解决了。
  /***********************************************************************************/
  测试一下Apache配置文件的语法
   /usr/local/apache2/bin/apachectl –t
  启动Apache
   /usr/local/apache2/bin/apachectl -k start&
  我在安装的时候就有明明安好,但是无法启动apache的现象,百思不得其解。后来换了个低版本的安装,就发现能够正常启动了。好像是apache对apr和apr-util的版本是有要求的。
  将Apache添加到自动启动中
  echo '/usr/local/apache2/bin/apachectl -k start&'>>/etc/rc.d/rc.local
  检查Apache的端口是否跑起来了
  netstat -an |grep 80
  将Apache添加到系统服务中去
   cp /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/httpd
   ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S61httpd
  ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc4.d/S61httpd
  
  ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc5.d/S61httpd
  

vim /etc/rc.d/init.d/httpd
在第二行处添加:
#chkconfig:345 61 61
#description:Apache
执行:
chkconfig --add httpd
ok,apache安装完毕
3、安装PHP
这部分转自:http://www.fkblog.org/blog619

  ##### zlib #####
Zlib 软件包包含 zlib 库,很多程序中的压缩或者解压缩函数都会用到这个库.


tar -zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3./configure --prefix=/usr/local/zlib
make && sudo make install

  ##### FreeType #####


tar -jxvf freetype-2.3.5.tar.bz2
cd freetype-2.3.5./configure --prefix=/usr/local/freetype
make && sudo make install

  ##### LibPNG #####


tar -zxvf libpng-1.2.20.tar.gz
cd libpng-1.2.20
cp scripts/makefile.linux makefile
./configure --prefix=/usr/local/libpng
make &&make install

  ##### Jpeg (让GD支持JPEG)#####


tar -zxvf jpegsrc.v6b.tar.gz
mkdir /usr/local/jpeg
mkdir /usr/local/jpeg/bin
mkdir /usr/local/jpeg/lib
mkdir /usr/local/jpeg/include
mkdir /usr/local/jpeg/man
mkdir /usr/local/jpeg/man/man1
./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
make && make install

  ##### GD Library #####


tar -zxvf gd-2.0.35.tar.gz
cd gd-2.0.35./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --with-png --with-zlib=/usr/local/zlib
make && make install

  安装过程可能出现以下错误信息


  把报错信息“configure.ac:64: error: possibly undefined macro: AM_ICONV”


  解决办法 (文件包已下载好)
到 http://www.gnu.org/software/gettext/ 下载了gettext-0.18.1.1.tar.gz
cp /usr/lib/libattr.* /lib/ (这个在转载的文章里没说,是因为make的时候报错说没有libattr.la这个文件,所以要复制过去)


tar xzf gettext-0.17.tar.gz
cd gettext-0.17./configure
make
make install

  经过以上操作,回去安装g d 就没有问题了!


  ##### libxml2 #####


tar -zxvf libxml2-2.6.26.tar.gz
cd libxml2-2.6.26./configure --prefix=/usr/local/libxml2 --with-zlib=/usr/local/zlib
make && make install

  ##### libxslt #####


tar -zxvf libxslt-1.1.17.tar.gz
cd libxslt-1.1.17./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
make && make install

  ##### curl #####


tar -zxvf curl-7.21.6.tar.gz
cd curl-7.21.6
mkdir -p /usr/local/curl
./configure --prefix=/usr/local/curl --with-ssl
make && make install

  
  ##### PHP #####
下载php
php下载地址:http://php.net/downloads.php


tar -zxvf php-5.3.5.tar.gz
cd php-5.3.5./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-gd --enable-gd-native-ttf --with-jpeg-dir=/usr/local/jpeg--with-png --with-ttf --with-zlib --with-zlib-dir=/usr/local/zlib--with-curl=/usr/local/curl --with-freetype-dir=/usr/local/freetype--with-mysql --with-iconv --with-mbstring --enable-mbstring=all --enable-ftp--with-libxml=/usr/local/libxml2 --with-xslt-dir=/usr/local/libxslt --with-pear=/usr/local/php/pear
make && sudo make install
cp php.ini-development /usr/local/php/lib/php.ini

  如果编译时出现错误,请注意错误提示!
  到这边LAMP环境安装完成
  
  4、Apache+PHP配置
   LoadModule php5_module modules/libphp5.so
   AddType application/x-httpd-php .php .php5 .phtml
   AddType application/x-httpd-php-source .phps
   DirectoryIndex index.html index.php index.php5 index.phtml
   DocumentRoot"/var/www"
  
页: [1]
查看完整版本: redhat 搭建LAMP环境