Debian6.04nginx+mysql+php5-fpmfastcgi+pathinfo

科技小能手發表於2017-11-12
工作忙,沒有太多時間整理文件。請把筆記放上來吧。

安裝系統,使用的是NET-INSTALL的ISO最小安裝,只安裝基本系統和系統工具。其他全部不安裝,以保證系統的乾淨。

安裝VIM編輯器
# apt-get install vim
安裝SSH伺服器
# apt-get install ssh
增加更新源
# vi /etc/apt/sources.list
##### 163 sources
deb http://mirrors.163.com/debian/ squeeze main non-free contrib
deb http://mirrors.163.com/debian/ squeeze-proposed-updates main contrib non-free
deb http://mirrors.163.com/debian-security/ squeeze/updates main contrib non-free
deb-src http://mirrors.163.com/debian/ squeeze main non-free contrib
deb-src http://mirrors.163.com/debian/ squeeze-proposed-updates main contrib non-free
deb-src http://mirrors.163.com/debian-security/ squeeze/updates main contrib non-free
#####
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all
#####Nginx For Debian 6
deb http://nginx.org/packages/debian/ squeeze nginx
deb-src http://nginx.org/packages/debian/ squeeze nginx

下載nginx key並安裝
#wget http://nginx.org/keys/nginx_signing.key
# apt-key add nginx_signing.key

下載dotdeb key並安裝
# wget http://www.dotdeb.org/dotdeb.gpg
# apt-key add dotdeb.gpg

系統更新
# apt-get update
# apt-get upgrade
安裝開發包
apt-get install build-essential
安裝服務配置工具
# apt-get install chkconfig
安裝檢視使用者工具
# apt-get install finger

安裝解決ZIP工具
# apt-get install unzip

系統基本設定
 記錄開機啟動日誌
# vi /etc/default/bootlogd
    BOOTLOGD_ENABLE=Yes
檢視方法
    cat /var/log/boot
讓命令列顯示彩色
進入使用者主目錄
# vi .bashrc
將以下內容前的#號去除
umask 022
export LS_OPTIONS=`–color=auto`
eval “`dircolors`”
alias ls=`ls $LS_OPTIONS`
alias ll=`ls $LS_OPTIONS -l`
alias l=`ls $LS_OPTIONS -lA`
# Some more alias to avoid making mistakes:
alias rm=`rm -i`
alias cp=`cp -i`
alias mv=`mv -i`

設定DNS Server
# vi /etc/resolv.conf 
nameserver 202.96.128.143
nameserver 8.8.8.8
nameserver 8.8.4.4


刪除exim
# dpkg -l |grep exim
# apt-get remove –purge exim4 exim4-base exim4-config exim4-daemon-light


安裝VMwareTools
要在“VM”選項中點選“Install VMware Tools”進行安裝
關鍵是以下命令
# apt-get install linux-headers-$(uname -r) 
# mount /dev/scd0 /mnt
複製VMware Tools工具包目錄
# cd /mnt
解壓
# cd vmware-tools-distrib/
# ./vmware-install.pl
之後一路回車,然後重啟電腦
安裝nginx
# apt-get install nginx

建立網頁目錄
# mkdir -p /opt/data/html

#設定目錄所有者
# chown nginx.nginx /opt/data -R

設定nginx執行的程式數
# vi /etc/nginx/nginx.conf
worker_processes  4
設定網頁主目錄
# vi /etc/nginx/conf.d/default.conf
location / {
        root   /opt/data/html;
        index  index.php index.html index.htm;
    }

重啟nginx
# service nginx restart
訪問網址出現以下代表正確
403 Forbidden

安裝MySQL
# apt-get install mysql-server-5.5
根據提示輸入mysql root的密碼
以下命令修改mysql安全設定
# mysql_secure_installation
Enter current password for root (enter for none):enter //初始密碼為你安裝mysql時的,直接回車即可
Set root password? [Y/n]Y //是否設定root密碼
New password: //新的密碼
Re-enter new password://再次輸入密碼
Remove anonymous users? [Y/n]Y //是否刪除匿名使用者
Disallow root login remotely? [Y/n]n //是否不允許遠端連線資料庫
Remove test database and access to it? [Y/n]Y //刪除test資料庫
Reload privilege tables now? [Y/n]Y //過載許可權
安裝PHP5
apt-get install php5-fpm php5-cgi php5-cli php5-curl php5-ffmpeg php5-mysql php5-gd libjpeg8-dev php5-imap php5-ldap php5-odbc php*-pear  php5-mcrypt  php5-mhash libmcrypt* libmcrypt-dev php5-common php5-idn php5-imagick php5-memcache  php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-json php5-suhosin php-apc php5-dev
配置PHP
# vi /etc/php5/fpm/php.ini
cgi.fix_pathinfo=1
upload_max_filesize = 8M
magic_quote_gpc = On
open_basedir =/opt/data/html/:/tmp/
[Date]
date.timezone = “Asia/Shanghai”
date.default_latitude = 31.5167
date.default_longitude = 121.4500


配置nginx支援php
# vi /etc/nginx/conf.d/default.conf
找到# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
換成以下
location ~ ^(.+.php)(.*)$ {
                root   /opt/data/html;
                fastcgi_index index.php;
                fastcgi_split_path_info ^(.+.php)(.*)$;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param   PATH_INFO               $fastcgi_path_info;
                fastcgi_param   PATH_TRANSLATED $document_root$fastcgi_path_info;
                fastcgi_pass 127.0.0.1:9000;
                include fastcgi_params;
        }
重啟
# reboot
配置PHPMYADMIN
從官方網站下載最新的phpmyadmin版本,解壓至網站相應目錄。
然後訪問http://伺服器域名或IP/phpmyadmin

重啟nginx
測試pathinfo方法:
將以下程式碼寫入檔案,上傳至伺服器訪問測試 ,主要是在後面輸入不存在的檔名
pathifo.php
<?php
echo “<pre>”;
print_r($_SERVER);
echo “</pre>”;
?>

 

本文轉自 ljpwinxp 51CTO部落格,原文連結:http://blog.51cto.com/191226139/861789