背景:ThinkPHP5 的环境要求如下:
PHP >= 5.4.0
PDO PHP Extension
MBstring PHP Extension
CURL PHP Extension
严格来说, ThinkPHP 无需安装过程,这里所说的安装其实就是把 ThinkPHP 框架放入 WEB 运行环境 。
说明:安装路径(--prefix参数)可以自己定义。下面配置中,--prefix值(安装路径)仅供参考。安装包都放在/home/install路径下。
一、安装php。
1)安装curl
进入curl解压后的目录
运行:./configure --prefix=/usr/local/uap/curl7_50_3/
2)安装php
进入php解压后的目录
运行:
./configure --enable-fpm --prefix=/usr/local/uap/php-5.6.25/ --with-config-file-path=/usr/local/uap/php-5.6.25/lib --with-pdo-mysql --enable-mbstring --with-curl=/home/install/curl-curl-7_50_3
3)安装安装 php pdo extention
运行命令:
cd /home/install/php-5.6.25/ext/pdo
./configure --with-php-config=/usr/local/uap/php5.6/bin/php-config --enable-pdo=shared
make && make install
生成的extension库在/usr/local/uap/php-5.6.25/lib
二、搭建web服务器
我们选择nginx作为web服务器。
1) 安装pcre-8.37(nginx依赖pcre)
进入解压后的文件夹,运行:./configure && make && make install。
当然,你也可以安装在你规定的路径。如果你要安装在其他路径,你可以./configure --prefix=自己定义的安装路径。
2) 安装openssl(如果需要使用https访问Thinkphp,需要安装)
进入解压后的文件夹,运行:./config --prefix=/usr/local/openssl && make && make install。
如果没有/usr/local/openssl路径,可以在/usr/local下建一个文件夹openssl。当然,你也可以安装在你规定的路径。
3) 安装nginx
安装nginx+openssl。
./configure --prefix=/usr/local/uap/nginx1.8.1/ --with-pcre=/home/install/pcre-8.37 --with-openssl=/home/install/openssl-1.0.1c-mp --with-http_stub_status_module --with-http_ssl_module
4) 安装thinkphp
在/usr/local/uap/nginx1.8.1/html/路径下建立一个tp5目录
把ThinkPHP 5.0的安装包解压到/usr/local/uap/nginx1.8.1/html/tp5中说明:可以把thinkphp的安装包解压到你自定义的路径下。但是你需要修改web路径。见下文中的黄色标注。
三、配置nginx
1)配置nginx.conf
配置后的nginx.conf文件如下:
主要配置下文用黄颜色标注的地方。
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#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;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
listen 443 ssl;
server_name localhost;
#证书路径
ssl_certificate /usr/local/openssl/bin/mycert.pem;
ssl_certificate_key /usr/local/openssl/bin/myprivatekey.pem;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# thinkphp 解压在html目录中。html为nginx默认web目录。html目录的路径是/usr/local/uap/nginx1.8.1/html
root html; #nginx默认web目录
index index.php index.html index.htm;
autoindex off;
#if (!-e $request_filename) {
# rewrite ^(.*)$ /index.php?s=$1 last;
# break;
#}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#配置nginx支持pathinfo模式
location ~ \.php {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
四、验证是否成功搭建nginx+php+openssl+thinkphp5.0
1)启动nginx进程
进入nginx安装目录(/usr/local/uap/nginx1.8.1/)下的sbin目录。
运行./nginx.
2)启动php-fpm进程
进入php安装目录(/usr/local/uap/php-5.6.25)下的sbin目录。
运行./php-fpm
3)打开浏览器。输入网址:http://ip/tp5/public/index.php
成功的画面如下:
五、附件
1)nginx使用的证书
证书下载路径:http://download.youkuaiyun.com/detail/xiangguiwang/9658287。当然,你也可以自己做。
参考连接:http://www.thinkphp.cn/topic/3228.html
http://php.net/manual/zh/install.unix.nginx.php
http://blog.helloarron.com/2015/10/12/linux/linux-php-compile-mudoles/