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 文件
user www www; worker_processes 1; #pid logs/nginx.pid; events { worker_connections 1024; } http { include 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 logs/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; charset utf-8; access_log logs/stream.access.log main; error_log logs/stream.error.log error; set $root_path /home/www/tp5/public; root $root_path; index index.php index.html; location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; 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_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
完成後重新啟動Nginx:
sudo service nginx restart
最後加入info.php
檔案到/var/www
底下測試,內容如下:
<?php phpinfo(); ?>
可使用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用戶組分配權限:
chown www:www /etc/php5/fpm/php-fpm.conf
chown 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的默認安裝,不需要再安裝了
[Some stuff excluded for brevity]make: *** [pdo_dbh.lo] 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