欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

腾讯云centos7 从零搭建laravel项目

程序员文章站 2022-10-25 23:09:22
网页原创链接:https://www.cnblogs.com/lalaza/p/11258929.html 目标,访问网站出现: 分割线 一、Laravel Homestead 环境安装(腾讯云不支持!) 试了各种方法,一直报错,最后在旧版腾讯云贴吧里面找到官方解答 内心各种曹尼玛啊啊啊啊啊! 二、 ......

网页原创链接:

目标,访问网站出现:

腾讯云centos7 从零搭建laravel项目

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

 

 一、laravel homestead 环境安装(腾讯云不支持!)

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

     腾讯云centos7 从零搭建laravel项目 

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

 

二、测试环境长期关闭 防火墙&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

腾讯云centos7 从零搭建laravel项目

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项目