教程:CentOS 6下手动安装LAMP环境

教程:CentOS 6下手动安装LAMP环境

上次微魔和大家分享了有关在Debian 6下手动配置LAMP(Linux+Apache+PHP+MySQL)环境的系列教程,也承诺近期和大家分享在CentOS下的LAMP教程,看来这个“近期”要比大家想得还要快~今天我们继续相关的内容。其实从头到尾看下来,大家很快就会发现,其实CentOS和Debian很多东西都是相通的,不同的只是一些apt-get和yum这种形式上的东西,所以只要举一反三,相信Linux下Web环境的配置并不会给大家带来太多的烦恼。

本期教程目录

  • 安装/配置Apache
  • 安装/配置MySQL
  • 安装/配置PHP
  •  

    一、安装/配置Apache

    1.更新系统&安装Apache

    yum update yum install httpd

    推荐:使用如下命令备份Apache配置文件

    cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup

    为了给大家拓展思路,本次在CentOS上的教程,和大家分享Apache的另外一种绑定域名和创建虚拟机的方式~

    2.编辑/etc/httpd/conf.d/vhost.conf,假设我们要绑定example.com和example.org两个域名,则参照下面内容加入文件,

    NameVirtualHost *:80 ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /srv/www/example.com/public_html/ ErrorLog /srv/www/example.com/logs/error.log CustomLog /srv/www/example.com/logs/access.log combined ServerAdmin webmaster@example.org ServerName example.org ServerAlias www.example.org DocumentRoot /srv/www/example.org/public_html/ ErrorLog /srv/www/example.org/logs/error.log CustomLog /srv/www/example.org/logs/access.log combined

    3.因为我们上文指定了几个目录而这几个目录还不存在,所以,使用如下命令创建相应目录,

    mkdir -p /srv/www/example.com/public_html mkdir /srv/www/example.com/logs mkdir -p /srv/www/example.org/public_html mkdir /srv/www/example.org/logs

    4.启动Apache

    /etc/init.d/httpd start

    日后每次修改vhost.conf文件,都需要使用如下命令使Apache重新载入配置文件

    /etc/init.d/httpd reload

    5.设置Apache开机启动

    /sbin/chkconfig --levels 235 httpd on

     

    二、安装/配置MySQL

    1.安装MySQL

    yum install mysql-server

    2.设置MySQL开机自动启动

    /sbin/chkconfig --levels 235 mysqld on

    3.启动MySQL

    /etc/init.d/mysqld start

    MySQL的配置文件位于/etc/my.cnf

    4.安装mysql_secure_installation(MySQL安全设置)

    mysql_secure_installation

    5.附上常用的MySQL命令

    登录MySQL

    mysql -u root -p

    创建数据库vmvps(注意MySQL命令行下都需要以;结尾),并将该数据库所有权限赋予vmvps_user(密码为123)

    create database vmvps; grant all on vmvps.* to 'vmvps_user' identified by '123';

    退出MySQL

    quit

     

    三、安装/配置PHP

    1.安装PHP

    yum install php php-pear php-mysql

    2.编辑配置文件/etc/php.ini,修改如下内容

    error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR display_errors = Off log_errors = On error_log = /var/log/php.log max_execution_time = 300 memory_limit = 64M register_globals = Off

    最后,重启Apache,大功告成~

    /etc/init.d/httpd restart

    推荐站内搜索:广东服务器托管、服务器、宽带ip地址查询、美国虚拟主机、vps换ip、外贸空间、网站服务器asp免费空间申请、代理 ip、asp主机空间、