組內實習生用ThinkPHP寫了個服務需要部署到服務器上,由於從未寫過PHP折騰了兩天才搞定Nginx的部署,記錄下步驟。
1. 安裝PHP大禮包LNMP:
wget http://soft.vpser.net/lnmp/lnmp1.5.tar.gz -cO lnmp1.5.tar.gz && tar zxf lnmp1.5.tar.gz && cd lnmp1.5 && ./install.sh lnmp
包含了PHP,Nginx,Mysql等等,會默認增加www用戶。
2. 啓動php-fpm:
cd /usr/local/php/sbin
sudo service php-fpm restart
3.修改nginx配置:
server
{
listen 80;
server_name _;
index index.html index.htm index.php;
root /www/phptest;
location ~ \.php {
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.*)")
{
set $real_script_name $1;
set $path_info $2;
}
fastcgi_pass unix:/tmp/php-cgi.sock; # 這裏查看/usr/local/php/etc/php-fpm.conf的listen,保持一致
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
...
4.重啓nginx:
cd /usr/local/nginx/sbin
sudo service nginx restart
5. php中mysql配置(略),關鍵是要配置好數據庫名,用戶名,密碼
6. 如果遇到翻頁跳轉失敗的問題,在thinkphp的入口頁index.php第一行加入:
define('_PHP_FILE_',$_SERVER['SCRIPT_NAME']);
7. 在本機使用ip/index.php訪問吧