zoukankan      html  css  js  c++  java
  • EShop网上商城项目(一)

    一、项目简介

      该项目由Irving提出,有Irving、wang.cheng、laoda、syh0307 四人开发,开发环境:LNMP

      该项目软件为四个程序员的兄弟连二期项目,不做任何商业用途。

      码云:https://git.oschina.net/include_yx/lamp.git || git@git.oschina.net:include_yx/lamp.git

    二、搭建服务器环境

      1. 服务器选择:LNMP(Linux+Nginx+MySQL+PHP)

      2.Linux安装:CentOS-6.3-i386-bin-DVD1.iso

      3.LNMP集成环境安装   

     1 [root@iZ287mhoky1Z ~]# wget -c http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz && tar zxf lnmp1.2-full.tar.gz && cd lnmp1.2-full && ./install.sh lnmp
     2 --2016-08-11 16:13:45--  http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz
     3 Resolving soft.vpser.net... 50.93.201.152, 2600:3c01::f03c:91ff:fe96:d57a
     4 Connecting to soft.vpser.net|50.93.201.152|:80... connected.
     5 HTTP request sent, awaiting response... 200 OK
     6 Length: 326745420 (312M) [application/octet-stream]
     7 Saving to: “lnmp1.2-full.tar.gz”
     8 
     9 100%[======================================================================================>] 326,745,420 2.05M/s   in 2m 10s  
    10 
    11 2016-08-11 16:15:56 (2.39 MB/s) - “lnmp1.2-full.tar.gz” saved [326745420/326745420]
    12 +------------------------------------------------------------------------+
    13 |          LNMP V1.2 for CentOS Linux Server, Written by Licess          |
    14 +------------------------------------------------------------------------+
    15 |        A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux       |
    16 +------------------------------------------------------------------------+
    17 |          For more information please visit http://www.lnmp.org         |
    18 +------------------------------------------------------------------------+
    19 Please setup root password of MySQL.(Default password: root)
    20 Please enter: ******
    21 MySQL root password:****** 
    22 ===========================
    23 Do you want to enable or disable the InnoDB Storage Engine?
    24 Default enable,Enter your choice [Y/n]: y
    25 You will enable the InnoDB Storage Engine
    26 ===========================
    27 You have 5 options for your DataBase install.
    28 1: Install MySQL 5.1.73
    29 2: Install MySQL 5.5.42 (Default)
    30 3: Install MySQL 5.6.23
    31 4: Install MariaDB 5.5.42
    32 5: Install MariaDB 10.0.17
    33 Enter your choice (1, 2, 3, 4 or 5): 3
    34 You will Install MySQL 5.6.23
    35 ===========================
    36 You have 5 options for your PHP install.
    37 1: Install PHP 5.2.17
    38 2: Install PHP 5.3.29
    39 3: Install PHP 5.4.41 (Default)
    40 4: Install PHP 5.5.25
    41 5: Install PHP 5.6.9
    42 Enter your choice (1, 2, 3, 4 or 5): 5
    43 You will install PHP 5.6.9
    44 ===========================
    45 You have 3 options for your Memory Allocator install.
    46 1: Don't install Memory Allocator. (Default)
    47 2: Install Jemalloc
    48 3: Install TCMalloc
    49 Enter your choice (1, 2 or 3): 1
    50 You will install not install Memory Allocator.
    51 .
    52 .
    53 .
    54 ============================== Check install ==============================
    55 Checking ...
    56 Nginx: OK
    57 MySQL: OK
    58 PHP: OK
    59 PHP-FPM: OK
    60 +------------------------------------------------------------------------+
    61 |          LNMP V1.2 for CentOS Linux Server, Written by Licess          |
    62 +------------------------------------------------------------------------+
    63 |         For more information please visit http://www.lnmp.org          |
    64 +------------------------------------------------------------------------+
    65 |    lnmp status manage: lnmp {start|stop|reload|restart|kill|status}    |
    66 +------------------------------------------------------------------------+
    67 |  phpMyAdmin: http://IP/phpmyadmin/                                     |
    68 |  phpinfo: http://IP/phpinfo.php                                        |
    69 |  Prober:  http://IP/p.php                                              |
    70 +------------------------------------------------------------------------+
    71 |  Add VirtualHost: lnmp vhost add                                       |
    72 +------------------------------------------------------------------------+
    73 |  Default directory: /home/wwwroot/default                              |
    74 +------------------------------------------------------------------------+
    75 |  MySQL/MariaDB root password: 123456                                   |
    76 +------------------------------------------------------------------------+
    77 +-------------------------------------------+
    78 |    Manager for LNMP, Written by Licess    |
    79 +-------------------------------------------+
    80 |              http://lnmp.org              |
    81 +-------------------------------------------+
    82 nginx (pid 14442 14440) is running...
    83 php-fpm is runing!
    84  SUCCESS! MySQL running (14859)
    85 Active Internet connections (only servers)
    86 Proto Recv-Q Send-Q Local Address               Foreign Address             State      
    87 tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      
    88 tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      
    89 tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      
    90 Install lnmp V1.2 completed! enjoy it.
    View Code

        lnmp1.2-full.tar.gz
        Linux   => CentOS-6.3
        Nginx   => Nginx1.2
        MySQL   => MySQL5.6.23
        PHP    => PHP5.6.8   

        3.1 相关软件安装目录:
          Nginx 目录: /usr/local/nginx/

          MySQL 目录 : /usr/local/mysql/

          MySQL数据库所在目录:/usr/local/mysql/var/

          PHP目录 : /usr/local/php/

          PHPMyAdmin目录 : /home/wwwroot/default/phpmyadmin/

          默认网站目录 : /home/wwwroot/default/

          Nginx日志目录:/home/wwwlogs/

        3.2 LNMP相关配置文件位置:
          Nginx主配置文件:/usr/local/nginx/conf/nginx.conf

          MySQL配置文件:/etc/my.cnf

          PHP配置文件:/usr/local/php/etc/php.ini

          php-fpm配置文件:/usr/local/php/etc/php-fpm.conf

        3.3 LNMP状态管理命令:
          LNMP 状态管理: lnmp {start|stop|reload|restart|kill|status}

          LNMP 各个程序状态管理: lnmp {nginx|mysql|mariadb|php-fpm|pureftpd} {start|stop|reload|restart|kill|status}

        3.4 Nginx配置文件:
        #vi /usr/local/nginx/conf/nginx.conf

      1 user  www www;
      2 
      3 worker_processes auto;
      4 #启动进程
      5 
      6 error_log  /home/wwwlogs/nginx_error.log  crit;
      7 #错误日志
      8 
      9 pid        /usr/local/nginx/logs/nginx.pid;
     10 #主进程PID保存文件
     11 
     12 #Specifies the value for maximum file descriptors that can be opened by this process.?
     13 worker_rlimit_nofile 51200;
     14 #文件描述符数量
     15 
     16 events
     17     {
     18         use epoll;
     19         #网络I/O模型,建议linux使用epoll,FreeBSD使用kqueue
     20         #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以                上内    核,可以大大提高nginx的性能
     21         worker_connections 51200;
     22         #单个工作进程最大允许连接数
     23         multi_accept on;
     24     
     25     }
     26 
     27 http
     28 #整体环境配置
     29     {
     30         include             mime.types;
     31         default_type    application/octet-stream;
     32         #设定mime类型,文件传送类型由mime.type文件定义
     33 
     34         server_names_hash_bucket_size 128;        #保存服务器名字的hash表大小
     35         client_header_buffer_size 32k;            #客户端请求头部缓冲区大小
     36         large_client_header_buffers 4 32k;            #最大客户端头缓冲大小
     37         client_max_body_size 50m;                #客户端最大上传文件大小(M)
     38 
     39         sendfile on;
     40         #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文                    件,对于普通应用,必须设为 on。如果用来进行下载等应用磁盘IO重负载应用,可                设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
     41         #高效文件传输
     42         tcp_nopush     on;
     43         #这个是默认的,结果就是数据包不会马上传送出去,等到数据包最大时,一次性的                    传输出去,这样有助于解决网络堵塞。(只在sendfile on时有效)
     44 
     45 
     46         keepalive_timeout 60;
     47         #连接超时时间
     48 
     49         tcp_nodelay on;
     50         #禁用nagle算法,也即不缓存数据。有效解决网络阻塞
     51 
     52         fastcgi_connect_timeout 300;
     53         fastcgi_send_timeout 300;
     54         fastcgi_read_timeout 300;
     55         fastcgi_buffer_size 64k;
     56         fastcgi_buffers 4 64k;
     57         fastcgi_busy_buffers_size 128k;
     58         fastcgi_temp_file_write_size 256k;
     59         #fastcgi设置
     60 
     61         gzip on;
     62         gzip_min_length  1k;
     63         gzip_buffers     4 16k;
     64         gzip_http_version 1.1;
     65         gzip_comp_level 2;
     66         gzip_types     text/plain application/javascript         application/x-javascript text/javascript text/css application/xml     application/xml+rss;
     67         gzip_vary on;
     68         gzip_proxied   expired no-cache no-store private auth;
     69         gzip_disable   "MSIE [1-6].";
     70 
     71         #limit_conn_zone $binary_remote_addr zone=perip:10m;
     72         ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
     73                 server_tokens off;
     74                 #隐藏nginx版本号(curl -I 192.168.4.154可以查看,更加安全)
     75 
     76                    #log format
     77                 log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
     78              '$status $body_bytes_sent "$http_referer" '
     79              '"$http_user_agent" $http_x_forwarded_for';
     80                 #定义日志格式
     81 
     82 server
     83     {
     84         listen 80 default_server;
     85         #listen [::]:80 default_server ipv6only=on;
     86         #监听80端口
     87         server_name www.eshop.com
     88         #服务器名
     89         index index.html index.htm index.php;
     90         #默认网页文件
     91         root  /eshop/laravel/public;
     92         #网页主目录
     93 
     94     #error_page   404   /404.html;
     95     include enable-php.conf;
     96                     
     97     location /nginx_status
     98             {
     99                 stub_status on;
    100                 access_log   off;
    101             }
    102     #开启status状态监测
    103     location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    104             {
    105                 expires      30d;
    106             }
    107     #静态文件处理,保存期30天
    108     location ~ .*.(js|css)?$
    109             {
    110                 expires      12h;
    111             }
    112     #js和css文件处理,保存期12小时
    113     location ~ /.
    114             {
    115                 deny all;
    116             }
    117 
    118     access_log  /home/wwwlogs/access.log  access;
    119     #正确访问日志
    120     }
    121 include vhost/*.conf;
    122 #vhost/下子配置文件生效
    123 }
    View Code

        3.5 检查Nginx配置文件语句错误:

          #/usr/local/nginx/sbin/nginx -t
        3.6 平滑重启:
          1)pkill -HUP nginx
          2)kill -HUP `pgrep -uroot nginx`
            Pgrep -uroot nginx 取出nginx主进程PID
          3)/usr/local/nginx/sbin/nginx -s reload

      4.开启PHP错误报告  

        4.1  路径 :/usr/local/php/etc/php.ini

        4.2  搜索并修改下行,把Off值改成On

          display_errors = Off //此时已经有错误信息了

        4.3  搜索下行

          error_reporting = E_ALL & ~E_NOTICE

          或者搜索:

          error_reporting = E_ALL & ~E_DEPRECATED

          修改为

          error_reporting = E_ALL | E_STRICT //显示错误信息范围

    三、搭建git版本控制器 

      1、首先需要安装Git,可以使用yum源在线安装:

        [root@iZ287mhoky1Z ~]# yum install -y git
    

      2、创建一个git用户,用来运行git服务

        # adduser git  
    

      3、初始化git仓库:这里我们选择/git/eshop.git来作为我们的git仓库

        [root@iZ287mhoky1Z git]# git init --bare eshop.git  
    

        执行以上命令,会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾。然后,把owner改为git:

        [root@iZ287mhoky1Z git]# chown git:git learngit.git 

      4、在这里,Git服务器就已经搭得差不多了。下面我们在客户端clone一下远程仓库

        Administrator@y-32 MINGW32 /e/wamp/www/yx
        $ git clone git@115.28.147.159:/git/eshop.git
        Cloning into 'eshop'...
        git@115.28.147.159's password:
        remote: Counting objects: 107, done.
        remote: Compressing objects: 100% (77/77), done.
        Receiving objects: 100% (107/107), 44.84 KiB | 0 bytes/s, done.
        ta 10)
        Resolving deltas: 100% (10/10), done.
        Checking connectivity... done.

        这里两点需要注意:第一,当你第一次使用Git的clone或者push命令连接GitHub时,会得到一个警告:

        The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
        RSA key fingerprint is xx.xx.xx.xx.xx.
        Are you sure you want to continue connecting (yes/no)?
    

        这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,输入yes回车即可。

        Git会输出一个警告,告诉你已经把GitHub的Key添加到本机的一个信任列表里了:

        Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
    

        这个警告只会出现一次,后面的操作就不会有任何警告了。
        如果你实在担心有人冒充GitHub服务器,输入yes前可以对照GitHub的RSA Key的指纹信息是否与SSH连接给出的一致。
        第二,这里提示你输入密码才能clone,当然如果你知道密码,可以键入密码来进行clone,但是更为常见的方式,是利用SSH的公钥来完成验证。

      5、创建SSH Key
        首先在用户主目录下,看看有没有.ssh目录,如果有,再看看这个目录下有没有id_rsa和id_rsa.pub这两个文件,如果已经有了,可直接跳到下一步。如果没有,打开Shell(Windows下打开Git Bash),创建SSH Key:$ ssh-keygen -t rsa -C "youremail@example.com"  

        你需要把邮件地址换成你自己的邮件地址,然后一路回车,使用默认值即可,由于这个Key也不是用于军事目的,所以也无需设置密码。

        如果一切顺利的话,可以在用户主目录里找到.ssh目录,里面有id_rsa和id_rsa.pub两个文件,这两个就是SSH Key的秘钥对,id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以放心地告诉任何人。

      6、Git服务器打开RSA认证
        然后就可以去Git服务器上添加你的公钥用来验证你的信息了。在Git服务器上首先需要将/etc/ssh/sshd_config中将RSA认证打开,即:

        1.RSAAuthentication yes     
        2.PubkeyAuthentication yes     
        3.AuthorizedKeysFile  .ssh/authorized_keys
    

        这里我们可以看到公钥存放在.ssh/authorized_keys文件中。所以我们在/home/git下创建.ssh目录,然后创建authorized_keys文件,并将刚生成的公钥导入进去。

        然后再次clone的时候,或者是之后push的时候,就不需要再输入密码了

      7、禁用git用户的shell登陆
        出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:

        git:x:1001:1001:,,,:/home/git:/bin/bash  
    

        最后一个冒号后改为:

        git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell  
    

        这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。

    四、搭建Laravel框架

      1.安装Composer

     1 [root@iZ287mhoky1Z myproject]# curl -sS https://getcomposer.org/installer | php
     2     curl: (56) SSL read: errno -5961
     3     PHP Parse error:  syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in - on line 2522
     4 
     5     Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in - on line 2522
     6     [root@iZ287mhoky1Z myproject]# ls
     7     index.php
     8     [root@iZ287mhoky1Z myproject]# curl -sS https://getcomposer.org/installer | sudo php
     9     All settings correct for using Composer
    10     Downloading 1.2.0...
    11 
    12     Composer successfully installed to: /myproject/composer.phar
    13     Use it: php composer.phar
    14 
    15 测试Composer是否安装成功:php composer.phar
    16 
    17 把composer.phar放在系统的 PATH 目录中,就能在全局访问composer.phar。 在类Unix系统中,你甚至可以在使用时不加 php 前缀。可以执行这些命令让 composer 在你的系统中进行全局调用:
    18     #mv composer.phar /usr/local/bin/composer
    19 
    20 测试composer命令:#composer
    21    ______
    22   / ____/___  ____ ___  ____  ____  ________  _____
    23  / /   / __ / __ `__ / __ / __ / ___/ _ / ___/
    24 / /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
    25 \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
    26                     /_/
    27 Composer version 1.2.0 2016-07-19 01:28:52
    28 ...
    29 
    30 Composer安装成功!!
    View Code

      2.安装Laravel LTS 

        # composer create-project laravel/laravel=5.1 --prefer-dist

      安装失败,修改PHP配置文件:(移出三个函数exec,proc_open,proc_get_status)

    1 ;disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
    2 disable_functions = passthru,system,chroot,scandir,chgrp,chown,shell_exec,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
    View Code  

      问题:laravel 使用composer安装到服务器上,访问laravel首页欢迎界面一直服务器错误(500)
      解决:修改两个目录权限bootstrap和storage权限,都给777

  • 相关阅读:
    【题解】【BT】【Leetcode】Populating Next Right Pointers in Each Node
    【题解】【BT】【Leetcode】Binary Tree Level Order Traversal
    【题解】【BST】【Leetcode】Unique Binary Search Trees
    【题解】【矩阵】【回溯】【Leetcode】Rotate Image
    【题解】【排列组合】【素数】【Leetcode】Unique Paths
    【题解】【矩阵】【回溯】【Leetcode】Unique Paths II
    【题解】【BST】【Leetcode】Validate Binary Search Tree
    【题解】【BST】【Leetcode】Convert Sorted Array to Binary Search Tree
    第 10 章 判断用户是否登录
    第 8 章 动态管理资源结合自定义登录页面
  • 原文地址:https://www.cnblogs.com/yexiang520/p/5784281.html
Copyright © 2011-2022 走看看