码迷,mamicode.com
首页 > 其他好文 > 详细

腾讯云centos7 从零搭建laravel项目

时间:2019-07-28 15:37:42      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:err   session   key   width   设置   public   img   cas   redis   

网页原创链接:https://www.cnblogs.com/lalaza/p/11258929.html

目标,访问网站出现:

技术图片

-----------------------分割线----------------------------------------

 

 一、Laravel Homestead 环境安装(腾讯云不支持!)

  试了各种方法,一直报错,最后在旧版腾讯云贴吧里面找到官方解答

     技术图片 

      内心各种曹尼玛啊啊啊啊啊!

 

二、测试环境长期关闭 防火墙&SELinux

//关闭
systemctl stop firewalld 
//关闭开机启动
systemctl disable firewalld

 

//临时关闭SELinux 
setenforce 0

vim /etc/selinux/config
把SELINUX=enforcing  改成SELINUX=disabled

 

三、安装nginx

cd /etc/yum.repos.d/
vim nginx.repo

复制下列文本至 nginx.repo (文本来源)

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
yum list | grep nginx
yum -y install nginx
nginx -v mkdir
/www mkdir /www/wwwroot mkdir /www/wwwroot/default cd /www/wwwroot/default vim index.html

输入至 index.html

Hellow World!!!
cd /etc/nginx/conf.d
vim default.conf

技术图片

systemctl start nginx
systemctl enable nginx

 

四、安装PHP

yum -y install epel-release
rpm -ivh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum list | grep php72
yum -y install mod_php72w php72w-cli php72w-fpm php72w-common php72w-devel
mkdir /www/wwwroot/learn
cd /www/wwwroot/learn
vim index.php

输入至 index.php

<?php
phpinfo();
?>
cd /etc/nginx/conf.d
vim learn.conf

输入下文,

server {
    listen 8080;
    server_name localhost;
    root /www/wwwroot/learn;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php index.html index.htm;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        root /www/wwwroot/learn;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
systemctl restart nginx
systemctl start php-fpm
systemctl enable php-fpm

 

五、安装MYSQL 

cd ~
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
yum list | grep mysql
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
yum list | grep mysql
//这步安装时间长,请耐心等待,看你的网络状况
yum -y install mysql-community-server mysql-community-client
systemctl start mysqld
systemctl enable mysqld
//设置MySQL
set global validate_password_policy=0;
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=3;
set global validate_password_special_char_count=0;
set global validate_password_length=3;
//复制好密码
grep temporary password /var/log/mysqld.log
mysql -uroot -p
(输入密码)
set password for root@localhost = password(root);
//退出MySQL
exit;

 

六、安装composer 

cd /tmp
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
composer -v
composer config -g repo.packagist composer https://packagist.phpcomposer.com

 

七、配置Laravel 项目(链接请都点开)

//安装 laravel
composer global require laravel/installer

配置环境变量,PATH,

下载离线包, 找最新的下

上传文件夹,并解压至 ‘/www/wwwroot/learn2‘ 文件夹

cd /www/wwwroot/learn2
vim .env

写入下列内容,

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:fYG9POLRD3bFB/eAfyRGNakdfbwTVDObop+imw7U42Q=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

 

vim /etc/nginx/conf.d/learn2.conf

写入内容,

server {
    listen 8081;
    server_name localhost;
    root /www/wwwroot/learn2/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.php index.html index.htm;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        root /www/wwwroot/learn2/public;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

 

八、填坑

打开网页 ‘IP:8081‘, 各种报错,

先在‘www/wwwroot/learn2/public/index.php‘ 里添加:

ini_set(‘display_errors‘,1);
error_reporting(E_ALL);

 

cd /www/wwwroot/learn2
chmod -R 777 *
yum -y install php72w-pdo
yum -y install php72w-mysql
systemctl restart php-fpm
php artisan key:generate

 

OK!,出现:

 技术图片

 

 

腾讯云centos7 从零搭建laravel项目

标签:err   session   key   width   设置   public   img   cas   redis   

原文地址:https://www.cnblogs.com/lalaza/p/11258929.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!