CentOS 6.3下搭建Web服务器

系统版本

查看系统版本

text 复制代码
[root@localhost ~]# uname -a
Linux centos-6-3 2.6.32-279.22.1.el6.x86_64 #1 SMP Wed Feb 6 03:10:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

准备工作

  1. 修改selinux配置文件(/etc/sysconfig/selinux) 关闭防火墙
shell 复制代码
sed -i 's|^SELINUX=enforcing|SELINUX=disabled|g' /etc/selinux/config
  1. 修改防火墙开放80、3306端口号,配置文件(/etc/sysconfig/iptables)
sehll 复制代码
echo '' >> /etc/sysconfig/iptables
echo '-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT' >> /etc/sysconfig/iptables
echo '-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT' >> /etc/sysconfig/iptables

一、安装MySQL

  1. 安装、设置随机启动、启动服务
shell 复制代码
yum -y install mysql mysql-server  #yum安装

chkconfig --levels 235 mysqld on   #设置随机启动

service mysqld start               #启动
service mysqld restart             #重启
service mysqld status              #查看状态
service mysqld stop                #停止
  1. 修改mysql密码
shell 复制代码
mysql_secure_installation

回显如下:

text 复制代码
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] y
New password: 
Re-enter new password: 
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] y
 ... 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] n
 ... skipping.

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] n
 ... skipping.

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... 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!
  1. 链接mysql, 表明安装成功
shell 复制代码
mysql -hlocalhost -uroot -p

二、安装apache

  1. 安装、设置随机启动、启动服务
shell 复制代码
yum -y install httpd              #yum安装

chkconfig --levels 235 httpd on   #设置随机启动

service httpd start               #启动
service httpd restart             #重启
service httpd status              #查看状态
service httpd stop                #停止
  1. 访问测试页,http://192.168.168.142

三、安装PHP5

  1. 安装
shell 复制代码
yum -y install php

service httpd restart    #重启httpd
  1. 添加测试代码
shell 复制代码
echo '<?php phpinfo();' > /var/www/html/info.php
  1. 访问测试代码,http://192.168.168.142/info.php
  1. 添加PHP5扩展模块

查询当前系统版本支持的模块

shell 复制代码
yum search php

回显:

text 复制代码
[root@centos-6-3 html]# yum search php
Loaded plugins: fastestmirror, presto, security
Loading mirror speeds from cached hostfile
============================================================== N/S Matched: php ===============================================================
cups-php.x86_64 : Common Unix Printing System - php module
graphviz-php.x86_64 : PHP extension for graphviz
php.x86_64 : PHP scripting language for creating dynamic web sites
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-imap.x86_64 : A module for PHP applications that use IMAP
php-intl.x86_64 : Internationalization extension for PHP applications
php-ldap.x86_64 : A module for PHP applications that use LDAP
php-mbstring.x86_64 : A module for PHP applications which need multi-byte string handling
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-odbc.x86_64 : A module for PHP applications that use ODBC databases
php-pdo.x86_64 : A database access abstraction module for PHP applications
php-pear.noarch : PHP Extension and Application Repository framework
php-pecl-apc.x86_64 : APC caches and optimizes PHP intermediate code
php-pgsql.x86_64 : A PostgreSQL database module for PHP
php-process.x86_64 : Modules for PHP script using system process interfaces
php-pspell.x86_64 : A module for PHP applications for using pspell interfaces
php-recode.x86_64 : A module for PHP applications for using the recode library
php-snmp.x86_64 : A module for PHP applications that query SNMP-managed devices
php-soap.x86_64 : A module for PHP applications that use the SOAP protocol
php-tidy.x86_64 : Standard PHP module provides tidy library support
php-xml.x86_64 : A module for PHP applications which use XML
php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
php-zts.x86_64 : Thread-safe PHP interpreter for use with the Apache HTTP Server
rrdtool-php.x86_64 : PHP RRDtool bindings
uuid-php.x86_64 : PHP support for Universally Unique Identifier library
php-enchant.x86_64 : Human Language and Character Encoding Support
php-pecl-apc-devel.x86_64 : APC developer files (header)
php-pecl-memcache.x86_64 : Extension to work with the Memcached caching daemon

  Name and summary matches only, use "search all" for everything.

安装模块以支持访问MySQL:

shell 复制代码
yum -y install php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc

service httpd restart    #重启httpd

访问测试页,查验是否已正确安装新模块:

四、安装phpMyAdmin

  1. 首先前往官方网站下载:phpMyAdmin-4.4.13-all-languages.zip,然后上传解压到/usr/share/目录下

  2. 编辑配置文件,vi /etc/httpd/conf.d/phpmyadmin.conf,内容如下:

text 复制代码
#
#   Web application to manage llySQL
#
#<Directory "/usr/share/phpmyadmin"
#   Order Deny,Allow
#   Deny from all
#   Allow from 127.0.0.1
#</Directory>

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phplyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin
  1. 配置phpmyadmin:
shell 复制代码
cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php
vi /usr/share/phpmyadmin/config.inc.php

PS:

相关推荐
HABuo3 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
礼拜天没时间.15 小时前
深入Docker架构——C/S模式解析
linux·docker·容器·架构·centos
礼拜天没时间.17 小时前
自定义镜像制作——从Dockerfile到镜像
linux·docker·容器·centos·bash
予枫的编程笔记2 天前
【Linux入门篇】Ubuntu和CentOS包管理不一样?apt与yum对比实操,看完再也不混淆
linux·人工智能·ubuntu·centos·linux包管理·linux新手教程·rpm离线安装
954L2 天前
CentOs7执行yum update出现链接404问题
linux·centos·yum·vault
威迪斯特3 天前
CentOS图形化操作界面:理论解析与实践指南
linux·运维·centos·组件·图形化·桌面·xserver
承渊政道3 天前
Linux系统学习【Linux基础开发工具】
linux·运维·笔记·学习·centos·编辑器
❀͜͡傀儡师3 天前
centos 7部署dns服务器
linux·服务器·centos·dns
予枫的编程笔记4 天前
【Linux入门篇】Linux入门不踩坑:内核、发行版解析+环境搭建全流程
linux·ubuntu·centos·vmware·xshell·linux入门·linux环境搭建
艾莉丝努力练剑4 天前
【Linux:文件】基础IO:文件操作的系统调用和库函数各个接口汇总及代码演示
linux·运维·服务器·c++·人工智能·centos·io