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

LAMP平台搭建部署

时间:2015-01-24 06:51:33      阅读:522      评论:0      收藏:0      [点我收藏+]

标签:lamp平台

LAMP平台部署及应用



什么是LAMP

目前最为成熟的一种企业网站应用模式,可提供动态Web站点应用及开发环境

构成组件

Linux、Apache、MySQL、PHP/Perl/Python

LAMP的优势

成本低廉

可定制、易于开发

方便易用、安全和稳定


一、安装apache


1.准备工作

服务器IP:192.168.3.10

[root@localhost ~]# service iptables stop       //关闭防火墙

[root@localhost ~]# setenforce 0 //关闭selinux


2.检查是否通过rpm方式安装了相关软件,防止冲突

rpm -e  httpd httpd-manual webalizer subversion mod_python mod_ssl mod_perl system-config-


httpd php php-cli php-ldap php-common php-mysql  mysql-server mysql dovecot 


3.源代码安装apache

[root@localhost ~]# tar xf httpd-2.2.17.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/httpd-2.2.17/

[root@localhost httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-


rewrite --enable-charset-lite --enable-cgi

[root@localhost httpd-2.2.17]# make && make install


--prefix:        指定将httpd服务程序安装到哪个目录

--enable-so:      启用动态加载模块支持

--enable-rewrite:启用网页地址重写功能

--enable-charset: 启用字符集支持

--enable-cgi:     启用CGI脚本程序支持


4.优化路径

[root@localhost httpd-2.2.17]# ln -s /usr/local/httpd/bin/* /usr/local/bin/

[root@localhost httpd-2.2.17]# cd /usr/local/

[root@localhost local]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

[root@localhost ~]# vim /etc/init.d/httpd

#!/bin/sh

#chkconfig: 345 61 61

#description:Apache https

[root@localhost ~]# chmod +x /etc/init.d/httpd 

[root@localhost ~]# chkconfig --add httpd

[root@localhost ~]# chkconfig --list httpd


[root@localhost ~]# service httpd restart


问题1:

httpd: apr_sockaddr_info_get() failed for localhost.com

httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 


for ServerName

httpd not running, trying to start


[root@localhost ~]# cd /usr/local/httpd/conf/

[root@localhost conf]# vi httpd.conf

     97 #ServerName crushlinux.example.com:80

     98 ServerName localhost:80

 

[root@localhost conf]# service httpd start

[root@localhost conf]# ps -aux |grep httpd

[root@localhost conf]# netstat -anpt | grep :80

tcp        0      0 :::80                       :::*                        LISTEN      


22238/httpd


问题2:

/usr/local/apache/bin/httpd: error while loading shared libraries: libiconv.so.2: cannot open 


shared object file: No such file or directory

有很多so模块在/usr/local/lib目录下,所以在/etc/ld.so.conf中加入/usr/local/lib这一行


[root@localhost conf]#vi /etc/ld.so.conf

/usr/local/lib

[root@localhost conf]# /sbin/ldconfig -v

现在您已经将 Apach源代码安装在 /usr/local/httpd。本源代码安装支持可装载模块

和标准的 MPM prefork。之后,可以使用如下命令启动 Apache 服务器:

/usr/local/httpd/bin/apachectl start


二、安装mysql


1.源代码安装Mysql

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

[root@localhost ~]# tar xf mysql-5.1.55.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/mysql-5.1.55/

[root@localhost mysql-5.1.55]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --


with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312

[root@localhost mysql-5.1.55]# make && make install


[root@localhost mysql-5.1.55]# cp support-files/my-medium.cnf /etc/my.cnf

[root@localhost mysql-5.1.55]# cd /usr/local/mysql/bin/

[root@localhost bin]# ./mysql_install_db --user=mysql


[root@localhost bin]# chown -R root:mysql /usr/local/mysql/

[root@localhost bin]# chown -R mysql /usr/local/mysql/var/

[root@localhost bin]# ln -s /usr/local/mysql/bin/* /usr/local/bin/

[root@localhost bin]# ln -s /usr/local/mysql/lib/mysql/* /usr/lib/

[root@localhost bin]# ln -s /usr/local/mysql/include/mysql/* /usr/include/


[root@localhost bin]# cd /usr/src/mysql-5.1.55/

[root@localhost mysql-5.1.55]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld

[root@localhost mysql-5.1.55]# chmod a+x /etc/rc.d/init.d/mysqld

[root@localhost mysql-5.1.55]# chkconfig --add mysqld

[root@localhost mysql-5.1.55]# chkconfig --list mysqld

mysqld         0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭


[root@localhost mysql-5.1.55]# service mysqld restart

Shutting down MySQL.                                       [确定]

Starting MySQL.                                            [确定]



如果报错:(没有略过)

[root@localhost mysql-5.1.55]#  service mysqld restart

MySQL manager or server PID file could not be found!       [失败]

Starting MySQL.Manager of pid-file quit without updating fi[失败]


问题:

启动MYSQL报错Starting MySQL.Manager of pid-file quit without updating fi[失败]

rm -rf /var/lib/mysql

/usr/local/mysql/bin/mysql_install_db --user=mysql 


[root@localhost ~]# netstat -anpt | grep :3306

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      


3089/mysqld  


三、安装其他软件包(php)


1.源代码安装libmcrypt

[root@localhost ~]# tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/libmcrypt-2.5.8/

[root@localhost libmcrypt-2.5.8]# ./configure && make && make install

[root@localhost libmcrypt-2.5.8]# ln -s /usr/local/lib/libmcrypt.* /usr/lib/


2.源代码安装mhash

[root@localhost ~]# tar xf mhash-0.9.9.9.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/mhash-0.9.9.9/

[root@localhost mhash-0.9.9.9]# ./configure && make && make install

[root@localhost mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash* /usr/lib/


3.源代码安装mcrypt

[root@localhost ~]# tar xf mcrypt-2.6.8.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/mcrypt-2.6.8/

[root@localhost mcrypt-2.6.8]# ./configure && make && make install


编译安装mcrypt报错:

configure: error: *** libmcrypt was not found

环境变量问题:gcc编译的时候根据自身定义的变量寻找相关函数库等文件

libmcrypt在环境变量中没有定义出来:所以需要手动添加:

export LD_LIBRARY_PATH=/usr/local/lib:$ LD_LIBRARY_PATH

继续编译安装吧!


4.源代码安装PHP

[root@localhost ~]# tar xf php-5.3.6.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/php-5.3.6/

[root@localhost php-5.3.6]# ./configure --prefix=/usr/local/php5 --with-mcrypt --with-


apxs2=/usr/local/httpd/bin/apxs --with-mysql=/usr/local/mysql --with-config-file-


path=/usr/local/php5 --enable-mbstring

[root@localhost php-5.3.6]# && make && make install


--prefix=/usr/local/php5 //指定安装目录

--with-mcrypt //加载扩展工具支持

--with-apxs2=/usr/local/httpd/bin/apxs //设置Apache提供的apxs模块程序文件位置

--with-mysql=/usr/local/mysql //指定mysql服务的安装路径

--with-config-file-path=/usr/local/php5 //指定php配置文件“php.ini”的存放路径

--enable-mbstring //启用多字节字符串功能


问题:

make && make install 报错信息如下:

/usr/bin/ld:cannot find-lltdl collect2:ld returned 1 exit status 

make :***[libphp5.la] Error 1


解决方案:

mount /dev/cdrom /mnt/

rpm -ivh /mnt/Server/libtool-1.5.22-7.el5_4.i386.rpm 

rpm -ivh /mnt/Server/libtool-ltdl-1.5.22-7.el5_4.i386.rpm 

rpm -ivh /mnt/Server/libtool-ltdl-devel-1.5.22-7.el5_4.i386.rpm


四、设置lamp组件


1.设置lamp组件

[root@localhost php-5.3.6]# ls /usr/src/php-5.3.6/php.ini-*


2.复制样例文件

[root@localhost php-5.3.6]# cp /usr/src/php-5.3.6/php.ini-development /usr/local/php5/php.ini


3.php.ini配置调整

[root@localhost ~]# vim /usr/local/php5/php.ini


773 default_charset = "utf-8" //设置默认字符集为utf-8

871 file_uploads = On //允许通过PHP网页上传文件

880 upload_max_filesize = 2M //允许上传的文件大小限制

883 max_file_uploads = 20 //每个HTTP请求最多允许上传的文件数

728 post_max_size = 8M //每次通过表单POST提交的数据量限制

226 short_open_tag = On //允许识别PHP短语法标记,即<? … ?>


4.添加ZendGuardLoader模块(用于优化页面加载速度)

[root@localhost ~]# tar xf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz -C /usr/src/

[root@localhost ~]# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/

[root@localhost php-5.3.x]# cp ZendGuardLoader.so /usr/local/php5/lib/php/

[root@localhost ~]# vim /usr/local/php5/php.ini

zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so

zend_loader.enable=1



5.调整Apache配置

[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf

53 LoadModule php5_module        modules/libphp5.so 配置加载PHP程序的模块文件

54 AddType application/x-httpd-php .php .phtml 添加对“.php”类型网页支持

169     DirectoryIndex index.php index.html         识别常见的php首页文件

[root@localhost ~]# service httpd restart



6.功能测试

1)测试PHP能否正常提供服务

[root@localhost ~]# vim /usr/local/httpd/htdocs/test1.php

<?php

phpinfo (); 内建函数用于显示PHP环境信息

?>

service httpd restart

浏览器输入:http://192.168.200.128/test1.php

技术分享


2)测试PHP能否正常访问mysql数据库

[root@localhost ~]# vi /usr/local/httpd/htdocs/test2.php

<?php

$link=mysql_connect(‘localhost‘,‘root‘,‘‘);

if($link) echo "Connect Successfully!";

else echo "Connect Faild!";

mysql_close();

?>


service httpd restart

浏览器输入:http://192.168.200.128/test2.php

技术分享


11、部署应用案例

tar xf phpMyAdmin-3.3.10-all-languages.tar.gz 

mv phpMyAdmin-3.3.10-all-languages /usr/local/httpd/htdocs/phpMyAdmin

cd /usr/local/httpd/htdocs/phpMyAdmin/

cp config.sample.inc.php config.inc.php       

vi config.inc.php

$cfg[‘blowfish_secret‘] = ‘pwd@123‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */


mysqladmin -u root password ‘123.com‘


12.

浏览器输入:http://192.168.3.10/phpMyAdmin/

用户名:root

密码:123.com


完成部署

本文出自 “空怀感” 博客,转载请与作者联系!

LAMP平台搭建部署

标签:lamp平台

原文地址:http://fuzhenyang.blog.51cto.com/9797988/1607597

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