LAMP
目前最为成熟的一种企业网站应用模式,可提供动态Web站点应用及开发环境
构成组件
Linux、Apache、MySQL、PHP/Perl/Python
LAMP的优势
成本低廉
可定制、易于开发
方便易用、安全和稳定
1.准备工作
服务器IP:192.168.1.10
[[email protected] ~]# service iptablesstop //关闭防火墙
[[email protected] ~]# setenforce 0 //关闭selinux
[[email protected] ~]# echo "192.168.1.10 www.benet.com" >> /etc/hosts
2.检查是否通过rpm方式安装了相关软件,防止冲突
[[email protected] ~]# 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
[[email protected] local]# chmod +x /etc/init.d/httpd
[[email protected] local]# chkconfig --add httpd
[[email protected] local]# chkconfig --list httpd
httpd 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭
[[email protected] local]# service httpd restart
[[email protected] local]# cd/usr/local/httpd/conf/
[[email protected] conf]# vi httpd.conf
chkconfig httpd on
另外一种问题可能会遇到,我列出来:
问题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这一行
[[email protected] conf]# vi/etc/ld.so.conf
/usr/local/lib
[[email protected] conf]# /sbin/ldconfig-v
现在您已经将 Apach源代码安装在/usr/local/httpd。本源代码安装支持可装载模块
和标准的 MPM prefork。之后,可以使用如下命令启动 Apache 服务器:
[[email protected] conf]#/usr/local/httpd/bin/apachectl start
Apache虚拟主机配置
如果需要在一个web服务器上面跑多个web站点就需要定义虚拟主机。通过虚拟主机web服务器可以充分利用服务器硬件资源,降低网站运行成本。
虚拟主机有以下三种类型:
基于IP:一个站点使用一个IP地址
基于端口:多个站点使用一个Ip地址,但是访问端口不同
基于域名:多个站点使用一个Ip地址,但是域名不同
注意:中心主机和虚拟主机无法一起使用,如果使用虚拟主机就必须取消中心主机。
取消中心主机:注释中心主机的DocumentRoot即可。
虚拟主机的定义:
<VirtualHost Host>
</VirtualHost>
基于IP:HOST的写法
IP1:80
IP2:80
基于端口:
IP:80
IP:8080
基于域名:
IP:80
ServerName 不同
设置基于端口的虚拟主机:
cd /usr/local/httpd/
mkdir benet.com vim index.html
mkdir accp.com vim index.html
vim /usr/local/httpd/conf/httpd.conf 改两个地方:如下
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
service httpd restart
设置基于域名的虚拟主机
先增加host记录:
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
基于IP地址的就不演示了。需要添加一块网卡,要重启机器,格式如下:
IP地址虚拟主机设置:
建立虚拟主机配置文件
1 2 3 4 5 6 7 8 |
[[email protected] html] # vim/etc/httpd/conf.d/virtual.conf
|
基于域名的虚拟主机加身份验证:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<VirtualHost 192.168.1.10>
|
创建认证文件
12 |
[[email protected] ~] # cd /usr/local/httpd/
[[email protected] ~]# bin/htpasswd -c /usr/local/httpd/conf/.awspad hujianli |
4.源代码安装Mysql
[[email protected] ~]# useradd -M -u 49 -s /sbin/nologin mysql
[[email protected] ~]# tar zxf 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] ~]# 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
MySQL manager or server PID file couldnot be found! [失败]
Starting MySQL.Manager of pid-file quitwithout updating fi[失败]
问题:
启动MYSQL报错StartingMySQL.Manager of pid-file quit without updating fi[失败]
[[email protected] mysql-5.1.55]# rm -rf /var/lib/mysql
[[email protected] mysql-5.1.55]# /usr/local/mysql/bin/mysql_install_db --user=mysql
重启看看是否可用
[[email protected] mysql-5.1.55]# service mysqld start
Starting MySQL. [确定]
[[email protected] mysql-5.1.55]# ps aux|grep mysql
如果不可用请继续如下操作
[[email protected] mysql-5.1.55]# kill -9 mysqld_safe(Pid number)
[[email protected] mysql-5.1.55]# kill -9 mysqld (Pid number)
重启看看是否可用
[[email protected] mysql-5.1.55]# service mysqld start
[[email protected] mysql-5.1.55]# cd ~
好了mysql安装完毕。
接下来准备php的安装环境:
5.源代码安装libmcrypt
[[email protected]~]# tar zxf libmcrypt-2.5.7.tar.gz -C/usr/src/
[[email protected]~]# cd /usr/src/libmcrypt-2.5.7/
[[email protected]]# ./configure
[[email protected]]# make && makeinstall
[[email protected]]# ln -s /usr/local/lib/libmcrypt.* /usr/lib/
[[email protected]]# cd ~
6.源代码安装mhash
[[email protected]~]# tar zxf mhash-0.9.9.9.tar.gz -C/usr/src/
[[email protected]~]# cd /usr/src/mhash-0.9.9.9/
[[email protected]]# ./configure
[[email protected]]# make && makeinstall
[[email protected]]# ln -s /usr/local/lib/libmhash* /usr/lib/
[[email protected]]# cd ~
7.源代码安装mcrypt
[[email protected]~]# tar zxf mcrypt-2.6.8.tar.gz -C/usr/src/
[[email protected]~]# cd /usr/src/mcrypt-2.6.8/
[[email protected]]# ./configure
[[email protected]]# make && makeinstall
[[email protected]]# cd ~
这个问题没解决。。。。我会尽快找到答案的,,未完待续。。