【精选】Ubuntu 14.04 安装Nginx、php5-fpm、ThinkPHP5.0(已经测试上线)
sudo apt-get update
安裝Nginx
https://www.vultr.com/docs/setup-nginx-rtmp-on-ubuntu-14-04
安裝完成後,Nginx的安装在/usr/local/nginx底下
安裝PHP
sudo apt-get install php5-fpm
修改PHP設定檔/etc/php5/fpm/php.ini,找到cgi.fix_pathinfo=1,將其值改為0:
cgi.fix_pathinfo=0
如此PHP的只會處理確切位置的檔案,一來加快速度二來更安全,修改完後重新啟動PHP:
sudo service php5-fpm restart
Nginx配置文件
nginx.conf 文件
userwww www;
worker_processes
1;
#pid logs
/nginx.pid;
events {
worker_connections
1024;
}
http {
include mime.types;
default_typeapplication
/octet-stream;
log_formatmain
'$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_loglogs/access.logmain;
sendfile on;
keepalive_timeout65;
server {
listen 80;
server_namelocalhost;
charset utf-8;
access_loglogs/stream.access.logmain;
error_log logs/stream.error.log error;
set $root_path /home/www/tp5/public;
root $root_path;
indexindex.php index.html;
location / {
if (!-e $request_filename) {
rewrite^(.*)$/index.php?s=/$1last;
break;
}
}
error_page 500 502 503 504/50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
try_files $uri =404;
#root html;
fastcgi_pass unix:/var/run/php5-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
完成後重新啟動Nginx:
sudo service nginx restart
最後加入info.php檔案到/var/www底下測試,內容如下:
<?php
();
?>
可使用curl指令測試你的info.php是否產生了相關的回應:
curl http://127.0.0.1/info.php
错误处理:
connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied)
处理方式是:编辑/etc/php5/fpm/pool.d/www.conf文件,将以下的注释去掉:
修改前:
user = www-data
group
= www-data
listen
.owner = www-data
listen
.group = www-data
;listen
.mode = 0660
修改后:
user = www
group = www
listen.owner = www
listen.group = www
listen.mode = 0660
然后重启php5-fpm
sudo service php5-fpm restart
显示同样的错误!郁闷了
给www用户组分配权限:
www:www /etc/php5/fpm/php-fpm.conf
www:www /var/run/php5-fpm.sock
重启php5-fpm
service php5-fpm restart
测试页面;测试成功
ThinkPHP重写后的地址:
安装pdo和pdo_mysql扩展
1 安装pdo
sudo pecl install pdo
出现以下错误是说明pdo已经加入了PHP的默认安装,不需要再安装了
make: *** Error 1 ERROR: `make' failed
2 安装pdo_mysql
sudo pecl install pdo_mysql
以下错误表示在pear中找不到pdo_mysql 驱动,那重新安装php5-mysql看看
Some stuff excluded for brevity]checking for PDO includes... checking for PDO includes... configure: error: Cannot find php_pdo_driver.h.ERROR: `/tmp/pear/temp/PDO_MYSQL/configure' failed
php5-fpm configure: error: Cannot find MySQL header files under
安装这个:
apt-get install libmysqlclient15-dev
3 重新安装php5-mysql
sudo apt-get install php5-mysql
4 配置php.ini文件(自行查看编辑文件命令)
sudo vi /etc/php5/fpm/php.ini
在最后面加上(本来配置文件是没有的)
extension = pdo.so extension = pdo_mysql.so
页:
[1]