CentOS 6.2下搭建Web服务器

1Centos 6.2下搭建web服务器

    现在,Linux在Web应用愈来愈广,许多企业都采用Linux来搭建Web服务器,这样即节省了购买正版软件的费用,并且还可以提升服务器的安全性。php

    以前咱们介绍了如何在openSUSE 12.1下搭建Web服务器,里面详细介绍了在openSUSE 12.1下搭建服务器的方法,其实除了Red Hat和openSUSE,CentOS也是人们常常用到的搭建Web服务器的Linux版本。html

Centos搭建web服务器

    CentOS是企业Linux发行版领头羊Red Hat Enterprise Linux(如下称之为RHEL)的再编译版本,RHEL是不少企业采用的linux发行版本,须要向RedHat付费才可使用,并能获得付过费用的服务和技术支持和版本升级。这个CentOS能够像REHL同样的构筑linux系统环境,但不须要向RedHat付任何的费用,一样也得不到任何有偿技术支持和升级服务。mysql

    因为出自一样的源代码,所以有些要求高度稳定性的服务器以CentOS替代商业版的Red Hat Enterprise Linux使用。二者的不一样,在于CentOS并不包含封闭源代码软件。因此这里给你们介绍一下如何在CentOS6.2下与Apache 二、PHP五、MySQL搭建Web服务器,但愿对一些人有帮助。linux

   1.开始说明web

   本教程中使用的IP地址是192.168.0.100,主机名称为Server1.example.com 这些设置可能会有所不一样,你须要根据不一样状况进行修改。sql

2CentOS 6.2下安装MySQL

    2.开始安装MySQL5数据库

  首先咱们应该先用下面的命令安装MySQL:apache

  yum install mysql mysql-server浏览器

  而后咱们须要建立MySQL系统的启动键连接启动MySQL服务器,这样以便于MySQL在系统启动时自动启动安全

    chkconfig --levels 235 mysqld on
    /etc/init.d/mysqld start

  为MySQL root账户设置密码:

    mysql_secure_installation

    会出现下面的一系列提示:

  root@server1 ~]# mysql_secure_installation

  NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

  SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

  In order to log into MySQL to secure it, we'll need the current

  password for the root user. If you've just installed MySQL, and

  you haven't set the root password yet, the password will be blank,

  so you should just press enter here.

  Enter current password for root (enter for none):

  OK, successfully used password, moving on...

  Setting the root password ensures that nobody can log into the MySQL

  root user without the proper authorisation.

  Set root password? [Y/n] <-- ENTER

  New password: <-- yourrootsqlpassword

  Re-enter new password: <-- yourrootsqlpassword

  Password updated successfully!

  Reloading privilege tables..

  ... Success!

  By default, a MySQL installation has an anonymous user, allowing anyone

  to log into MySQL without having to have a user account created for

  them. This is intended only for testing, and to make the installation

  go a bit smoother. You should remove them before moving into a

  production environment.

  Remove anonymous users? [Y/n] <-- ENTER

  ... Success!

  Normally, root should only be allowed to connect from 'localhost'. This

  ensures that someone cannot guess at the root password from the network.

  Disallow root login remotely? [Y/n] <-- ENTER

  ... Success!

  By default, MySQL comes with a database named 'test' that anyone can

  access. This is also intended only for testing, and should be removed

  before moving into a production environment.

  Remove test database and access to it? [Y/n] <-- ENTER

  - Dropping test database...

  ... Success!

  - Removing privileges on test database...

  ... Success!

  Reloading the privilege tables will ensure that all changes made so far

  will take effect immediately.

  Reload privilege tables now? [Y/n] <-- ENTER

  ... Success!

  Cleaning up...

  All done! If you've completed all of the above steps, your MySQL

  installation should now be secure.

  Thanks for using MySQL!

  [root@server1 ~]#

3CentOS 6.2下安装Apache

   3.安装阿帕奇2

  Apache2的是做为一个CentOS的软件包,所以咱们能够直接用下面命令安装它:

    yum install httpd

  如今配置系统在引导时启动Apache

    chkconfig --levels 235 httpd on

  并启动Apache

    /etc/init.d/httpd start

  如今,您的浏览器到http://192.168.0.100,你应该看到Apache2的测试页:

Centos搭建web服务器
Apache 2测试网页

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

    4.安装PHP5

    咱们能够用下面的命令来安装PHP5

    yum install php

    安装完须要重启

    /etc/init.d/httpd restart

4CentOS 6.2下安装PHP5

  5.咱们能够安装PHP5和Apache的PHP5的模块以下:

     默认网站的文件根目录是在/srv/www/html中。如今咱们将在该目录中建立一个小型PHP文件(info.php的)在浏览器中调用它。该文件将显示不少关于咱们的PHP安装,如安装的PHP版本和有用的一些细节。

    vi /var/www/html/info.php

Centos搭建web服务器
修改细节

  如今,咱们能够用浏览器访问例如http://192.168.0.100/info.php文件

Centos搭建web服务器
PHP页面

  正如你所看到的,PHP5的工做,它经过Apache 2.0的处理程序,在服务器API线。若是你继续向下滚动,你会看到全部在PHP5中已经启用的模块。MySQL是没有列出,这意味着咱们没有在PHP5支持MySQL。

    6.PHP5得到MySOL的支持

  让PHP在MySQL中得到支持,咱们能够安装的php-mysql软件包。安装一些其余的PHP5模块,以及您可能须要的应用程序,这是一个好主意:

    yum search php

  还安装须要安装的

    yum install php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc

    如今从新启动Apache2的:

    /etc/init.d/httpd restart

  如今,重载http://192.168.0.100/info.php在您的浏览器,并再次向下滚动到模块部分。如今,你应该找到许多新的模块,包括MySQL模块:

Centos搭建web服务器
MySQL页面

5CentOS 6.2下安装phpMyAdmin

    7.安装phpMyAdmin

   phpMyAdmin是一个网络接口,经过它能够管理你的MySQL数据库。

    首先,咱们使CentOS系统RPMForge软件库的phpMyAdmin,而不是官方的CentOS 6.2库:

    因此须要导入RPMForge的GPG密钥:

    rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

    x86_64系统:

    yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

    在i386系统:

    yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

    安装phpmyadmin

    yum install phpmyadmin

    如今咱们能够设置phpMyAdmin,了咱们能够改变Apache的配置来让phpMyAdmin不只仅只能从localhost登陆。

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

Centos搭建web服务器
配置

    下一步,咱们从HTTP改变的phpMyAdmin的cookie来身份验证:

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

 Centos搭建web服务器
修改身份验证

    重启阿帕奇

    /etc/init.d/httpd restart

    在地址栏输入http://192.168.0.100/phpMyAdmin/:你就能够访问phpMyAdmin了。

Centos搭建web服务器
phpmyadmin页面

    CentOS能够获得RHEL的全部功能,甚至是更好的软件。但CentOS并不向用户提供商业支持,固然也不负上任何商业责任。

    若是你要将你的RHEL转到CentOS上,由于不但愿为RHEL升级而付费。固然,你必须有丰富linux使用经验,所以RHEL的商业技术支持对你来讲并不重要。但若是你是单纯的业务型企业,那么仍是建议你选购RHEL软件并购买相应服务。这样能够节省你的IT管理费用,并可获得专业服务。

    由此,对于CentOS 6.2下搭建Web服务器简单的介绍的了解,以及与Apache 二、PHP五、MySQL进行更加紧密的结合使用,相信企业用户更能从CentOS系统上获取商业上真正应用需求。

 

CentOS下apache绑定域名

CentOS下apache绑定域名以及apache绑定多个域名,首先要找到apache的配置文件httpd.conf的位置。CentOS操做系统通常在 /etc/httpd/conf 下,有的Linux操做系统版本是在 /etc/Apache2/conf  或 /usr/local/etc/apache  文件夹里面,剩下须要作的是修改配置文件httpd.conf,通常配置文件最下面有以下绑定域名说明:

  1. # VirtualHost example: 
  2. # Almost any Apache directive may go into a VirtualHost container. 
  3. # The first VirtualHost section is used for requests without a known 
  4. # server name. 
  5. #<VirtualHost *:80>
  6. #    ServerAdmin webmaster@dummy-host.example.com 
  7. #    DocumentRoot /www/docs/dummy-host.example.com 
  8. #    ServerName dummy-host.example.com 
  9. #    ErrorLog logs/dummy-host.example.com-error_log 
  10. #    CustomLog logs/dummy-host.example.com-access_log common 
  11. #</VirtualHost>

    你们能够依葫芦画瓢,也能够结合相关语法加入本身的配置说明,下面是我无忧程序的配置文件:一、* 星号修改为本身网站的IP地址 二、ServerAdmin管理员邮箱(无关紧要) 三、DocumentRoot网站文件在服务器的目录路径 四、ServerName绑定相应域名 五、ServerAlias泛解析绑定子域名 六、ErrorLog和CustomLog指定日志文件存放路径。

  1. <VirtualHost 175.102.8.117:80>
  2.     addDefaultCharset gbk 
  3.     DocumentRoot /chengxu
  4.     ServerName 66php.com 
  5.     ServerAlias *.66php.com 
  6.     ErrorLog /sym/logs/66php.com-error_log 
  7.     CustomLog /sym/logs/66php.com-access_log common 
  8. </VirtualHost>

    若是一个服务器绑定多个域名不是在ServerName添加多个域名,ServerName 后面只能加一个域名,要重复绑定则须要添加多加多个VirtualHost模块。

相关文章
相关标签/搜索