CENTOS 6.5全新主机安装配置LAMP

Centos6 64bit是Linode自动安装的,很干净,啥都没有,难免要编译东西,所以先把一些编译环境给yum好:

yum install gcc gcc-c++ make flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel
 libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel 
gettext-devel pcre-devel

修改时区:

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

修改host:

echo "HOSTNAME=webmaster" >> /etc/sysconfig/network
hostname "webmaster"

然后vim /etc/hosts:

127.0.0.1 localhost.localdomain localhost
xx.xx.xx.xx webmaster.onepx.com webmaster

xx.xx.xx.xx是VPS在Linode Manager上分配的IP。

安装Apache:

yum install httpd

Apache的配置文件在/etc/httpd/conf/httpd.conf,如果要往上加东西最好加在/etc/httpd/conf.d/这个文件夹里,命名为x.conf就可以,apache启动的时候会自动加载这个文件夹里所有的.conf文件。

添加域名,以onepx.com和二级域名doc.onepx.com为例。由于受之前用面板的影响,还是习惯把网站目录放在/home下,vim /etc/httpd/conf.d/vhost.conf,加入:

NameVirtualHost *:80
<VirtualHost *:80>
     ServerAdmin silihai@gmail.com
     ServerName onepx.com
     ServerAlias www.onepx.com
     DocumentRoot /home/onepx/public_html/
     ErrorLog /home/onepx/logs/error.log
     CustomLog /home/onepx/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
     ServerAdmin silihai@gmail.com
     ServerName doc.onepx.com
     ServerAlias www.doc.onepx.com
     DocumentRoot /home/onepx/public_html/doc/
     ErrorLog /home/onepx/logs/doc.error.log
     CustomLog /home/onepx/logs/doc.access.log combined
</VirtualHost>

启动apache前需要按照上面的目录结构建立目录:

mkdir -p /home/onepx/public_html
mkdir /home/onepx/public_html/doc
mkdir /home/onepx/logs

启动apache:

/etc/init.d/httpd start

以后在vhost.con中添加域名后都需要重启apache:

/etc/init.d/httpd restart

让Centos6开机的时候自动启动apache:

/sbin/chkconfig --levels 235 httpd on

安装mysql:

yum install mysql-server

系统启动时加载mysql:

/sbin/chkconfig --levels 235 mysqld on

启动mysql server:

/etc/init.d/mysqld start

Mysql配置文件在/etc/my.cnf,比较要紧的是解决编码问题,加入下列,一劳永逸:

[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8

然后重启mysql:

/etc/init.d/mysqld restart

运行:

mysql_secure_installation

作用是设置mysql密码,删除一些默认的东东。然后登录:

mysql -u root -p

创建mysql数据库和用户,数据库名为”blog”,用户”onepx”,密码”password”:

create database blog;
grant all on blog.* to 'onepx' identified by 'password';

导入已有数据库:

use blog;
source /home/之前的数据.sql;

搞定后quit。以后备份,不用登录mysql,在bash下:

mysqldump -u onepx -p blog > /home/backup_blog.sql

下面开始安装PHP:

yum install php php-pear php-mysql

PHP的配置文件在/etc/php.ini,同时也有目录/etc/php.d/,下面若干.ini文件,都是在启动apache的时候自动加载,加的东西可以往这里放,命名为xxx.ini就可以了,比如下面我要安装的eacclerator,安装之前还是先yum吧:

yum install php-gd httpd-devel php-mbstring php-xml php-xmlrpc php-devel

这两天eaccelerator官方网站上的源居然down掉了…只好去其它地方下:

wget http://voxel.dl.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/
eaccelerator-0.9.6.1.zip
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1
phpize
./configure -enable-eaccelerator=shared
make
make install

配置eaccelerator,vim /etc/php.d/eaccelerator.ini,我的配置:

extension="eaccelerator.so"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.check_mtime="1"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.debug="0"
eaccelerator.enable="1"
eaccelerator.filter=""
eaccelerator.optimizer="1"
eaccelerator.shm_max="0"
eaccelerator.shm_only="0"
eaccelerator.shm_prune_period="0"
; 设定cache超过32MB会导致apache无法启动,详见eaccelerator的配置。
eaccelerator.shm_size="96"
eaccelerator.shm_ttl="600"

别忘了:

mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

最后:

/etc/init.d/httpd restart

LAMP安装配置完毕!

喜欢的话订阅一个呗~第一时间收到文章更新哟~

发表评论

电子邮件地址不会被公开。