Dico

CentOS7.5 Laravel Install

  • 민갤

환경: CentOS7.5 Minimal, Apache2.4.6, PHP7.2

Composer

다운로드

# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...

Composer (version 1.8.0) successfully installed to: /root/composer.phar
Use it: php composer.phar

실행 파일 경로로 이동

# mv composer.phar /usr/bin/composer

unzip 설치

unzip이 있어야 Laravel을 안전하게 설치할 수 있다.

  • 확인
# yum list unzip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.navercorp.com
 * epel: mirror.premi.st
 * extras: mirror.navercorp.com
 * ius: muug.ca
 * updates: mirror.navercorp.com
Available Packages
unzip.x86_64
  • 설치
# yum -y install unzip
(... skip ...)
Installed:
  unzip.x86_64 0:6.0-19.el7                                                                                            

Complete!

계정 생성

root 계정으로 Laravel을 설치할 수 없다.

# adduser laravel
# passwd laravel
laravel 사용자의 비밀 번호 변경 중
새  암호:
새  암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.

Laravel 설치 프로그램 다운로드

# su laravel
$ composer global require laravel/installer
Changed current directory to /home/laravel/.config/composer
Using version ^2.0 for laravel/installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
  - Installing symfony/process (v4.2.0): Downloading (100%)         
  - Installing symfony/polyfill-ctype (v1.10.0): Downloading (100%)         
  - Installing symfony/filesystem (v4.2.0): Downloading (100%)         
  - Installing symfony/polyfill-mbstring (v1.10.0): Downloading (100%)         
  - Installing symfony/contracts (v1.0.1): Downloading (100%)         
  - Installing symfony/console (v4.2.0): Downloading (100%)         
  - Installing guzzlehttp/promises (v1.3.1): Downloading (100%)         
  - Installing ralouphie/getallheaders (2.0.5): Downloading (100%)         
  - Installing psr/http-message (1.0.1): Downloading (100%)         
  - Installing guzzlehttp/psr7 (1.5.2): Downloading (100%)         
  - Installing guzzlehttp/guzzle (6.3.3): Downloading (100%)         
  - Installing laravel/installer (v2.0.1): Downloading (100%)         
symfony/contracts suggests installing psr/cache (When using the Cache contracts)
symfony/contracts suggests installing psr/container (When using the Service contracts)
symfony/contracts suggests installing symfony/cache-contracts-implementation
symfony/contracts suggests installing symfony/service-contracts-implementation
symfony/contracts suggests installing symfony/translation-contracts-implementation
symfony/console suggests installing psr/log-implementation (For using the console logger)
symfony/console suggests installing symfony/event-dispatcher
symfony/console suggests installing symfony/lock
guzzlehttp/guzzle suggests installing psr/log (Required for using the Log middleware)
Writing lock file
Generating autoload files

Laravel 실행 파일을 찾을 수 있도록 PATH 추가

$ vi ~/.bash_profile
1    # .bash_profile
2  
3    # Get the aliases and functions
4    if [ -f ~/.bashrc ]; then
5            . ~/.bashrc
6    fi
7  
8    # User specific environment and startup programs
9  
10  PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/.config/composer/vendor/bin
11  
12  export PATH
13  
14  alias artisan="php artisan"

$ source ~/.bash_profile
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/home/laravel/.local/bin:/home/laravel/bin:/home/laravel/.config/composer/vendor/bin

Laravel 프로젝트 생성

laravel new 명령어를 통해 생성

$ cd /home/laravel
$ laravel new DicoProject
(... skip ...)
Generating optimized autoload files
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
> @php artisan key:generate --ansi
Application key set successfully.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: beyondcode/laravel-dump-server
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
Application ready! Build something amazing.

또는 Composer의 create-project 커멘드를 통해 생성

$ composer create-project --prefer-dist laravel/laravel DicoProject

기본 설정

$ chmod -R 755 /home/laravel/DicoProject/
$ chmod -R 775 /home/laravel/DicoProject/bootstrap/cache
$ chmod -R 777 /home/laravel/DicoProject/storage
$ vi /home/laravel/DicoProject/config/app.php
(... skip ...)
     59     /*
     60     |--------------------------------------------------------------------------
     61     | Application Timezone
     62     |--------------------------------------------------------------------------
     63     |
     64     | Here you may specify the default timezone for your application, which
     65     | will be used by the PHP date and date-time functions. We have gone
     66     | ahead and set this to a sensible default for you out of the box.
     67     |
     68     */
     69 
     70     'timezone' => 'Asia/Seoul',
     71 
     72     /*
     73     |--------------------------------------------------------------------------
     74     | Application Locale Configuration
     75     |--------------------------------------------------------------------------
     76     |
     77     | The application locale determines the default locale that will be used
     78     | by the translation service provider. You are free to set this value
     79     | to any of the locales which will be supported by the application.
     80     |
     81     */
     82 
     83     'locale' => 'ko',

Apache 설정

# su
# vi /etc/httpd/conf/httpd.conf

사용자 설정

66 User laravel
67 Group laravel

PHP 설정

160 #
161 # DirectoryIndex: sets the file that Apache will serve if a directory
162 # is requested.
163 #
164 <ifmodule dir_module="">
165     DirectoryIndex index.html index.htm index.php index.php7
166 </ifmodule>

286     AddType application/x-httpd-php .php .html .htm .inc .php7 .phtml .asp .bak .old
287     AddType application/x-httpd-php-source .phps

로그 설정

176 #
177 # ErrorLog: The location of the error log file.
178 # If you do not specify an ErrorLog directive within a <virtualhost>
179 # container, error messages relating to that virtual host will be
180 # logged here.  If you *do* define an error logfile for a <virtualhost>
181 # container, that host's errors will be logged there and not here.
182 #
183 ErrorLog "|/usr/sbin/rotatelogs /home/laravel/logs/error_log.%y-%m-%d.log 86400"
184 

205     #
206     # The location and format of the access logfile (Common Logfile Format).
207     # If you do not define any access logfiles within a <virtualhost>
208     # container, they will be logged here.  Contrariwise, if you *do*
209     # define per-<virtualhost> access logfiles, transactions will be
210     # logged therein and *not* in this file.
211     #
212     #CustomLog "logs/access_log" common
213 
214     #
215     # If you prefer a logfile with access, agent, and referer information
216     # (Combined Logfile Format) you can use the following directive.
217     #
218     CustomLog "|/usr/sbin/rotatelogs /home/laravel/logs/access_log.%y-%m-%d.log 86400" combined env=!do_not_log
219
  • rotatelogs: 로그 파일을 정리하는 Apache 기능. 숫자는 로그의 순환기간으로, 24시간(86400)마다 새로운 로그를 시작한다.

VirtualHost 설정

358 # Virtual Host
359 include /etc/httpd/conf/vhost.conf

vhost.conf 파일 생성 및 설정

# vi /etc/httpd/conf/vhost.conf
########## laravel ##################
<VirtualHost *:80>
#	ServerAdmin webmaster@dummy-host.example.com
	DocumentRoot /home/laravel/DicoProject/public
	ServerName localhost
#	ErrorLog los/dummy-host.example.com-error_log
#       CustomLog los/dummy-host.example.com-access_log
	<Directory "/home/laravel/DicoProject/public">
		AllowOverride None
		Require all granted
	</Directory>
</VirtualHost>
#####################################

httpd.conf 문법 확인 후 재시작

# /usr/sbin/apachectl configtest
Syntax OK
# systemctl restart httpd

버전 확인

# cd /home/laravel/DicoProject
# php artisan --version
Laravel Framework 5.7.15



localhost 접속

라라벨