本文為轉載,原文:阿里雲Centos系統下的laravel環境搭建
lnmp環境的安裝有很多,可以nginx,mysql,php這三項內容單獨安裝,也可以使用lnmp一鍵安裝包安裝。下面將介紹centos 7系統的一鍵安裝包的安裝方法,該方法比較簡單,也非常使用。
- 下載安裝包
百度搜索“lnmp”,選擇搜索結果的第一條點擊進去,如下圖:這里是lnmp的官網,進入官網之后,點擊導航中的下載,結果如下圖:
復制下載地址:http://soft.vpser.net/lnmp/lnmp1.4-full.tar.gz, 在centos終端輸入如下命令,便可下載安裝包到當前目錄:
wget http://soft.vpser.net/lnmp/lnmp1.4-full.tar.gz
- 解壓到當前目錄
tar -xvf lnmp1.4-full.tar.gz
- 解壓成功后進入目錄:
cd lnmp1.4-full
- 執行安裝文件install.sh
install.sh
- 根據自己需求配置安裝選項,配置完提示Press any key to install…or Press Ctrl+c to cancel,按任意鍵后,便開始安裝,安裝過程時間比較長,耐心等待即可。
- lnmp的幾個簡單命令
lnmp start //開啟服務
lnmp stop //停止服務
lnmp restart //重啟服務
- nginx的幾個路徑
/usr/local/nginx //安裝路徑
/usr/local/nginx/conf //配置文件路徑
/usr/local/nginx/conf/nginx.conf //服務器配置文件
/usr/local/nginx/conf/vhost //nginx.conf文件會自動讀取該目錄下后綴為.conf文件。
/home/wwwroot/default //部署文件目錄,該目錄可在配置文件中配置
-
Composer
- 安裝composer
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
#使用國內鏡像
$ composer config -g repo.packagist composer https://packagist.phpcomposer.com
$ composer -v
-
使用composer創建laravel項目
composer create-project --prefer-dist laravel/laravel blog "5.2.*"
blog:項目目錄
—prefer-dist:使用壓縮版
5.2.*:laravel版本
在創建項目的時候,報如下錯誤,這是因為PHP的proc_open功能未開啟,我們可以在php的配置文件中開啟該功能。
通過以下命令找到php的配置文件find / -name php.ini
/usr/local/php/etc/php.ini
laravel項目創建成功
項目創建成功后要記得修改文件權限。chmod 777 -R demo1
配置部署
在/usr/local/nginx/conf/vhost目錄下創建配置文件
cd /usr/local/nginx/conf/vhost/demo1.conf
然后在文件中添加以下代碼
server
{
listen 8989;
#listen [::]:80 default_server ipv6only=on;
server_name _;
index index.html index.htm index.php;
root /home/wwwroot/demo1/public;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
}
在阿里雲服務器開發8989端口,並重啟lnmp即可訪問。
-