sudo apt-get install nginx php5-fpm php5-cli php5-mcrypt git
这里会安装 nginx 作为web server,同时会安装一些PHP工具,安装git是为了后期部署的时候拉取代码
更改PHP配置
安装完上诉组件之后,我们需要进行一些配置,首先需要打开fpm/php.ini,去更改fix_pathinfo为0
sudo vim /etc/php5/fpm/php.ini
cgi.fix_pathinfo=0
这里的设置是让PHP在请求的文件不在的时候别去尝试执行相似名字的脚本,防止攻击者欺骗PHP去执行一些不应该执行的代码,最后我们需要显式地启用MCrypt扩展并重启php5-fpm 服务以便重新载入让刚才的更改
sudo php5enmod mcrypt
sudo service php5-fpm restart
配置Nginx
下面我们要配置一下nginx,里面存在一些路径,这里我是使用apt-get安装的nginx,如果是手动编译安装的话请自寻路径,首先我们要创建一个目录以便放置我们的laravel代码,这里我直接放到/usr/share/nginx/laravel
sudo mkdir -p /usr/share/nginx/laravel
下面需要配置我们的nginx
sudo nano /etc/nginx/sites-available/default
这里你看到的大概是这样的
server {
listen 80 default_server
listen [::]:80 default_server ipv6only=on
root /usr/share/nginx/html
index index.html index.htm
# Make site accessible from http://localhost/
server_name localhost
location /{
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/=404
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
#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 /usr/share/nginx/html
#}
#location ~ \.php$ {
#fastcgi_split_path_info ^(.+\.php)(/.+)$
# NOTE: You should have "cgi.fix_pathinfo = 0" in php.ini
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock
#fastcgi_index index.php
#include fastcgi_params
#}
#}
需要把它替换成下面的配置文件,其中server_name要替换成你自己的域名或者ip,其中root里面的内容就是刚才我们创建laravel的目录并且多了一个public目录,这里public目录的作用就是去掉我们每次请求laravel路由里面的public,让路由语义更强
server {
listen 80 default_server
listen [::]:80 default_server ipv6only=on
root /usr/share/nginx/laravel/public
index index.php index.html index.htm
server_name server_domain_or_IP
location /{
try_files $uri $uri//index.php?$query_string
}
location ~ \.php$ {
try_files $uri /index.php =404
fastcgi_split_path_info ^(.+\.php)(/.+)$
#With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock
fastcgi_index index.php
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
include fastcgi_params
}
}
做完这些我们的工作基本就完成了,在目录中部署写好的laravel程序,打开绑定的域名就可以看到效果了
增加mcrypt先运行:find / -name mcrypt 找到mcrypt的路径(一般在你的php安装包里面的ext里面)。
[root@fredfred879 htdocs]# find / -name mcrypt
/root/soft/php-5.6.30/ext/mcrypt
然后进入这个目录(下面是进入目录的命令,你要写你自己的目录路径)
[root@fredfred879 htdocs]# cd /root/soft/php-5.6.30/ext/mcrypt
[root@fredfred879 mcrypt]# ls
config.m4 config.w32 CREDITS mcrypt.c mcrypt.dsp mcrypt_filter.c php_mcrypt_filter.h php_mcrypt.h tests TODO
然后运行:/usr/local/php5/bin/phpize 这是一个可执行的文本文件,要确保它在系统中。会发现当前目录下多了一些configure文件。
[root@fredfred879 mcrypt]# /usr/local/php5/bin/phpize
Configuring for:
PHP Api Version: 20131106
Zend Module Api No: 20131226
Zend Extension Api No: 220131226
[root@fredfred879 mcrypt]#
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)