LAMP

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

构成组件

Linux、Apache、MySQL、PHP/Perl/Python

LAMP的优势

成本低廉

可定制、易于开发

方便易用、安全和稳定


1.准备工作

服务器IP:192.168.1.10

[root@crushlinux ~]# service iptablesstop //关闭防火墙

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

[root@crushlinux ~]# echo "192.168.1.10 www.benet.com" >> /etc/hosts

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

[root@crushlinux ~]# rpm –qa |grep httpd httpd-manual webalizer subversionmod_python mod_ssl mod_perl system-config-httpd php php-cli php-ldap php-commonphp-mysqlmysql-server mysql dovecot --nodeps

如果有相关冲突的包就要先卸载掉

  rpm  -e php  php-cli  php-ldap php-common  php-mysql  --nodeps

yum -y insatll gcc* 安装编译的环境gcc


tar zxvf httpd-2.2.9.tar.gz -C /usr/src/

cd /usr/src/httpd-2.2.9/

./configure --prefix=/usr/local/httpd --enable-so --enable-rewrite--enable-charset-lite --enable-cgi

  make && make install

  cd /usr/local/httpd/

   ls

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

#!/bin/sh

#chkconfig:345 61 61

#description:Apache httpd

[root@crushlinux local]# chmod +x /etc/init.d/httpd

[root@crushlinux local]# chkconfig --add httpd

[root@crushlinux local]# chkconfig --list httpd

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

[root@crushlinux local]# service httpd restart

编译安装LAMP平台和出现的问题_成本

[root@crushlinux local]# cd/usr/local/httpd/conf/

[root@crushlinux conf]# vi httpd.conf

编译安装LAMP平台和出现的问题_成本_02

编译安装LAMP平台和出现的问题_mysql_03

chkconfig httpd on


编译安装LAMP平台和出现的问题_成本_04



另外一种问题可能会遇到,我列出来:

问题2:

/usr/local/apache/bin/httpd: errorwhile 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@crushlinux conf]# vi/etc/ld.so.conf

/usr/local/lib

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

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

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

[root@crushlinux conf]#/usr/local/httpd/bin/apachectl start

Apache虚拟主机配置

如果需要在一个web服务器上面跑多个web站点就需要定义虚拟主机。通过虚拟主机web服务器可以充分利用服务器硬件资源,降低网站运行成本。

虚拟主机有以下三种类型:

   基于IP:一个站点使用一个IP地址


   基于端口:多个站点使用一个Ip地址,但是访问端口不同

   基于域名:多个站点使用一个Ip地址,但是域名不同

 

注意:中心主机和虚拟主机无法一起使用,如果使用虚拟主机就必须取消中心主机。

取消中心主机:注释中心主机的DocumentRoot即可。


虚拟主机的定义:

<VirtualHost  Host>

 

</VirtualHost>

 

基于IPHOST的写法

   IP180

   IP280

基于端口:

   IP80

   IP8080

基于域名:

   IP80

ServerName  不同


设置基于端口的虚拟主机:

cd /usr/local/httpd/

mkdir benet.com   vim index.html

mkdir accp.com     vim index.html

编译安装LAMP平台和出现的问题_企业网站_05

vim /usr/local/httpd/conf/httpd.conf 改两个地方:如下

编译安装LAMP平台和出现的问题_Linux_06


编译安装LAMP平台和出现的问题_服务器_07 

vim /usr/local/httpd/conf/extra/httpd-vhosts.conf 


编译安装LAMP平台和出现的问题_Linux_08

service httpd restart

编译安装LAMP平台和出现的问题_mysql_09

编译安装LAMP平台和出现的问题_Linux_10


设置基于域名的虚拟主机

先增加host记录:

编译安装LAMP平台和出现的问题_企业网站_11

vim /usr/local/httpd/conf/extra/httpd-vhosts.conf

编译安装LAMP平台和出现的问题_Linux_12

编译安装LAMP平台和出现的问题_成本_13编译安装LAMP平台和出现的问题_企业网站_14

编译安装LAMP平台和出现的问题_mysql_15


基于IP地址的就不演示了。需要添加一块网卡,要重启机器,格式如下:

IP地址虚拟主机设置:

建立虚拟主机配置文件

1
2
3
4
5
6
7
8
[root@ns1 html]# vim/etc/httpd/conf.d/virtual.conf
<VirtualHost 192.168.1.10:80>
 DocumentRoot "/usr/local/httpd/benet.com/"
</VirtualHost>
  
<VirtualHost 192.168.1.20:80>
 DocumentRoot "/usr/local/httpd/accp.com/"
</VirtualHost>



基于域名的虚拟主机加身份验证:

1
2
3
4
5
6
7
8
9
10
11
12
13
<VirtualHost 192.168.1.10>
 DocumentRoot "/usr/local/httpd/benet.com/"
 ServerName www.benet.com
 <Directory "/usr/local/httpd/benet.com/">
    AllowOverride authconfig
    AuthType Basic
    AuthName "Restrict area"
    AuthUserFile "/usr/local/httpd/conf/.awspad"
    Require valid-user
 </Directory>
</VirtualHost>

 

创建认证文件

12

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

[root@localhost ~]# bin/htpasswd -c /usr/local/httpd/conf/.awspad hujianli



编译安装LAMP平台和出现的问题_mysql_16

编译安装LAMP平台和出现的问题_企业网站_17

4.源代码安装Mysql

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

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

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

[root@crushlinux mysql-5.1.55]#./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312

[root@crushlinux ~]# make && make install



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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

编译安装LAMP平台和出现的问题_mysql_18

问题:

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

[root@crushlinux mysql-5.1.55]# rm -rf /var/lib/mysql

[root@crushlinux mysql-5.1.55]# /usr/local/mysql/bin/mysql_install_db --user=mysql

重启看看是否可用

编译安装LAMP平台和出现的问题_企业网站_19

[root@crushlinux mysql-5.1.55]# service mysqld start

Starting MySQL. [确定]

编译安装LAMP平台和出现的问题_成本_20

[root@crushlinux mysql-5.1.55]# ps aux|grep mysql

如果不可用请继续如下操作

[root@crushlinux mysql-5.1.55]# kill -9 mysqld_safe(Pid number)

[root@crushlinux mysql-5.1.55]# kill -9 mysqld (Pid number)

重启看看是否可用

[root@crushlinux mysql-5.1.55]# service mysqld start

[root@crushlinux mysql-5.1.55]# cd ~

编译安装LAMP平台和出现的问题_企业网站_21好了mysql安装完毕。

接下来准备php的安装环境:


5.源代码安装libmcrypt

[root@crushlinux~]# tar zxf libmcrypt-2.5.7.tar.gz -C/usr/src/

[root@crushlinux~]# cd /usr/src/libmcrypt-2.5.7/

[root@crushlinuxlibmcrypt-2.5.8]# ./configure

[root@crushlinuxlibmcrypt-2.5.8]# make && makeinstall

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

[root@crushlinuxlibmcrypt-2.5.8]# cd ~


6.源代码安装mhash

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

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

[root@crushlinuxmhash-0.9.9.9]# ./configure

[root@crushlinuxmhash-0.9.9.9]# make && makeinstall

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

[root@crushlinuxmhash-0.9.9.9]# cd ~



7.源代码安装mcrypt

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

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

[root@crushlinuxmcrypt-2.6.8]# ./configure

[root@crushlinuxmcrypt-2.6.8]# make && makeinstall

[root@crushlinuxmcrypt-2.6.8]# cd ~

编译安装LAMP平台和出现的问题_成本_22

这个问题没解决。。。。我会尽快找到答案的,,未完待续。。