用YUM升级CentOS系统中PHP和MySQL

用上umVPS后,很多时候在虚拟主机不用自己动手的事情都要自己搞定了,例如:PHP和MySQL的升级。因为不用自己动手,也动不了,所以冰古不太清楚虚拟主机的PHP和MySQL是不是会及时地更新。但用VPS,可以动手玩一下也保证安全,冰古是很乐意进行更新的。以下就是用YUM升级CentOS系统中PHP和MySQL的过程:

yum是CentOS系统自带的用于方便地添加/删除/更新RPM包的工具,它能自动解决包的倚赖性问题。
用yum更新PHP,只需用一条命令就可以搞定:

#yum update php


但问题来了,使用此命令后,系统告诉我,没有发现可更新的包。而当前的PHP版本只是5.2.1,PHP官方已经更新到5.2.6了。
经过一番询问,才知道原来CentOS系统的源里PHP仍旧是5.2.1,需要额外的源才能升级PHP。
根据外国网友的介绍,冰古添加了额外的源
登录SSH后依次运行下列命令:

#rpm --import http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka

#vi /etc/yum.repos.d/utterramblings.repo #文中这里是使用nano,但VPS不能启动nano,用vi代替也是可以的


在打开的文档中加入下面内容:

[utterramblings]
name=Jason's Utter Ramblings Repo
baseurl=http://www.jasonlitka.com/media/EL$releasever/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka


保存。
再次运行下面的命令就可以完成php的升级了

#yum update php


同理,运行下面命令,升级mysql

#yum update mysql

用PHP得到访问者的真实IP

在php中,通常我们用$_SERVER['REMOTE_ADDR']得到访问者的ip。但当访问者使用了代理,它只能得到代理的ip。这时使用下面的函数就能得到访问者的真实ip:

function getRealIpAddr(){
  if (!empty($_SERVER['HTTP_CLIENT_IP'])){//check ip from share internet
    $ip=$_SERVER['HTTP_CLIENT_IP'];
  }
  elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){//to check ip is pass from proxy
    $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  }else{
    $ip=$_SERVER['REMOTE_ADDR'];
  }
  return $ip;
}

事实上这个函数也不是万能,众所周知,头信息是可以伪造的。

在不同的浏览器上测试你的网页设计

Browsershots是一个在线截屏网站,输入你的网址,她会为你对该网站进行截屏。这样的网站也不稀奇,过去冰古也介绍过。但该网站包含的服务可能让你感到惊奇,Linux,Windows,Mac OS和BSD平台下共达59种浏览器可选,并且你可以定制“屏幕大小”,“颜色深度”,“JavaScript的开启”,“Java的开启”和“Flash的开启”。更为BT的是,这个服务你甚至可以利用她的API在你的机上架设同样的服务。

bingu.net在seamonkey 2.0 ubuntu 8.04上:
seamonky 2.0 ubuntu 8.04
bingu.net在safari 3.1 macOS X10.4上:
safari 3.1 mac os x 10.4
bingu.net在navigator 9.0.0.5 windows 2000上:
navigator 9.0.0.5 windows 2000

免费的photoshop网页设计教程

免费photoshop网页设计教程sitepoint.com限时免费派发The Photoshop Anthology: 101 Web
Design Tips, Tricks & Techniques.
(pdf格式)!对了,这个活动将在2008-6-13结束,要下就快下了。

这个是完整版,不是通常只能下的样板。正如书名描述的那样,她包含了用Photoshop进行网页设计方面的入门知识。共9章,295页。
章节简介:
Chapter 1: Getting Started with Photoshop
If you’re brand new to Photoshop, come here to learn about how to get around. If
you’re not brand new, you may still enjoy the time-saving tips included in these pages.

Chapter 2: Basic Skills
Build a good foundation for your use of Photoshop with these basic skills, including
resizing, rotating, and hiding parts of your picture.

Chapter 3: Creating Buttons
Make buttons of every shape and style by following the solutions in this chapter.

Chapter 4: Creating Backgrounds
Create tiling backgrounds that you can use in design elements such as headings and
menu bars, or even the page background itself!

Chapter 5: Working with Text
Learn to adjust type settings and make cool text effects for your next logo or web graphic.

Chapter 6: Adjusting Images
Fix, salvage, and adjust photographs that are over-exposed, under-exposed, or just
dull-looking. Or, take a good photograph and make it look even better!

Chapter 7: Manipulating Images
Start with a photograph or image and add your own effects such as scanlines,
refections, and more!

Chapter 8: Designing a Web Site
Bringing all the skills from previous chapters together, this chapter shows you how
to create web design mockups in Photoshop, then generate web-optimized images.

Chapter 9: Advanced Photoshop Techniques
Automate and animate! This chapter shows you how to save time when performing
similar tasks on many different fles, then shows you how to use Photoshop and
ImageReady to create animations.

加速wordpress的想法

是的,wordpress的确跑的不太快。最近在做这个模板的时候,顺便也产生了一些加速wordpress的想法。效果可能不太明显,但也能起到一定的作用吧。

plugin-hog-detector
从上图可以看到,在End Header中使用的时间几乎是90%。

wordpress-plugin-hog-detector
从这张中可以看到,End Header中花费的时间仍旧不少,但只能占到50%左右。而End Footer中占用了一大部分的时间。第一张图是本地没有使用插件时生成的,第二张是冰古blog使用了25个插件时生成的。由两张图片可以大致得出End Header和loop是wordpress默认任务使用的时间,而End Footer是插件花销的时间。

以上只是说明了一个几乎是众所周知的事实:wordpress真的跑不快,默认任务已经要大部分的时间来跑了,而插件是另一个让wordpress跑的慢的原因。

以下就是我加速wordpress的想法:
1. 不要定制性。怎样是不要定制性呢?打开你的wordpress,然后查看源代码,你可以看到类似这样的代码:

<!-- Added By Democracy Plugin. -->
<script type='text/javascript' src='http://bingu.net/blog/wp-content/plugins/democracy/democracy.js'></script>
<link rel='stylesheet' href='http://bingu.net/blog/wp-content/plugins/democracy/basic.css' type='text/css' />
<link rel='stylesheet' href='http://bingu.net/blog/wp-content/plugins/democracy/style.css' type='text/css' />


这个是Democracy插件利用wp_head()添加的,你大可以将上面的代码直接复制到你的模板中(我这里是举例,你不会真的把上面的代码加到你的模板中吧 :lol: ),然后修改这个插件的代码,找到类似这样的代码:

add_action('wp_head', 'jal_add_js');


将它屏蔽掉:

//add_action('wp_head', 'jal_add_js');

打开模板的header.php,你看到的可能是这样的:

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head profile="http://gmpg.org/xfn/11">
	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

	<title><?php bloginfo('name'); ?><?php wp_title(); ?></title>

	<style type="text/css" media="screen">
		@import url( <?php bloginfo('stylesheet_url'); ?> );
	</style>

	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo('rss2_url'); ?>" />
	<link rel="alternate" type="text/xml" title="RSS .92" href="<?php bloginfo('rss_url'); ?>" />
	<link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="<?php bloginfo('atom_url'); ?>" />

	<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
	<?php wp_get_archives('type=monthly&format=link'); ?>
	<?php //comments_popup_script(); // off by default ?>
	<?php wp_head(); ?>
</head>

<body>
<div id="rap">
<h1 id="header"><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></h1>


为什么不改成这样呢?

<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

	<title>你的blog名字<?php wp_title(); ?></title>

	<style type="text/css" media="screen">
		@import url( 'http://你的wordpress地址/wp-content/themes/你的模板名/style.css' );
	</style>

	<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://你的wordpress地址/wp-rss2.php" />
	<link rel="alternate" type="text/xml" title="RSS .92" href="http://你的wordpress地址/wp-rss.php" />
	<link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="http://你的wordpress地址/wp-feed.php" />

	<link rel="pingback" href="http://你的wordpress地址/xmlrpc.php" />
	<?php wp_head(); ?>
</head>

<body>
<div id="rap">
<h1 id="header"><a href="你的wordpress地址">你的blog名</a></h1>

关掉你的Widgets,直接修改模板文件。

上面都做了,你可能发现效果不是太明显,但还是能起一定的作用的。

2. 你可以看到除非你不使用插件,不关你怎么对wordpress进行优化其实都是杯水车薪,很难看到什么效果。其实最有效的方法,应该是压缩模板的html,css,js代码和对使用的图片进行优化。
你的顶部图片有20k大,如果你把它去掉后是什么概念,我相信这样的效果是很明显的。

当然这里说的方法可能有悖你的想法,牺牲可定制化来获得不太明显的加速,这的确有点可笑,不过这也是萝卜青菜啦。