CentOS 6.4下搭建WEB服务环境

2013-12-24 浏览:4289
CentOS 6.4下搭建WEB服务环境
评论:(0)复制地址

Apache+Nginx+Tomcat+PHP+Memcache+MySQL+phpMyAdmin

安装依赖环境

yum install -y gcc gcc-c++  makezlib zlib-devel pcre*  libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers perl-devel perl-ExtUtils-Embed

创建www用户组和用户

groupadd www
useradd -g www www -s /bin/bash

一、Apache安装

方法1:yum源安装

安装:

 yum install httpd

配置启动项

chkconfig --levels 235 httpd on

启动/停止/重启Apache

/etc/init.d/httpd start #启动start,停止stop,重启restart

访问验证

http://localhost  #在浏览器里输入主机ip 看到Apache界面即安装成功

Apache的默认文档根目录是在CentOS上的/var/www/html目录,配置文件是/etc/httpd/conf/httpd.conf。配置存储在的/etc/httpd/conf.d/目录

方法2:源码安装

待更新……

二、Nginx安装

方法1:yum源安装

方法2:源码安装

1、解压nginx压缩包并进入.

tar -xvzf nginx-1.4.1.tar.gz
cd nginx-1.4.1

2、编译nginx并安装.

./configure --prefix=/usr/local/nginx --user=www --group=www --with-rtsig_module --with-select_module --with-poll_module --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_perl_module --http-fastcgi-temp-path=/tmp --with-pcre --without-http_uwsgi_module --without-http_scgi_module --without-http_geo_module --without-http_map_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --add-module=/root/src/ngx_cache_purge-2.1
make && make install

3、配置nginx

安装完成

三、Tomcat安装

方法1:yum源安装

方法2:源码安装

1、安装jdk

./jdk-6u45-linux-x64.bin
mv jdk1.6.0_45 /usr/local/jdk

2、添加环境变量

####TOMCAT####
JAVA_HOME="/usr/local/jdk"
CLASS_PATH="$JAVA_HOME/lib:$JAVA_HOME/jre/lib"
PATH=".:$PATH:$JAVA_HOME/bin "
CATALINA_HOME="/usr/local/tomcat"
export JAVA_HOME CATALINA_HOME
####

3、解压tomcat包并移到安装目录

tar -xvzf apache-tomcat-7.0.37.tar.gz
mv apache-tomcat-7.0.37 /usr/local/tomcat

安装完成

四、PHP安装

方法1:yum源安装

方法2:源码安装

1、安装gd gd-devel

yum -y install gd gd-devel

2、安装libiconv

./configure --prefix=/usr/local/libiconv
make && make install

3、安装libmcrypt

./configure --prefix=/usr/local/libmcrypt 
 make && make install

4、解压php源码包

tar -xjvf php-5.3.19.tar.bz2
cd php-5.3.19

5、编译源码并安装

./configure  --prefix=/usr/local/php --enable-maintainer-zts --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-bcmath --enable-shmop --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-bz2 --enable-static --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-exif
make && make install

6、拷贝配置文件

cp php.ini-dist /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

7、启动php-fpm.

/usr/local/php/sbin/php-fpm

安装完成

五、Memcache安装

1、安装libevent

tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local/libevent
make && make install

2、安装memcached

tar -zxvf memcached-1.4.15.tar.gz 
cd memcached-1.4.15
./configure -prefix=/usr/local/memcached --with-libevent=/usr/local/libevent
make && make install

3、安装memcache(php插件)

tar vxzf memcache-3.0.8.tgz
cd memcache-3.0.8
/usr/local/php/bin/phpize
./configure -enable-memcache -with-php-config=/usr/local/php/bin/php-config -with-zlib-dir
make && make install

安装完成会有类似下面的提示:

Installing shared extensions:/usr/local/php/lib/php/extensions/no-debug-zts-20090626/

修改PHP的配置文件

vi /usr/local/php/etc/php.ini 做一下修改
extension_dir = “/usr/local/php/lib/php/extensions/no-debug-zts-20090626/“
extension = "memcache.so"  //如果有分号,把分号去掉!

4、安装eAccelerator加速器

tar jxvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
/usr/local/php/bin/phpize
./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
make && make install

记住生成的提示信息,将php.ini的extension_dir处填写生成的地址

/usr/local/php/lib/php/extensions/no-debug-zts-20090626/

根据php.ini的配置,建立eaccelerator文件夹并赋予权限

mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

5、运行memcached并加入启动项.

/usr/local/memcached/bin/memcached -d -m 100 -u www -l 127.0.0.1 -p 12000 -c 256 -P /tmp/memcached

安装完成

六、MySQL安装

方法1:yum安装.

方法2:cmake安装(新版mysql都是采用cmake方式安装)

1、安装cmake.

yum -y install cmake

2、解压mysql压缩包.

tar -xzvf mysql-5.5.25a.tar.gz

3、创建mysql用户及用户组.

groupadd mysql
useradd -g mysql mysql -s /sbin/nologin

4、创建mysql安装目录及数据库存放目录并改权限.

mkdir -p /usr/local/mysql
mkdir -p /home/mysql/data
chown -R mysql.mysql /home/mysql

5、进入解压文件夹中安装数据库.

cd mysql-5.5.25a
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/home/mysql/data -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0
make && make install

6.检验是否安装成功.

ls /usr/local/mysql/    
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files

有bin等以上文件的话,恭喜你已经成功安装了mysql.

7、初始化数据库,复制配置文件.

cd /usr/local/mysql
scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/home/mysql/data --user=mysql
cp support-files/my-medium.cnf /etc/my.cnf

8、使用下列命令把mysql添加为系统服务.

cd /usr/local/mysql/support-files/   
cp ./mysql.server /etc/init.d/mysqld  
/etc/init.d/mysqld restart

9、添加环境变量.

vi /etc/profile
export PATH=/usr/local/mysql/bin:$PATH
source /etc/profile

10、大工告成,创建root密码并登陆.

/usr/local/mysql/bin/mysqladmin -u root password 'new-password'  //创建密码
/usr/local/mysql/bin/mysql -uroot -p  //登入

安装完成

七、phpMyAdmin安装


请注意上诉顺序并非安装顺序,推荐安装顺序为mysql-php-memcache-nginx|apache-phpmyadmin.


评论:(0)复制地址

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。