PHP、Mysql和Nginx的安装请参照:
CentOS7快速搭建LNMP环境
安装Composer
Laravel是使用composer来做包依赖管理的,Laravel的安装也同样需要composer。所以我们搭建好了PHP、Mysql、Nginx(Apache)之后,还需要安装composer。
这里我只做composer的安装介绍。
Composer网址
- composer下载
curl -sS https://getcomposer.org/installer | php
- composer移动到系统$PATH可以搜索到的路径下,这样以后可以直接在命令行使用composer命令
mv composer.phar /usr/local/bin/composer
- 修改composer的执行权限
chmod +x /usr/local/bin/composer
- 查看是否已经安装成功
composer -v
看到看到终端会输出以下信息,说明已经安装成功了。
[root@lmc ~]# composer -v
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.4.2 2017-05-17 08:17:52
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
about Short information about Composer.
archive Create an archive of this composer package.
browse Opens the package's repository URL or homepage in your browser.
clear-cache Clears composer's internal package cache.
clearcache Clears composer's internal package cache.
config Set config options.
create-project Create new project from a package into given directory.
depends Shows which packages cause the given package to be installed.
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader.
dumpautoload Dumps the autoloader.
exec Execute a vendored binary/script.
global Allows running commands in the global composer dir ($COMPOSER_HOME).
help Displays help for a command
home Opens the package's repository URL or homepage in your browser.
info Show information about packages.
init Creates a basic composer.json file in current directory.
install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
licenses Show information about licenses of dependencies.
list Lists commands
outdated Shows a list of installed packages that have updates available, including their latest version.
prohibits Shows which packages prevent the given package from being installed.
remove Removes a package from the require or require-dev.
require Adds required packages to your composer.json and installs them.
run-script Run the scripts defined in composer.json.
search Search for packages.
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Show information about packages.
status Show a list of locally modified packages.
suggests Show package suggestions.
update Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate Validates a composer.json and composer.lock.
why Shows which packages cause the given package to be installed.
why-not Shows which packages prevent the given package from being installed.
安装Laravel
composer安装之后我们就可以安装Laravel了
- 安装Laravel
composer global require "laravel/installer"
[root@lmc ~]# composer global require "laravel/installer"
Changed current directory to /root/.config/composer
Using version ^1.3 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
- Installing symfony/process (v3.3.0): Downloading (100%)
- Installing psr/log (1.0.2): Downloading (100%)
- Installing symfony/debug (v3.3.0): Downloading (100%)
- Installing symfony/polyfill-mbstring (v1.3.0): Downloading (100%)
- Installing symfony/console (v3.3.0): Downloading (100%)
- Installing guzzlehttp/promises (v1.3.1): Downloading (100%)
- Installing psr/http-message (1.0.1): Downloading (100%)
- Installing guzzlehttp/psr7 (1.4.2): Downloading (100%)
- Installing guzzlehttp/guzzle (6.2.3): Downloading (100%)
- Installing laravel/installer (v1.3.5): Downloading (100%)
symfony/console suggests installing symfony/event-dispatcher ()
symfony/console suggests installing symfony/filesystem ()
Writing lock file
Generating autoload files
[root@lmc ~]# laravel -v
-bash: laravel: command not found
安装完成之后我们发现不能直接使用laravel命令
但是我们看到laravel其实已经安装完成了
[root@lmc ~]# ls .config/composer/vendor/bin/ -l
total 0
lrwxrwxrwx 1 root root 28 Jun 4 07:12 laravel -> ../laravel/installer/laravel
为了使用方便,我们将laravel命令放到系统的$PATH里面
vi ~/.bashrc
在最后加上laravel所在的路径,我的路径是/root/.config/composer/vender/bin/
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
export PATH=/root/.config/composer/vendor/bin/:$PATH
为了生效,执行下面命令
source ~/.bashrc
现在我们直接使用命令
laravel -v
看到下面的信息说明我们可以直接使用laravel命令了
Laravel Installer 1.3.5
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
new Create a new Laravel application.