騰訊雲centos7 從零搭建laravel項目

網頁原創連接:http://www.javashuo.com/article/p-wtpnfqsw-hd.htmlphp

目標,訪問網站出現:html

-----------------------分割線----------------------------------------mysql

 

 1、Laravel Homestead 環境安裝(騰訊雲不支持!)linux

  試了各類方法,一直報錯,最後在舊版騰訊雲貼吧裏面找到官方解答nginx

      

      心裏各類曹尼瑪啊啊啊啊啊!laravel

 

2、測試環境長期關閉 防火牆&SELinuxweb

//關閉
systemctl stop firewalld 
//關閉開機啓動
systemctl disable firewalld

 

//臨時關閉SELinux 
setenforce 0

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

 

3、安裝nginxsql

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

複製下列文本至 nginx.repo (文原本源)vim

[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.htmlcentos

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

systemctl start nginx
systemctl enable nginx

 

4、安裝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

 

5、安裝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;

 

6、安裝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

 

7、配置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;
    }
}

 

8、填坑

打開網頁 '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!,出現:

 

相關文章
相關標籤/搜索