LAMP平台部署及应用
什么是LAMP
目前最为成熟的一种企业网站应用模式,可提供动态Web站点应用及开发环境
构成组件
Linux、Apache、MySQL、PHP/Perl/Python
LAMP的优势
成本低廉
可定制、易于开发
方便易用、安全和稳定
一、安装apache
1.准备工作
服务器IP:192.168.3.10
[[email protected] ~]# service iptables stop //关闭防火墙
[[email protected] ~]# 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
[[email protected] ~]# tar xf httpd-2.2.17.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/httpd-2.2.17/
[[email protected] httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --enable-so --enable-
rewrite --enable-charset-lite --enable-cgi
[[email protected] httpd-2.2.17]# make && make install
--prefix: 指定将httpd服务程序安装到哪个目录
--enable-so: 启用动态加载模块支持
--enable-rewrite:启用网页地址重写功能
--enable-charset: 启用字符集支持
--enable-cgi: 启用CGI脚本程序支持
4.优化路径
[[email protected] httpd-2.2.17]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[[email protected] httpd-2.2.17]# cd /usr/local/
[[email protected] local]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[[email protected] ~]# vim /etc/init.d/httpd
#!/bin/sh
#chkconfig: 345 61 61
#description:Apache https
[[email protected] ~]# chmod +x /etc/init.d/httpd
[[email protected] ~]# chkconfig --add httpd
[[email protected] ~]# chkconfig --list httpd
[[email protected] ~]# 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
[[email protected] ~]# cd /usr/local/httpd/conf/
[[email protected] conf]# vi httpd.conf
97 #ServerName crushlinux.example.com:80
98 ServerName localhost:80
[[email protected] conf]# service httpd start
[[email protected] conf]# ps -aux |grep httpd
[[email protected] 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这一行
[[email protected] conf]#vi /etc/ld.so.conf
/usr/local/lib
[[email protected] conf]# /sbin/ldconfig -v
现在您已经将 Apach源代码安装在 /usr/local/httpd。本源代码安装支持可装载模块
和标准的 MPM prefork。之后,可以使用如下命令启动 Apache 服务器:
/usr/local/httpd/bin/apachectl start
二、安装mysql
1.源代码安装Mysql
[[email protected] ~]# useradd -M -u 49 -s /sbin/nologin mysql
[[email protected] ~]# tar xf mysql-5.1.55.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/mysql-5.1.55/
[[email protected] mysql-5.1.55]# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --
with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312
[[email protected] mysql-5.1.55]# make && make install
[[email protected] mysql-5.1.55]# cp support-files/my-medium.cnf /etc/my.cnf
[[email protected] mysql-5.1.55]# cd /usr/local/mysql/bin/
[[email protected] bin]# ./mysql_install_db --user=mysql
[[email protected] bin]# chown -R root:mysql /usr/local/mysql/
[[email protected] bin]# chown -R mysql /usr/local/mysql/var/
[[email protected] bin]# ln -s /usr/local/mysql/bin/* /usr/local/bin/
[[email protected] bin]# ln -s /usr/local/mysql/lib/mysql/* /usr/lib/
[[email protected] bin]# ln -s /usr/local/mysql/include/mysql/* /usr/include/
[[email protected] bin]# cd /usr/src/mysql-5.1.55/
[[email protected] mysql-5.1.55]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[[email protected] mysql-5.1.55]# chmod a+x /etc/rc.d/init.d/mysqld
[[email protected] mysql-5.1.55]# chkconfig --add mysqld
[[email protected] mysql-5.1.55]# chkconfig --list mysqld
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
[[email protected] mysql-5.1.55]# service mysqld restart
Shutting down MySQL. [确定]
Starting MySQL. [确定]
如果报错:(没有略过)
[[email protected] 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
[[email protected] ~]# netstat -anpt | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
3089/mysqld
三、安装其他软件包(php)
1.源代码安装libmcrypt
[[email protected] ~]# tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/libmcrypt-2.5.8/
[[email protected] libmcrypt-2.5.8]# ./configure && make && make install
[[email protected] libmcrypt-2.5.8]# ln -s /usr/local/lib/libmcrypt.* /usr/lib/
2.源代码安装mhash
[[email protected] ~]# tar xf mhash-0.9.9.9.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/mhash-0.9.9.9/
[[email protected] mhash-0.9.9.9]# ./configure && make && make install
[[email protected] mhash-0.9.9.9]# ln -s /usr/local/lib/libmhash* /usr/lib/
3.源代码安装mcrypt
[[email protected] ~]# tar xf mcrypt-2.6.8.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/mcrypt-2.6.8/
[[email protected] 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
[[email protected] ~]# tar xf php-5.3.6.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/php-5.3.6/
[[email protected] 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
[[email protected] 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组件
[[email protected] php-5.3.6]# ls /usr/src/php-5.3.6/php.ini-*
2.复制样例文件
[[email protected] php-5.3.6]# cp /usr/src/php-5.3.6/php.ini-development /usr/local/php5/php.ini
3.php.ini配置调整
[[email protected] ~]# 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模块(用于优化页面加载速度)
[[email protected] ~]# tar xf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/
[[email protected] php-5.3.x]# cp ZendGuardLoader.so /usr/local/php5/lib/php/
[[email protected] ~]# vim /usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
5.调整Apache配置
[[email protected] ~]# 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首页文件
[[email protected] ~]# service httpd restart
6.功能测试
1)测试PHP能否正常提供服务
[[email protected] ~]# vim /usr/local/httpd/htdocs/test1.php
<?php
phpinfo (); 内建函数用于显示PHP环境信息
?>
service httpd restart
浏览器输入:http://192.168.200.128/test1.php
2)测试PHP能否正常访问mysql数据库
[[email protected] ~]# 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‘] = ‘[email protected]‘; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
mysqladmin -u root password ‘123.com‘
12.
浏览器输入:http://192.168.3.10/phpMyAdmin/
用户名:root
密码:123.com
完成部署