码迷,mamicode.com
首页 > 其他好文 > 详细

LAMP平台的部署

时间:2015-04-08 01:20:19      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:lamp部署 linux

LAMP平台的搭建

1. 系统环境:

1)软件包版本:

httpd-2.2.9

mysql-5.1.56

php-

2)系统:CentOSrelease 6.4 (Final)- 2.6.32-358.el6.x86_64

3)系统关闭防火墙,禁用selinux

servicesiptables stop

chkconfigiptables off

sed -i‘s/enforcing/disabled/g’ /etc/selinux/config

setenforce0

2. 部署

2.1 部署apache

2.1.1 安装apache

快速执行命令:

cd /usr/src/

wget http://down1.chinaunix.net/distfiles/httpd-2.2.9.tar.bz2

tar jxf httpd-2.2.9.tar.bz2

cd httpd-2.2.9

./configure --prefix=/usr/local/httpd-2.2.9--enable-so --enable-rewrite --enable-cgi --enable-cgid--enable-mpms-shared=all --with-zlib --with-pcre

make && make install

 

演示步骤:

[root@LAMP~]# cd /usr/src/
[root@LAMPsrc]# wget http://down1.chinaunix.net/distfiles/httpd-2.2.9.tar.bz2
[root@LAMPsrc]# tar jxf httpd-2.2.9.tar.bz2 
[root@LAMPsrc]# cd httpd-2.2.9
[root@LAMPhttpd-2.2.9]#  ./configure--prefix=/usr/local/httpd-2.2.9 --enable-so --enable-rewrite --enable-cgi--enable-cgid--enable-mpms-shared=all  --with-zlib --with-pcre 
[root@LAMPhttpd-2.2.9]# make && make install


2.1.2 配置apache

1) 优化执行路径

快速执行命令:

cd /usr/local/

ln -s httpd-2.2.9/ httpd

ln -sf /usr/local/httpd-2.2.9/bin/* /usr/bin/

 

操作演示

[root@LAMPhttpd-2.2.9]# cd /usr/local/
[root@LAMPlocal]#  ln -s httpd-2.4.4/ httpd
[root@LAMPlocal]#  ln -sf/usr/local/httpd-2.4.4/bin/* /usr/bin/
[root@LAMPlocal]# httpd -v           //测试结果。可以看到apache的版本,路径优化成功
Serverversion: Apache/2.2.9 (Unix)
Serverbuilt:   Jan 17 2015 20:26:25


2) 设置开机自启动,并启动apache

快捷命令:

cp /usr/local/httpd-2.2.9/bin/apachectl/etc/init.d/httpd

chmod a+x /etc/init.d/httpd

sed -i ‘1a #description:Apache Controller Script‘/etc/init.d/httpd

sed -i ‘2a #chkconfig:- 85 15‘  /etc/init.d/httpd

chkconfig --add httpd

chkconfig httpd on

service httpd start

netstat -anput | grep httpd

 

操作演示

[root@LAMP~]# cp /usr/local/httpd-2.4.4/bin/apachectl /etc/init.d/httpd   //创建控制脚本
[root@LAMP~]#  sed -i ‘1a #description:Apache ControllerScript‘ /etc/init.d/httpd  [root@LAMP ~]# sed -i ‘2a #chkconfig:- 85 15‘  /etc/init.d/httpd     //在脚本中添加控制级别,若没有此两行,则无法正常加入系统服务。此操作也可以手动用vim编辑器添加
[root@LAMP~]#  chmod a+x /etc/init.d/httpd    //给控制脚本赋予执行权限,否则无法用server命令控制
[root@LAMP~]#  head -3 /etc/init.d/httpd   //查看添加是否成功   
#!/bin/sh
#description:Apache ControllerScript
#chkconfig:-85 15 
[root@LAMP~]#  ll /etc/init.d/httpd    //查看权限是否赋予正确
-rwxr-xr-x1 root root 3512 12月 16 12:38 /etc/init.d/httpd
[root@LAMP~]# chkconfig --add httpd
[root@LAMP~]# chkconfig httpd on
[root@LAMP~]# chkconfig --list | grep httpd
httpd           0:off   1:off  2:on    3:on    4:on   5:on    6:off
[root@LAMP ~]# service httpd start
httpd: apr_sockaddr_info_get() failed for LAMP
httpd: Could not reliably determine the server‘s fullyqualified domain name, using 127.0.0.1 for ServerName
提示:该两条信息是由于没有定义网站域名造成的,使用下面的命令。即可解决
[root@LAMP ~]# egrep "ServerName"/usr/local/httpd/conf/httpd.conf | tail -1
#ServerName www.example.com:80
[root@LAMP ~]# sed -i"s/#ServerName/ServerName/g" /usr/local/httpd/conf/httpd.conf
[root@LAMP ~]# sed -i"s/www.example.com/127.0.0.1/g" /usr/local/httpd/conf/httpd.conf
[root@LAMP ~]# egrep "ServerName"/usr/local/httpd/conf/httpd.conf | tail -1          
ServerName 127.0.0.1:80


2.1.3 客户端测试:

技术分享

测试成功,apache安装已经OK了 

 

2.2部署MySQL

2.2.1安装MySQL

1)创建mysql帐号

useradd-M -s /sbin/nologin -u 49 mysql

执行过程:

[root@LAMP~]# useradd -M -s /sbin/nologin -u 49 mysql

[root@LAMP~]# cat /etc/passwd | grep mysql

mysql:x:49:500::/home/mysql:/sbin/nologin

参数说明:

-M 不创建mysql家目录

-s 指定mysql登录的shell环境,nologin表示不登录shell

-u 指定mysql用户的uid

2) 检查系统是否存在mysql,存在则卸载。此外还要安装ncurses ncurses-devel

[root@LAMP~]# rpm -q mysqld

package mysqld isnot installed

[root@LAMP~]# yum installncurses ncurses-devel -y

3)下载mysql软件包,编译安装

cd /usr/src/    

wget http://down1.chinaunix.net/distfiles/mysql-5.1.56.tar.gz

tar zxf mysql-5.1.56.tar.gz

cd mysql-5.1.56

./configure--prefix=/usr/local/mysql-5.1.56 --with-unix-socket-path=/usr/local/mysql-5.1.56/tmp/mysql.sock  --with-charset=utf8--with-collation=utf8_general_ci   --with-extra-charsets=gbk,gb2312--localstatedir=/usr/local/mysql-5.1.56/data --enable-assembler--with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --enable-thread-safe-client--with-mysqld-user=mysql --with-big-table --without-debug  --with-pthread

make&& make install

执行过程:

[root@LAMPsrc]#  tar zxf  mysql-5.1.56.tar.gz
[root@LAMPsrc]#  cd mysql-5.1.56
[root@LAMPmysql-5.1.56]# ./configure --prefix=/usr/local/mysql-5.1.56--with-unix-socket-path=/usr/local/mysql-5.1.56/tmp/mysql.sock  --with-charset=utf8--with-collation=utf8_general_ci   --with-extra-charsets=gbk,gb2312--localstatedir=/usr/local/mysql-5.1.56/data --enable-assembler --with-mysqld-ldflags=-all-static  --with-client-ldflags=-all-static--enable-thread-safe-client --with-mysqld-user=mysql --with-big-table--without-debug  --with-pthread
[root@LAMPmysql-5.1.56]# make && make install


参数解释:

     ./configure --prefix=/usr/local/mysql-5.1.56       #指定安装路径

      --with-unix-socket-path=/usr/local/mysql-5.1.56/tmp/mysql.sock  \ #指定mysql.sock位置

      --with-charset=utf8          #指定mysql默认的字符集

       --with-collation=utf8_general_ci     

       --with-extra-charsets=gbk,gb2312    #指定mysql可扩展的字符集

      --localstatedir=/usr/local/mysql-5.1.56/data     #指定mysql 数据库文件存放的位置

      --enable-assembler     #允许使用汇编模式(优化性能)

      --with-mysqld-ldflags=-all-static   #服务器使用静态库(优化性能)

      --with-client-ldflags=-all-static   #客户端使用静态库(优化性能)

      --enable-thread-safe-client      #以线程方式编译mysql

     --with-mysqld-user=mysql        #指定mysql运行的用户

      --with-big-tables     #支持大表格式

      --without-debug     #使用非debug模式

      --with-pthread        #强制使用pthread线程序库编译

      配置完成之后,没有error提示,出现thanke you for choosemysql即可执行make 编译安装,最后make install 安装到系统

Thank you for choosing MySQL!

Remember to check the platform specific part of thereference manual

for hints about installing MySQL on your platform.

Also have a look at the files in the Docs directory.

 

2.2.2配置MySQL

1)生成mysql 的主配置文件 my.cnf

[root@LAMPmysql-5.1.56]# cp -f /usr/src/mysql-5.1.56/support-files/my-medium.cnf/etc/my.cnf
cp:overwrite `/etc/my.cnf‘? y           #覆盖掉原来的即可

2)生成mysql的启动文件,便于管理

[root@LAMPmysql-5.1.56]# cp -f/usr/src/mysql-5.1.56/support-files/mysql.server/etc/init.d/mysqld
[root@LAMPmysql-5.1.56]# chmod a+x /etc/init.d/mysqld
[root@LAMPmysql-5.1.56]# chkconfig --add mysqld
[root@LAMPmysql-5.1.56]# chkconfig mysqld on

3)链接mysql执行路径

[root@LAMP~]# ln -sf /usr/local/mysql-5.1.56/bin/* /usr/local/bin/
[root@LAMP~]# ln -sf /usr/local/mysql-5.1.56/lib/mysql/* /usr/lib
[root@LAMP~]# ln -sf /usr/local/mysql-5.1.56/include/mysql/* /usr/include/
[root@LAMP~]# ln -sf /usr/local/mysql-5.1.56/ /usr/local/mysql

5)初始化数据库

[root@LAMP~]# cd /usr/local/mysql/bin/
[root@LAMPbin]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql-5.1.56/--datadir=/usr/local/mysql-5.1.56/data
当出现两个OK时,表示初始化成功

6)设置权限

[root@LAMPbin]# chown -R root:mysql /usr/local/mysql-5.1.56/
[root@LAMPbin]# chown -R mysql /usr/local/mysql-5.1.56/data/

7)启动mysql

[root@LAMPbin]# service mysqld start   
StartingMySQL SUCCESS! 
[root@LAMPbin]# netstat -anput | grep mysql
tcp        0     0 0.0.0.0:3306               0.0.0.0:*                   LISTEN      42386/mysqld

 

 

2.3部署PHP

2.3.1安装php所需的组件(libiconv,libmcrypt,mhash,mcrypt-install)

1) 安装libiconv

cd /usr/src

wget http://down1.chinaunix.net/distfiles/libiconv-1.14.tar.gz

tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make && make install

2) 安装libmcrypt

cd /usr/src

wget http://down1.chinaunix.net/distfiles/libmcrypt-2.5.7.tar.gz

tar zxf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure
make
make install

2) 安装mhash

cd /usr/src

wget http://down1.chinaunix.net/distfiles/mhash-0.9.3.tar.gz

tar zxf mhash-0.9.3.tar.gz

cd mhash-0.9.3

./configure

make
make install

4)安装mcrypt

cd /usr/src

wget http://down1.chinaunix.net/distfiles/mcrypt-2.6.4.tar.gz

tar zxf mcrypt-2.6.4.tar.gz

cd mcrypt-2.6.4

echo "/usr/local/lib">>/etc/ld.so.conf

/sbin/ldconfig

./configure

make
make install

 

2.3.2安装PHP

1)安装所需组件包

yum install zlib libxml2 libjpeg freetype libpnggd  curl   zlib-devel libxml2-devel libjpeg-develfreetype-devel libpng-devel gd-devel openssl openssl-devel curl-devel –y

2)下载PHP包进行编译安装

cd /usr/src

wget http://down1.chinaunix.net/distfiles/php-5.3.6.tar.bz2

tar jxf php-5.3.6.tar.bz2

cd php-5.3.6

./configure --prefix=/usr/local/php --with-mcrypt--with-apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql--with-config-file-path=/usr/local/php --enable-mbstring -with-iconv=/usr/local/libiconv--enable-static  --with-xmlrpc --with-openssl--with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --enable-short-tags --enable-sockets--enable-zend-multibyte --enable-soap --enable-gd-native-ttf --enable-curl --enable-xsl--with-libxml-dir

make

make install

 

补充:

报错:configure: error: libpng.(a|so)not found.

原因:在/usr/lib下没有libpng.so这个文件,需要从/usr/lib64/下做软连接

解决:ln -s /usr/lib64/libpng.so/usr/lib/libpng.so

 

 

2.3.3配置PHP.整合LAMP

1)创建php的配置文件php.ini

cp -f /usr/src/php-5.3.6/php.ini-production  /usr/local/php/php.ini

2)修改php.ini中的参数

sed -i ‘s/short_open_tag = Off/short_open_tag = On/g‘  /usr/local/php/php.ini

3)修改httpd.conf,使与php整合到一块

sed -i  "54iAddType application/x-httpd-php .php" /usr/local/httpd/conf/httpd.conf

sed -i ‘s/DirectoryIndex/DirectoryIndex index.php/g‘  /usr/local/httpd/conf/httpd.conf

service httpd reload

 

测试:

创建测试网页tesx.php

<?php

Phpinfo()

?>

echo "<?php phpinfo() ?>"> /usr/local/httpd/htdocs/test.php

打开浏览器访问测试出现php相关信息表示LAMP安装成功

 


本文出自 “Study-Everyday” 博客,请务必保留此出处http://studys.blog.51cto.com/9736817/1629797

LAMP平台的部署

标签:lamp部署 linux

原文地址:http://studys.blog.51cto.com/9736817/1629797

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!