linux(CentOS7)安装composer和Laravel步骤

整理自腾讯云开发者实验室文档Linux 下部署 Laravel 环境

LAMP(php7)

yum源

yum update -y
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

mysql

yum install mariadb mariadb-server -y 
systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation

apache

yum install -y httpd
systemctl start httpd.service
systemctl enable httpd.service

php7

yum install -y php70w php70w-mysql php70w-mcrypt php70w-dom php70w-mbstring

Composer

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/bin/composer
chmod +x /usr/bin/composer
composer config -g repo.packagist composer https://packagist.phpcomposer.com

Laravel

初始化

cd /var/www
composer create-project laravel/laravel test
cd test
chown apache:apache -R *

配置

代码

/var/www/test/app/Providers/AppServiceProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;

class AppServiceProvider extends ServiceProvider
{

    public function boot()
    {
        Schema::defaultStringLength(191);
    }
    public function register()
    {

    }
}

数据库

mysql -uroot -p -e "create database laravel;"

配置文件

/var/www/test/.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:Wi0qQG1pXdGp5U7uM4Q2eAA2zdxTg8yM4wyo61HvL6g=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=你设置的root密码

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

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

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

生成数据库

php /var/www/test/artisan migrate

配置apache

/etc/httpd/conf.d/laravel.conf

<VirtualHost *:80>
    DocumentRoot "/var/www/test/public"
    ServerName <您的 CVM IP 地址>
</VirtualHost>

重启 apache

systemctl restart httpd.service

至此,安装完毕。

版权声明

弈心博客


本文首发site_name,转载请附上博文链接!