LAMP平台搭建部署
LAMP平台部署及应用Linux+Apache+Mysql/MariaDB+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.
目前最为成熟的一种企业网站应用模式,可提供动态Web站点应用及开发环境
构成组件
Linux、Apache、MySQL、PHP/Perl/Python
LAMP的优势
成本低廉
可定制、易于开发
方便易用、安全和稳定
一、安装apache
1.准备工作
服务器IP:192.168.3.10
# service iptables stop //关闭防火墙
# setenforce 0//关闭selinux
2.检查是否通过rpm方式安装了相关软件,防止冲突
rpm -ehttpd httpd-manual webalizer subversion mod_python mod_ssl mod_perl system-config-
httpd php php-cli php-ldap php-common php-mysqlmysql-server mysql dovecot
3.源代码安装apache
# tar xf httpd-2.2.17.tar.gz -C /usr/src/
# cd /usr/src/httpd-2.2.17/
# ./configure --prefix=/usr/local/httpd --enable-so --enable-
rewrite --enable-charset-lite --enable-cgi
# make && make install
--prefix: 指定将httpd服务程序安装到哪个目录
--enable-so: 启用动态加载模块支持
--enable-rewrite:启用网页地址重写功能
--enable-charset: 启用字符集支持
--enable-cgi: 启用CGI脚本程序支持
4.优化路径
# ln -s /usr/local/httpd/bin/* /usr/local/bin/
# cd /usr/local/
# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
# vim /etc/init.d/httpd
#!/bin/sh
#chkconfig: 345 61 61
#description:Apache https
# chmod +x /etc/init.d/httpd
# chkconfig --add httpd
# chkconfig --list httpd
# 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
# cd /usr/local/httpd/conf/
# vi httpd.conf
97 #ServerName crushlinux.example.com:80
98 ServerName localhost:80
# service httpd start
# ps -aux |grep httpd
# 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这一行
#vi /etc/ld.so.conf
/usr/local/lib
# /sbin/ldconfig -v
现在您已经将 Apach源代码安装在 /usr/local/httpd。本源代码安装支持可装载模块
和标准的 MPM prefork。之后,可以使用如下命令启动 Apache 服务器:
/usr/local/httpd/bin/apachectl start
二、安装mysql
1.源代码安装Mysql
# useradd -M -u 49 -s /sbin/nologin mysql
# tar xf mysql-5.1.55.tar.gz -C /usr/src/
# cd /usr/src/mysql-5.1.55/
# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --
with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312
# make && make install
# cp support-files/my-medium.cnf /etc/my.cnf
# cd /usr/local/mysql/bin/
# ./mysql_install_db --user=mysql
# chown -R root:mysql /usr/local/mysql/
# chown -R mysql /usr/local/mysql/var/
# ln -s /usr/local/mysql/bin/* /usr/local/bin/
# ln -s /usr/local/mysql/lib/mysql/* /usr/lib/
# ln -s /usr/local/mysql/include/mysql/* /usr/include/
# cd /usr/src/mysql-5.1.55/
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# chmod a+x /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --list mysqld
mysqld 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
# service mysqld restart
Shutting down MySQL. [确定]
Starting MySQL. [确定]
如果报错:(没有略过)
#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
# netstat -anpt | grep :3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
3089/mysqld
三、安装其他软件包(php)
1.源代码安装libmcrypt
# tar xf libmcrypt-2.5.8.tar.gz -C /usr/src/
# cd /usr/src/libmcrypt-2.5.8/
# ./configure && make && make install
# ln -s /usr/local/lib/libmcrypt.* /usr/lib/
2.源代码安装mhash
# tar xf mhash-0.9.9.9.tar.gz -C /usr/src/
# cd /usr/src/mhash-0.9.9.9/
# ./configure && make && make install
# ln -s /usr/local/lib/libmhash* /usr/lib/
3.源代码安装mcrypt
# tar xf mcrypt-2.6.8.tar.gz -C /usr/src/
# cd /usr/src/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
# tar xf php-5.3.6.tar.gz -C /usr/src/
# cd /usr/src/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
# && 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 :*** 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组件
# ls /usr/src/php-5.3.6/php.ini-*
2.复制样例文件
# cp /usr/src/php-5.3.6/php.ini-development /usr/local/php5/php.ini
3.php.ini配置调整
# 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模块(用于优化页面加载速度)
# tar xf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz -C /usr/src/
# cd /usr/src/ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/
# cp ZendGuardLoader.so /usr/local/php5/lib/php/
# vim /usr/local/php5/php.ini
zend_extension=/usr/local/php5/lib/php/ZendGuardLoader.so
zend_loader.enable=1
5.调整Apache配置
# 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首页文件
# service httpd restart
6.功能测试
1)测试PHP能否正常提供服务
# vim /usr/local/httpd/htdocs/test1.php
<?php
phpinfo ();内建函数用于显示PHP环境信息
?>
service httpd restart
浏览器输入:http://192.168.200.128/test1.php
2)测试PHP能否正常访问mysql数据库
# 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
完成部署
页:
[1]