Linode Centos6 64位安装配置LAMP
这是我在Linode的VPS上,安装配置LAMP的过程。基础Linux系统Centos6 64bit;内存756MB;Intel(R) Xeon(R) L5520 @ 2.27GHz,4核心,理论上会有30个VPS分享这颗CPU -_-!。
我之前用的VPS都是带面板的,要么DirectAdmin,要么WHM/Cpanel,安装升级LAMP都有scripts,非常好用。但面板毕竟占内存,而VPS对内存是最敏感的,所以这次面板的任务我准备交给vim...
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
以下多数内容多数基于:Set up a LAMP Server on CentOS 6.
修改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 该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。 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 该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。 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
Centos6 LAMP安装配置完毕!
这次在Linode VPS上安装配置LAMP,我比较激进的选择了刚出没多久的Centos6,而且是64bit,并没有遇到什么障碍。本想全部自己编译安装来着,但那个实在是太折腾了,玩不起,还是yum吧...
如果你现在正在观看这篇"Linode Centos6 64bit安装配置LAMP",就说明一切正常 :)
Centos6安装配置LAMP后记:yum安装的PHP已经支持php mail,但是wordpress等依靠php mail发送回复通知的程序依然不会发送邮件,这时候需要安装sendmail。
yum install sendmail /sbin/chkconfig --levels 235 sendmail on /etc/init.d/sendmail start