<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bernie Yu &#187; php</title>
	<atom:link href="http://bernieyu.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://bernieyu.com</link>
	<description>复刻生活</description>
	<lastBuildDate>Tue, 17 May 2016 09:03:15 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>VPS搭建LNMP过程全记录</title>
		<link>http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/</link>
		<comments>http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/#comments</comments>
		<pubDate>Tue, 09 Jun 2015 08:56:47 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[vps]]></category>
		<category><![CDATA[安装]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=227</guid>
		<description><![CDATA[最近有朋友新买一个VPS，让帮忙搭建服务器（Linux + Nginx + MySQL + PHP）。 本来觉 ... <a class="more-link" href="http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<p>最近有朋友新买一个VPS，让帮忙搭建服务器（Linux + Nginx + MySQL + PHP）。<br />
本来觉得手到擒来的事，可操作起来却发现有些东西记忆已经模糊了。帮朋友弄好后，赶紧把过程记下来，以备后查。</p>
<ol>
<li>更新系统
<ul>
<li>
<pre>apt-get update
apt-get upgrade</pre>
</li>
</ul>
</li>
<li>安装MySQL
<ul>
<li>
<pre>apt-get install mysql-server mysql-client</pre>
<p>MySQL 安全设置</p>
<pre>mysql_secure_installation</pre>
<p>过程中会询问是否更改 root密码，是否移除匿名用户，是否禁止root远程登录等。</li>
</ul>
</li>
<li>安装Nginx
<ul>
<li>
<pre>apt-get install nginx
service nginx start</pre>
<p>如果没有service命令，则使用</p>
<pre>/etc/init.d/nginx start</pre>
<p>直接访问IP地址，验证nginx安装是否成功<br />
<img class="alignnone size-full wp-image-229" src="http://bernieyu.com/wp-content/uploads/2015/06/20150609154658.png" alt="20150609154658" width="390" height="181" /></li>
</ul>
</li>
<li>安装PHP
<ul>
<li>
<pre>apt-get install php5-fpm php5-gd php5-mysql php5-curl</pre>
<p>安装完毕之后，查看PHP的版本，验证安装是否成功 ：</p>
<pre>root@vultr:/www# php5-fpm -v
PHP 5.3.10-1ubuntu3.18 (fpm-fcgi) (built: Apr 17 2015 15:08:33)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies</pre>
</li>
</ul>
</li>
<li>配置PHP-FPM
<ul>
<li>编辑/etc/php5/fpm/php.ini
<pre>vi /etc/php5/fpm/php.ini</pre>
<pre>cgi.fix_pathinfo=0

error_reporting =E_ALL | E_STRICT

display_errors = On

log_errors = On
error_log = /var/log/php_error.log</pre>
</li>
<li>编辑 /etc/php5/fpm/pool.d/www.conf
<pre>vi /etc/php5/fpm/pool.d/www.conf</pre>
<pre>user = www-data
group = www-data

;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660

pm.status_path = /fpm_status</pre>
</li>
<li>重启php5-fpm
<pre>service php5-fpm restart</pre>
</li>
</ul>
</li>
<li>配置Nginx
<ul>
<li>编辑/etc/nginx/nginx.conf
<pre>user  www-data;
worker_processes  4;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    server_tokens off;

    gzip  on;
    gzip_disable "msie6";
    gzip_buffers 4 16K;
    gzip_comp_level 5;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript;
    gzip_vary on;
    include /etc/nginx/sites-available/*.conf;
}</pre>
</li>
</ul>
</li>
<li>配置网站
<ul>
<li>新建/www/test目录
<pre>mkdir /www
mkdir /www/test</pre>
</li>
<li>新建index.php
<pre>vi /www/test/index.php</pre>
<pre>&lt;?php

phpinfo();

?&gt;</pre>
</li>
<li>更改目录权限
<pre>chown -R www-data:www-data /www/test</pre>
</li>
<li>新建网站配置
<pre>vi /etc/nginx/conf.d/www.test.com.conf</pre>
<pre>server {
    listen       80;
    server_name  www.test.com;

    access_log /var/log/nginx/www.test.com.access.log main;
    error_log  /var/log/nginx/www.test.com.error.log warn;

    error_page  404              /404.html;
    error_page  500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location / {
        root /www/test;
        index  index.html index.htm index.php;
        #WordPress伪静态,不需要可以删除
        if (-f $request_filename/index.html){
                rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
                rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
                rewrite (.*) /index.php;
        }
    }

    #fpm_status,可通过www.test.com/fpm_status查看fpm状态，添加?full参数可查看详细状态。
    #正式上线时需要注释掉此段
    location ~ ^/(fpm_status)$ {
     access_log off;
     include fastcgi_params;
     fastcgi_pass unix:/var/run/php5-fpm.sock;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ \.php$ {
        proxy_buffers 8 16k;
        proxy_buffer_size 32k;
        root   /www/test;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
</pre>
</li>
<li>链接到sites-available
<pre>ln -s /etc/nginx/conf.d/www.test.com.conf /etc/nginx/sites-available/www.test.com.conf</pre>
</li>
<li>测试nginx配置
<pre>nginx -t</pre>
<p>如果配置文件正常，则显示：</p>
<pre>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful</pre>
<p>如果报错，则检查配置文件</li>
<li>待一切正常后，重启nginx
<pre>service nginx restart</pre>
</li>
<li>此时访问www.test.com，会出现PHP运行信息<br />
<img class="alignnone size-medium wp-image-230" src="http://bernieyu.com/wp-content/uploads/2015/06/20150609164645-300x236.png" alt="20150609164645" width="300" height="236" /></li>
<li>访问 www.test.com/fpm_status 或者 www.test.com/fpm_status?full 可以查看fpm状态</li>
</ul>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx + awstats 7.3 + GeoIP + PHP-FPM 全记录</title>
		<link>http://bernieyu.com/2015/04/nginx-awstats-7-3-geoip-php-fpm-install/</link>
		<comments>http://bernieyu.com/2015/04/nginx-awstats-7-3-geoip-php-fpm-install/#comments</comments>
		<pubDate>Thu, 16 Apr 2015 08:33:23 +0000</pubDate>
		<dc:creator><![CDATA[Bernie Yu]]></dc:creator>
				<category><![CDATA[IT技术]]></category>
		<category><![CDATA[awstats]]></category>
		<category><![CDATA[fpm]]></category>
		<category><![CDATA[GeoIP]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://bernieyu.com/?p=179</guid>
		<description><![CDATA[nginx + awstats 7.3 + GeoIP + PHP-FPM 全记录 VPS上已经部署好了ngi ... <a class="more-link" href="http://bernieyu.com/2015/04/nginx-awstats-7-3-geoip-php-fpm-install/">　　>>阅读全文&#60;&#60;</a>]]></description>
				<content:encoded><![CDATA[<p>nginx + awstats 7.3 + GeoIP + PHP-FPM 全记录</p>
<p>VPS上已经部署好了nginx+php-fpm，此次为添加awstats的过程全记录，以备后查。</p>
<ol>
<li>下载awstats 7.3
<ul>
<li>
<pre>wget http://prdownloads.sourceforge.net/awstats/awstats-7.3.zip

unzip awstats-7.3.zip
mv awstats-7.3 /usr/local/awstats</pre>
</li>
<li></li>
</ul>
</li>
<li>运行awstats配置向导，生成配置文件
<ul>
<li>
<pre>cd /usr/local/awstats
perl tools/awstats_configure.pl</pre>
</li>
<li>根据屏幕提示输入</li>
<li>
<pre>#-----&gt; Check for web server install 
#Enter full config file path of your Web server. 
#Example: /etc/httpd/httpd.conf 
#Example: /usr/local/apache2/conf/httpd.conf 
#Example: c:\Program files\apache #group\apache\conf\httpd.conf 
#Config file path ('none' to skip web server setup): 
&gt; none    #不用apache，输入none

#-----&gt; Need to create a new config file ? 
#Do you want me to build a new AWStats config/profile 
#file (required if first install) [y/N] ? 
&gt;y        #创建新的配置文件

#What is the name of your web site or profile analysis ? 
#Example: www.mysite.com 
#Example: demo 
#Your web site, virtual server or profile name: 
&gt; www  #配置文件名称

#Default: /etc/awstats 
#Directory path to store config file(s) (Enter for default): 
&gt;（enter） #保存在默认位置，直接回车

</pre>
</li>
<li>再几次回车后，结束配置向导</li>
<li></li>
</ul>
</li>
<li>下载GeoIP库
<ul>
<li>
<pre>wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget  http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz

gunzip GeoIP.dat.gz
gunzip GeoLiteCity.dat.gz
gunzip GeoIPASNum.dat.gz

mv *.dat /usr/local/awstats/wwwroot/cgi-bin/
chown -R www-data:www-data /usr/local/awstats/wwwroot/</pre>
</li>
</ul>
</li>
<li>下载并安装GeoIP API（C和Perl）
<ul>
<li>
<pre>wget https://www.maxmind.com/download/geoip/api/c/GeoIP-1.4.8.tar.gz

wget https://www.maxmind.com/download/geoip/api/perl/Geo-IP-1.40.tar.gz

tar xf GeoIP-1.4.8.tar.gz
cd GeoIP-1.4.8
./configure
make &amp;&amp; make install 

#检查是否生成c库文件
ls /usr/local/lib

rm -rf GeoIP-1.4.8

tar xf Geo-IP-1.40.tar.gz
cd Geo-IP-1.40
perl Makefile.PL LIBS='-L/usr/local/lib' 
make &amp;&amp; make install
</pre>
</li>
</ul>
</li>
<li>建立awstats数据库文件夹，并调整权限
<ul>
<li>
<pre>mkdir /usr/local/awstats/wwwroot/output
chown -R www-data:www-data /usr/local/awstats/wwwroot</pre>
</li>
</ul>
</li>
<li>修改awstats配置文件
<ul>
<li>
<pre>vi /etc/awstats/awstats.www.conf

#日志文件位置
#使用logresolvemerge.pl 可以解析多个日志文件，并且可以直接解析.gz这样已经压缩的日志
LogFile="/usr/local/awstats/tools/logresolvemerge.pl /var/log/nginx/www.bernieyu.com.access.log* |"

#站点域名
SiteDomain="bernieyu.com"
HostAliases="bernieyu.com www.bernieyu.com 127.0.0.1 localhost"

#数据输出文件夹
DirData="/usr/local/awstats/wwwroot/output"

#解决搜索关键字乱码
LoadPlugin="decodeutfkeys"  

#IP解析插件
LoadPlugin="geoip GEOIP_STANDARD /usr/local/awstats/wwwroot/cgi-bin/GeoIP.dat"
LoadPlugin="geoip_city_maxmind GEOIP_STANDARD /usr/local/awstats/wwwroot/cgi-bin/GeoLiteCity.dat"
LoadPlugin="geoip_asn_maxmind GEOIP_STANDARD /usr/local/awstats/wwwroot/cgi-bin/GeoIPASNum.dat"
</pre>
</li>
<li><span style="color: #ff0000;">注意：在网上搜到的文章，大部分都说GeoIPASNum.dat是机构数据，对应的插件是geoip_org_maxmind，这个是错误的，应该是geoip_asn_maxmind</span>
<pre></pre>
</li>
</ul>
</li>
<li>生成数据，测试配置
<ul>
<li>
<pre>chmod +x /usr/local/awstats/wwwroot/cgi-bin/awstats.pl 
/usr/local/awstats/wwwroot/cgi-bin/awstats.pl  -config=www</pre>
</li>
</ul>
</li>
<li>生成密码文件
<ul>
<li>
<pre>htpasswd -c /etc/awstats/awstats.pwd username</pre>
</li>
</ul>
</li>
<li>配置nginx，使其支持awstats
<ul>
<li>在网上查到的文件大部分都说nginx对perl支持不好，因此需要生成静态文件，再由nginx访问。而事实上awstats本身已经提供了nginx的支持</li>
<li>复制awstats提供的模板到对应位置</li>
<li>
<pre>cp /usr/local/awstats/tools/nginx/awstats-fcgi.php /usr/local/awstats/wwwroot/cgi-bin/fcgi.php
cp /usr/local/awstats/tools/nginx/awstats-nginx.php /etc/nginx/conf.d/awstats.conf
ln -s /etc/nginx/conf.d/awstats.conf /etc/nginx/site-available/awstats.conf</pre>
</li>
<li>编辑awstats.conf</li>
<li>
<pre>vi /etc/nginx/conf.d/awstats.conf

server {
        #去掉127.0.0.1，否则只能本地访问
        listen 80;
        server_name awstats.bernieyu.com;
        access_log /var/log/nginx/awstats.bernieyu.com.access_log main;
        error_log /var/log/nginx/awstats.bernieyu.com.error_log info;
        root /usr/local/awstats/wwwroot;
        index index.html;
        access_log off;

        #访问限制，使用之前生成的密码文件
        # Restrict access
        auth_basic "Restricted";
        auth_basic_user_file /etc/awstats/awstats.pwd;


        # Static awstats files: HTML files stored in DOCUMENT_ROOT/awstats/
        location /awstats/classes/ {
                alias /usr/local/awstats/wwwroot/classes/;
        }

        location /awstats/css/ {
                alias /usr/local/awstats/wwwroot/css/;
        }

        location /awstats/icon/ {
                alias /usr/local/awstats/wwwroot/icon/;
        }

        location /awstats/js/ {
                alias /usr/local/awstats/wwwroot/js/;
        }

        #支持http://awstats.bernieyu.com/www的方式访问
        location ~ ^/([a-z0-9-_\.]+)$ {
                return 301 $scheme://awstats.bernieyu.com/cgi-bin/awstats.pl?config=$1;
        }

        # Dynamic stats.
        location ~ ^/cgi-bin/(awredir|awstats)\.pl {
                gzip off;

                #指定到php-fpm的位置
                fastcgi_pass unix:/var/run/php5-fpm.sock;

                fastcgi_param SCRIPT_FILENAME /usr/local/awstats/wwwroot/cgi-bin/fcgi.php;
                fastcgi_param X_SCRIPT_FILENAME /usr/local/awstats/wwwroot$fastcgi_script_name;
                fastcgi_param X_SCRIPT_NAME $fastcgi_script_name;
                include fastcgi_params;
        }
}
</pre>
</li>
<li></li>
</ul>
</li>
<li>编辑nginx的主配置文件，主要是日志格式，并将awstats.conf包含进去
<ul>
<li>
<pre>vi /etc/nginx/nginx.conf

http {
    ...
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';
    include /etc/nginx/sites-available/*.conf;
}</pre>
</li>
</ul>
</li>
<li>在crontab中添加更新的调度
<ul>
<li>
<pre>vi /etc/crontab

#根据自已经需要配置更新频率
#every hour
#0 * * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www

#every day
0 0 * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www
</pre>
</li>
</ul>
</li>
<li>更新一下数据
<ul>
<li>
<pre>/usr/local/awstats/tools/awstats_updateall.pl now</pre>
</li>
</ul>
</li>
<li>访问http://awstats.bernieyu.com/www看效果吧</li>
</ol>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://bernieyu.com/2015/04/nginx-awstats-7-3-geoip-php-fpm-install/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
