磕磕绊绊配置linux 下 laravel5.1 环境

第二次配置linux下的  laravel 5.1的环境了,第一次迷迷糊糊就配上了,第二次 再来配的时候 什么都没有,什么都不记得了,所以赶紧记录下这次配的所有过程,以备后期再用。

版权声明:本文为博主原创文章,未经博主允许不得转载。

1、安装nginx:

这个网上很多,也很简单,这里不过多介绍了。

2、安装php:

 wget http://repo.webtatic.com/yum/el7/webtatic-release.rpm 

经检测这个源是可用的php5.6版本。

然后 安装 rpm -ivh ./webtatic-release.rpm 

3、安装需要的php扩展:

yum install php56w

yum install php56w-fpm

yum install php56w-mbstring

yum install php56w-openssl

yum install php56w-mysql

yum install php56w-tokenizer

yum install php56w-pdo

4、修改nginx配置文件

我是这样的 直接cp /etc/nginx/nginx.conf /etc/nginx/nginx-81.conf

然后修改内容为:

user  nginx;
worker_processes  1;


error_log  /var/log/nginx/error-81.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;


pid        /var/log/nginx/nginx-81.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;
    client_max_body_size 100m;
    gzip  on;
server {
        listen  81;  
server_name localhost;  
set $root_path '/srv/www/xxxxx/public';  
root $root_path;  
index index.php index.html index.htm;  
try_files $uri $uri/ @rewrite;  
location @rewrite {  
rewrite ^/(.*)$ /index.php?_url=/$1;  
}  
location / {
  try_files $uri $uri/ /index.php?$query_string;
}  
location ~ \.php {  
 
fastcgi_pass 127.0.0.1:9000;  
fastcgi_index /index.php;  
include fastcgi_params; 
fastcgi_split_path_info       ^(.+\.php)(/.+)$;  
fastcgi_param PATH_INFO       $fastcgi_path_info;  
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;  
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
fastcgi_buffer_size 128k;  
                fastcgi_buffers 4 256k;  
                fastcgi_busy_buffers_size 256k; 
}  
 
location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {  
root $root_path;  
}  
 
location ~ /\.ht {  
deny all;  
}  
    }
    #server {
    #    listen       88;
    #    server_name  localhost;
    # set $root_path '/srv/www/maxuejie/public';
    # root $root_path;


    # index index.php index.html index.htm;


    # #try_files $uri $uri/ @rewrite;
    #    location / {
    #     try_files $uri $uri/ /index.php?$query_string;
    #    }
    # location @rewrite {
    #     rewrite ^/(.*)$ /index.php?_url=/$1;
    # }


    # location ~ \.php {
    #     fastcgi_pass 127.0.0.1:9000;
    #     fastcgi_index /index.php;


    #     include /usr/local/nginx/conf/fastcgi_params;


    #     fastcgi_split_path_info       ^(.+\.php)(/.+)$;
    #     fastcgi_param PATH_INFO       $fastcgi_path_info;
    #     fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    #     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    # }


    # location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
    #   root $root_path;
    # }


    # 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;
    #    }
    #}
}


修改完毕后执行

/usr/sbin/nginx -c /etc/nginx/nginx-81.conf

5、启动nginx 和php-fpm

service nginx start/restart

service php-fpm start/restart

输入配置的服务器地址和配置的81端口号,就可以看到成果了。

如果提示  File not found.  则可参考 以下 一位大神整理的文档

http://blog.csdn.net/skykingf/article/details/45221575


以下为转载内容:

在CentOS 7和7.1上搭建出来的LNMP运行环境,PHP网站根目录设为/srv/www/default。

使用systemctl启动php-fpm时,浏览器会报个404错误


但是用root权限手动使用php-fpm -D命令启动却一切正常。

仔细排查了几遍,原来是SELinux在作怪。先看看SELinux的介绍:

安全增强式 Security-Enhanced Linux(SELinux)是一个在内核中实践的强制访问控制(MAC)安全性机制。SELinux 首先在 CentOS 4 出现,并在后续的CentOS发行版中获得重大改善。这些改善代表用 SELinux 解决问题的方法亦随着时间而改变。SELinux 更能遵从最小权限的理念。在缺省的 enforcing 情况下,一切均被拒绝,接着有一系列例外的政策来允许系统的每个元素(服务、程序、用户)运作时所需的访问权。当一项服务、程序或用户尝试访问或修改一个它不须用的文件或资源时,它的请求会遭拒绝,而这个行动会被记录下来。由于 SELinux 是在内核中实践的,应用程序无须被特别编写或重写便可以采用 SELinux。当然,如果一个程序特别留意稍后所提及的 SELinux 错误码,它的运作可能会更畅顺。假若 SELinux 拦阻了一个行动,它会以一个标准的(至少是常规的)「拒绝访问」类错误来汇报给该应用程序。然而,很多应用程序不会测试系统函数所返回的错误码,因此它们也许不会输出消息解释问题所在,或者输出错误消息。

SELinux 拥有三个基本的操作模式,当中 Enforcing 是缺省的模式。此外,它还有一个 targeted 或 mls 的修饰语。这管制 SELinux 规则的应用有多广泛,当中 targeted 是较宽松的级别。

Enforcing: 这个缺省模式会在系统上启用并实施 SELinux 的安全性政策,拒绝访问及记录行动

Permissive: 在 Permissive 模式下,SELinux 会被启用但不会实施安全性政策,而只会发出警告及记录行动。Permissive 模式在排除 SELinux 的问题时很有用

Disabled: SELinux 已被停用

在CentOS 7.1上使用sestatus命令查看当前SELinux运行状态。 

SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

可以看到当前是Enforcing模式在运行。

查看SELinux的配置文件

$ cat /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

可以看到开机也是 Enforcing模式在运行。使用setenforce命令切换到Permissive模式

$ sudo setenforce 0
$ sestatus         
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28

再使用

sudo systemctl start php-fpm.service
启动php-fpm服务,这样LNMP服务就正常了

另一种解决方法是不改变SELinux的模式,改变网站根目录的权限。

sudo chcon -Rt httpd_sys_content_t /srv/www/  
su -c "chcon -R -h -t httpd_sys_script_rw_t /srv/www/"  


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值