zen-cart网站,模版,采集,二次开发

首页 » Linux » liunx基础 » 阅读文章

CentOS搭建 LAMP服务器环境

2012-03-07 23:58 154556 0 发表评论
标签:


前期准备

1.关闭SELlinux,编辑其配置文件

vi /etc/sysconfig/selinux

将SELinux=Enforcing改为SELinux=disabled,并重启系统

2.关闭防火墙

Netfilter/Iptables 默认80端口也是禁用的,先关闭

iptables -F

或者临时将HTTP、FTP端口添加进防火墙规则

iptables -I RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
iptables -I RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
service iptables save #保存配置规则

当然也可以直接编辑iptables配置文件

vi /etc/sysconfig/iptables

增加内容

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

保存退出后,重启iptables生效

service iptables restart

3.先查看apache mysql php是否安装

rpm -qa | grep httpd
rpm -qa | grep mysql
rpm -qa | grep php

如果安装了,要先卸载,使用yum remove

方法一:用yum工具来搭建LAMP

如果是本机网速不是很快的,可以改为光盘yum源,参照前面讲的将CentOS DVD改为默认yum源

1.安装Apache

yum -y install httpd

安装完成后,启用Apache

service httpd start
#或者
/etc/init.d/httpd start

查看Apache是否启动,可以

ps -le | grep httpd

查看Apache进程是否存在,或者在浏览器输入本机地址会出现apache测试页面

apche加入开机启动

chkconfig --list | grep httpd

开启要在哪个运行级开机启动

chkconfig --levels 3 httpd on

2.安装mysql

yum -y install mysql mysql-server

安装完成后,启用mysql

service mysqld start
#或者
/etc/init.d/mysqld start

设置mysql密码,默认密码为空

mysqladmin -u root -p password 123456 #设置root密码为123456

登陆mysql

mysql -u root -p

mysql加入开机启动

chkconfig --list | grep mysqld  #查看mysql的各运行级别状态
chkconfig --levels 3 mysqld on  #开启运行级别3下自启动

3.安装php

yum -y install php php-mysql

安装完成后,可以到网站更目录/var/www/html中写入php文件,用phpinfo()函数来查看下当前环境的信息。

4.增加一个rpmforge的源

RPMForge是CentOS系统下的软件仓库,拥有4000多种的软件包,被CentOS社区认为是最安全也是最稳定的一个软件仓库,这样有些东西就可以用yum来安装了

wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm  #下载
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.i386.rpm	#安装

5.安装gd库

service httpd restart
yum -y install php-gd*
yum -y install libpng
yum -y install freetype
yum -y install libxml2
yum -y install zlib

升级php

centos 5.x目前提供php版本为5.1.6,存在着比较多的漏洞,我们可以通过增加yum源的方式简单的升级php

rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
vi /etc/yum.repos.d/CentOS-Base.repo  #末尾增加如下内容
[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

#保存退出后
yum clean all
yum update php -y

升级php方法二

rpm --import http://repo.webtatic.com/yum/RPM-GPG-KEY-webtatic-andy
wget -P /etc/yum.repos.d/ http://repo.webtatic.com/yum/webtatic.repo
yum --enablerepo=webtatic --exclude=php*5.3* list php
yum --enablerepo=webtatic --exclude=php*5.3* update -y php

修正php升级引起的mysql问题

mysql_upgrade -uroot -p[mysql_password]

6.安装mcrypt,phpmyadmin需要用到

yum -y install php-mcrypt
yum -y install phpmyadmin

修改phpmyadmin.conf让用户可以远程登陆

vi /etc/httpd/conf.d/phpmyadmin.conf

注释掉下面的语句(前面加#)

<Directory "/usr/share/phpmyadmin">
  Order Deny,Allow
  Deny from all
  Allow from 127.0.0.1
</Directory>

然后重启apache

然后浏览器输入http://centos机IP/phpmyadmin,不过提示配置文件现在需要绝密的短语密码(blowfish_secret)。

配置phpmyadmin下的config.inc.php

vi /usr/share/phpmyadmin/config.inc.php

$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

改为

$cfg['blowfish_secret'] = 'www.ezencart.com'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

里面www.ezencart.com可以随意改为任意字符

7.伪静态

编辑apache配置文件

vi /etc/httpd/conf/httpd.conf

查找

LoadModule rewrite_module modules/mod_rewrite.so

如果前面有#,则去掉,如果没有则相应位置添加这一行

开启.htaccess支持

在配置文件中查找htaccess,将他下一行中

 AllowOverride None

改为

 AllowOverride All

方法二:源码包编译lamp环境

前期准备和上面一样

1.首先安装相关依赖包

sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

2.安装MySQL:

tar -zxvf mysql-5.0.41.tar.gz #解压源码包
cd mysql-5.0.41/

#配置mysql
./configure --prefix=/usr/local/mysql --with-extra-charsets=all --enable-thread-safe-client --enable-assembler --with-charset=utf8 --enable-thread-safe-client --with-extra-charsets=all --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile

make && make install #编译安装

#创建mysql用户和mysql组
groupadd mysql
useradd -g mysql mysql

#指定mysql的用户为mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql

#将mysql配置文件拷贝到/etc/my.cnf
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf

#修改文件夹所有者和所属组
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql/.

#mysql脚本加入开机启动(/etc/init.d是/etc/rc.d/init.d的一个软连接)
cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
chkconfig --level 245 mysql off

#记录了编译时使用的动态链接库的路径
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
echo "/usr/local/lib" >> /etc/ld.so.conf

#将/etc/ld.so.conf列出的路径下的库文件 缓存到/etc/ld.so.cache 以供使用
ldconfig

#软链接
ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql

#启动mysql
service mysql start
/usr/local/mysql/bin/mysqladmin -u root password 123456 (指定mysql的root登陆密码123456)

service mysql restart

3.安装Apache:

tar -zxvf httpd-2.2.9.tar.gz
cd cd httpd-2.2.9

#配置Apache
./configure --prefix=/usr/local/apache --enable-rewrite=shared --enable-so --enable-ssl --with-charset=UTF8 --disable-access --disable-auth --disable-charset-lite --disable-include --disable-log-config --disable-env --disable-setenvif --disable-mime --disable-status --disable-autoindex --disable-asis --disable-cgid --disable-cgi --disable-negotiation --disable-dir --disable-actions --disable-userdir --disable-alias --enable-so --enable-mods-shared='access auth auth_anon auth_dbm auth_digest dav dav_fs actions alias asis autoindex cache cern_meta cgi charset_lite deflate dir disk_cache env expires file_cache headers include info log_config logio mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias'

#编译安装
make && make install

#启动Apahce
/usr/local/apache/bin/apachectl start

#开机启动
echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.d/rc.local

4.安装PHP:

tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local
make && make install

tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
/sbin/ldconfig
cd libltdl
./configure --enable-ltdl-install
make && make install

tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make && make install
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make && make install

tar -zxvf php-5.2.14.tar.gz
gzip -d ./suhosin-patch-5.2.14-0.9.7.patch.gz
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1
cd php-5.2.14/
patch -p 1 -i ../suhosin-patch-5.2.14-0.9.7.patch
./buildconf --force
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --enable-magic-quotes --with-mysql=/usr/local/mysql --with-pear --enable-sockets --with-ttf --with-freetype-dir=/usr --enable-gd-native-ttf --with-zlib --enable-sysvsem --enable-sysvshm --with-libxml-dir=/usr --with-apxs2=/usr/local/apache/bin/apxs --with-iconv-dir=/usr/local --with-xmlrpc --enable-xml --enable-shmop --enable-zip --with-mhash --with-mcrypt --enable-discard-path --enable-bcmath --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --with-openssl
make ZEND_EXTRA_LIBS='-liconv'
make install
./libtool --finish /usr/local/src/php-5.2.14/libs
cp php.ini-dist /usr/local/php/etc/php.ini
echo 'ulimit -SHn 65535' >> /etc/rc.local

修改/usr/local/apache/conf/httpd.conf 末尾添加

# PHP5
AddType application/x-httpd-php .php .phtml .php5
AddType application/x-httpd-php-source .phps

在DirectoryIndex增加index.php

DirectoryIndex index.html index.html.var index.php index.php5

相关安全设置,/usr/local/php/etc/php.ini

expose_php=off
disable_functions=symlink,shell_exec,exec,proc_close,proc_open,popen,system,dl,passthru,escapeshellarg, escapeshellcmd

都设置完后,重启apache

/usr/local/apache/bin/apachectl restart

5.在安装ZendOptimizer加速器(典型脚本安装)

tar -zxvf ZendOptimizer-3.2.6-linux-glibc21-i386.tar.gz
cd ZendOptimizer-3.2.6-linux-glibc21-i386
sh install.sh

同意协议后,填写php.info的位置/usr/local/php/etc/ ,然后填写apache控制脚本位置 /usr/local/apache/bin/apachectl

安装成功后,可以通过phpinfo()函数看到页面上多了两行
with Zend Extension Manager v1.2.0, Copyright (c) 2003-2007, by Zend Technologies
with Zend Optimizer v3.2.6, Copyright (c) 1998-2007, by Zend Technologies

6.安装phpmyadmin

 tar -zxcf phpMyAdmin-3.0.0-rc1-all-languages.tar.gz
 cp -a /lamp/phpMyAdmin-3.0.0-rc1-all-languages  /usr/local/apache/htdocs/phpmyadmin
 cd /usr/local/apache/htdocs/phpmyadmin
 cp config.sample.inc.php config.inc.php

然后同方法一一样修改加密字符

相关日志:

评论 共0条 (RSS 2.0) 发表评论

  1. 暂无评论,快抢沙发吧。

发表评论

  • 
  • 插入代码

联系我 Contact Me

回到页首