lnmp部署服务器

前言:部署项目上线

1、把项目代码放到服务器上,这个地方就有多种选择(下次找时间按整理一下),这里选择使用svn来管理代码

  • 可以自己分别安装lnmp环境,也可以找一键安装方式
  • svn的搭建,注意一下这里有三个代码版本,本地项目代码a,服务器上的svn仓库版本代码b,服务器上的线上访问的代码c;原理是a拉去上传到b,c进行更新,保持与b同步

2、 配置nginx

server
    {
        listen 8083;#监听端口号
        server_name  _;#域名
        index index.html index.htm index.php;#默认打开文件
        root  /home/wwwroot/smartcloud/public;#网站根目录

        #定义变量
        set $root /home/wwwroot/smartcloud/public;

        location ~ [^/]\.php(/|$)
        {
            try_files $uri =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            #设置PATH_INFO
            fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
            fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
            #引入fastcgi配置
            include fastcgi.conf;
        }

        #从URL中去掉index.php入口文件
        location /
        {
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
        }

        #error_page   404   /404.html;
        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

3、系统可能出现的问题

  • 被禁止访问:access denied
    • 解决办法: 打开php.ini 把以下cgi.fix_pathinfo=0 改为1 保存退出重启lnmp
  • 服务器500
    • 解决办法 : 把php.ini中的display_errors=Off 改为ON 保存退出重启lnmp
  • open_basedir错误
    • 解决办法: 找到nginx/conf/下的fastcgi.conf 文件 注释掉最后一行
  • workman 可能出现的问题 启动如果报错的话 stream_socket_server 被禁用
    • 解决办法 把php.ini中的 disable_functions 最后的stream_socket_server删掉

4.数据库导入

  • 先把mysql配置为外网可访问 或者直接在进入mysql导入数据库
  • 数据库端口防火墙设置
  • 创建一个只读账户
	进入sql修改
    grant all privileges on *.* to '用户名'@'%' identified by '密码' with grant option;
	创建只读用户
	GRANT select ON *.* to 'read_user'@'%' identified by 'apld#$%666';
	创建所有权限
	GRANT all privileges ON *.* to 'root'@'%' identified by '746382';
	刷新权限
	flush privileges;
  • 使用新建的这个账户连接数据库,进行导入导出操作

5、关于一些运行时目录给予777权限,比如runtime

6、再次运行,部署成功后,建议在screen 里面进行一个项目网站的维护

发布了13 篇原创文章 · 获赞 1 · 访问量 1945

猜你喜欢

转载自blog.csdn.net/qq_37029718/article/details/105067957