Repository: petehouston/laravel-deploy-on-shared-hosting Branch: master Commit: 970287ea7c05 Files: 4 Total size: 24.6 KB Directory structure: gitextract_4d_ejxce/ ├── README-es.md ├── README-vi.md ├── README-zh_CN.md └── README.md ================================================ FILE CONTENTS ================================================ ================================================ FILE: README-es.md ================================================ # Cómo desplegar aplicaciones Laravel en hosting compartido [![API Documentation](http://img.shields.io/badge/en-English-yellow.svg)](README.md) [![API Documentation](http://img.shields.io/badge/es-Español-brightgreen.svg)](README-es.md) [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-yellow.svg)](README-vi.md) [![API Documentation](https://img.shields.io/badge/zh_CN-%E4%B8%AD%E6%96%87%EF%BC%88%E4%B8%AD%E5%9B%BD%E5%A4%A7%E9%99%86%EF%BC%89-yellow.svg)](README-zh_CN.md) Guía simple de cómo desplegar aplicaciones Laravel y Lumen en servicios de alojamiento compartidos. Para una versión rápida de esta guía, lee el post original en Medium: "[The simple guide to deploy Laravel 5 application on shared hosting](https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.7y3pk6wrm)" (en inglés). ## Requisitos Antes de intentar publicar tu aplicación en un servicio de alojamiento, necesitas asegurarte de que cumple con los [requisitos de Laravel](https://laravel.com/docs/5.2#server-requirements). Básicamente, Laravel `5.2` necesita: - PHP >= `5.5.9` - Extensiones PHP: - OpenSSL - PDO - Mbstring - Tokenizer > Estos requisitos pueden variar dependiendo de la versión de Laravel que quieres instalar. Verifica los requisitos del servidor para la versión de Laravel apropiada en la [documentación oficial](https://laravel.com/docs/master). Además de esto, **necesitas tener permisos de acceso SSH para tu cuenta en tu servicio de alojamiento; de otro modo, nada de lo que sigue funcionará.** Además de PHP y esas extensiones requeridas, podrías necesitaralgunas utilidades para hacer tu despliegue más fácil: - [Git](https://git-scm.com/) - [Composer](https://getcomposer.org/) Eso es todo por ahora. Por favor, sírvase leer las siguientes secciones para aprender más acerca del despliegue (deployment). ## Intrucciones Iniciemos por entender cómo deberíamos organizar la estructura de nuestra aplicación Laravel. En primer lugar, deberías tener algo similar a estos archivos y carpetas en tu cuenta de tu alojamiento: ```bash .bash_history .bash_logout .bash_profile .bashrc .cache .cpanel .htpasswds logs mail public_ftp public_html .ssh tmp etc www -> public_html ``` El código para el front-end para la cuenta principal, la cuál está vinculada con tu dominio principal, debería estar en `public_html` o `www`. Debido a que no queremos exponer las *cosas de Laravel* (como `,env`, etc..) al mundo exterior, las ocultaremos. Crea un nuevo directorio para almacenar todo el código; colócale el nombre `projects` o cualquiera que desees. ```bash $ mkdir projects $ cd projects ``` Bien. Desde aquí, simplemente ejecuta un comando `git` para obtener tu código: ```bash $ git clone http://[GIT_SERVER]/awesome-app.git $ cd awesome-app ``` El próximo paso es hacer que la carpeta `awesome-app/public` se mapee con la carpeta `www` mencionada anteriormente. Los enlaces simbólicos son de gran ayuda para esto, pero primero necesitamos respaldar la carpeta `public` de nuestro proyecto. ```bash $ mv public public_bak $ ln -s ~/www public $ cp -a public_bak/* public/ $ cp public_bak/.htaccess public/ ``` Debido a que creamos el enlace simbólico desde la carpeta `~/www` para hacer que se convierta en la carpeta `public` *virtual* en tu proyecto, debemos actualizar el archivo `~/www/index.php` para reemplazar las rutas viejas con las nuevas: ```diff - require __DIR__.’/../bootstrap/autoload.php’; + require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; - $app = require_once __DIR__.’/../bootstrap/app.php’; + $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; ``` El archivo actualizado debera quedar así: ```php require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; ``` Ya lo difícil está hecho. El resto es hacer algunas configuraciones básicas de Laravel. Permitir permisos de escritura al directorio `storage` es importante: ```bash $ chmod -R o+w storage ``` **Edita tu archivo`.env` con la configuración apropiada. ¡No lo pases por alto!** Por último, actualiza los paquetes requeridos por tu proyecto Laravel usando **composer** y agrega algunas caché necesarias: ```bash $ php composer install $ php composer dumpautoload -o $ php artisan config:cache $ php artisan route:cache ``` **¡Felicidades! Has configurado exitosamente una aplicación Laravel en un servicio de alojamiento web compartido.** ## Preguntas Frecuentes (FAQ) > **1. ¿Cómo adquiero permiso de acceso SSH para mi cuenta?** Simplemente contacta con el soporte de tu proveedor de hospedaje. Necesitarán confirmar tu identidad y te permitirán acceso SSH inmediatamente. > **2. ¿En dónde está `git`? No lo piedo encontrar.** Por lo general, `git` es colocado en esta ruta para proveedores de alojamiento con CPanel, `/usr/local/cpanel/3rdparty/bin/git`. Así que debes acceder a él escribiendo la ruta completa si quieres ejecutar un comando `git`. O, mejor aún, crear un alias más conveniente: ```bash alias git="/usr/local/cpanel/3rdparty/bin/git" ``` > **3. ¿Cómo obtener composer?** Puedes usar FTP o comandos SCP para subir el archivo `composer.phar` a tu alojamiento remoto después de descargarlo localmente. También puedes usar `wget` o `curl` para descargar el archivo directamente en tu remoto: ```bash $ wget https://getcomposer.org/composer.phar ``` ó ```bash $ curl -sS https://getcomposer.org/installer | php — –filename=composer ``` > **4. ¿Estas instrucciones funciona con Lumen?** Laravel y Lumen son como gemelos, así que lo mismo aplica para Lumen. > **5. Intento ejecutar `composer` pero no muestra nada. ¿Cuál es el problema?** Tienes que proveer una configuración PHP apropiada para ejecutar `composer`, lo que significa que no puedes usar `composer` directamente en algunos servicios de alojamiento. Así que para ejecutarlo, necesitarás ejecutar este comando: ```bash $ php -c php.ini composer [COMMAND] ``` > **6. ¿De dónde puedo obtener el `php.ini` para cargar con `composer`?** Puedes copiar la configuración predeterminada de PHP, la cual por lo general está en `/usr/local/lib/php.ini` o puedes encontrarlo con este comando: ```bash $ php -i | grep "php.ini" ``` ## Lista de proveedores de servicio comprobados en los que funciona Los siguientes servicios de alojamiento compartidos han sido probadas estas instrucciones y funcionado perfectamente al 100%. * [NameCheap](https://www.namecheap.com/) * [JustHost](https://www.justhost.com/) * [bluehost](https://www.bluehost.com/) * [GoDaddy](https://godaddy.com/) * [HostGator](http://www.hostgator.com/) * [GeekStorage](https://www.geekstorage.com/) Funciona en el plan compartido de [GeekStorage](https://www.geekstorage.com/), pero hay que habilitar PHP 5.6 a través de .htaccess: `AddHandler application/x-httpd-php56 .php` Si encuentras algún otro proveedor de servicio en que funcione, por favor, notifícalo. Esta lista se actualizará para informar a otros acerca de ello también. ## ¿Aún tienes problemas? Si sigues fallando al intentar desplegar tu aplicación, puedes crear una nueva [insidencia](https://github.com/petehouston/laravel-deploy-on-shared-hosting/issues) con los detalles para ayudarte. ## Guía de Contribución Siéntete libre de clonar (folk) el proyecto a tu cuenta y enviar una petición de [pull](https://github.com/petehouston/laravel-deploy-on-shared-hosting/pulls). ================================================ FILE: README-vi.md ================================================ # Phương pháp triển khai ứng dụng Laravel trên shared hosting [![API Documentation](http://img.shields.io/badge/en-English-yellow.svg)](README.md) [![API Documentation](http://img.shields.io/badge/es-Español-yellow.svg)](README-es.md) [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-brightgreen.svg)](README-vi.md) [![API Documentation](https://img.shields.io/badge/zh_CN-%E4%B8%AD%E6%96%87%EF%BC%88%E4%B8%AD%E5%9B%BD%E5%A4%A7%E9%99%86%EF%BC%89-yellow.svg)](README-zh_CN.md) Hướng dẫn đơn giản để triển khai ứng dụng Laravel và Lumen trên shared hosting. Bạn có thể xem bản hướng dẫn nhanh (chắc hẳn nhiều trong số bạn đã từng đọc qua), trên medium, "[The simple guide to deploy Laravel 5 application on shared hosting](https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.7y3pk6wrm)" ## Yêu cầu Before trying to deploy a Laravel application on a shared hosting, you need to make sure that the hosting services provide a fit [requirement to Laravel](https://laravel.com/docs/5.2#server-requirements). Basically, following items are required for Laravel 5.2: Trước khi thực hiện triển khai ứng dụng Laravel trên shared hosting, bạn cần đảm bảo nhà cung cấp dịch vụ cho bạn môi trường với [các yêu cầu cần thiết cho Laravel](https://laravel.com/docs/5.2#server-requirements). Về cơ bản, yêu cầu cho Laravel 5.2 như sau: * PHP >= 5.5.9 * OpenSSL PHP Extension * PDO PHP Extension * Mbstring PHP Extension * Tokenizer PHP Extension Tuy nhiên, yêu cầu này còn phụ thuộc vào phiên bản của Laravel bạn muốn sử dụng, hãy đọc tài liệu về [yêu cầu tương ứng của từng phiên bản Laravel](https://laravel.com/docs/master). **Tiếp đến, bạn cần có quyền truy cập vào SSH tới tài khoản hosting của bạn; nếu không mọi thứ ở đây sẽ trở nên vô nghĩa.** Ngoài các yêu cầu về phiên bản PHP và các extensions cần thiết, bạn cần có thêm một vài công cụ để cho việc triển khai được dễ dàng hơn. * [Git](https://git-scm.com/) * [Composer](https://getcomposer.org/) Theo tôi như vậy là đủ. Hãy xem các phần bên dưới để tìm hiểu phương thức triển khai. ## Hướng dẫn Cùng bắt đầu bằng việc tìm hiểu về cách chúng ta nên quản lý cấu trúc thư mục của ứng dụng Laravel. Đầu tiên, cùng nhìn xem danh sách các files và thư mục bạn có trên tài khoản. ```bash .bash_history .bash_logout .bash_profile .bashrc .cache .cpanel .htpasswds logs mail public_ftp public_html .ssh tmp etc www -> public_html ... ``` Với tài khoản chính được gắn với domain chính của bạn, phần front-end sẽ phải nằm trong thư mục `public_html` hoặc `www`. Vì chúng ta không muốn để lộ các *thông tin nhạy cảm của Laravel* (ví như các file .env, v..v..) ra bên ngoài, chúng ta sẽ giấu chúng đi. Tạo một thư mục mới để chứa toàn bộ code, đặt tên là `projects` hay bất cứ tên nào bạn muốn. ```bash $ mkdir projects $ cd projects ``` Từ đây, chúng ta sẽ sử dụng câu lệnh git để lấy code về, ```bash $ git clone http://[GIT_SERVER]/awesome-app.git $ cd awesome-app ``` Bước tiếp theo là làm cho thư mục `awesome-app/public` được tham chiếu tới `www`, symbol link sẽ hỗ trợ chúng ta việc này, nhưng chúng ta cần backup thư mục `public` trước đã. ```bash $ mv public public_bak $ ln -s ~/www public $ cp -a public_bak/* public/ $ cp public_bak/.htaccess public/ ``` Phần khoai nhất đã xong, phần còn lại sẽ là các bước cơ bản để thiết lập Laravel. Cấp quyền ghi cho thư mục `storage` là một việc quan trọng, ```bash $ chmod -R o+w storage ``` **Hãy chỉnh cấu hình trong file `.env`. Đừng bỏ quên điều này!** Cuối cùng, hãy cập nhật các packages cần thiết cho project Laravel sử dụng **composer** và thêm các cache cần thiết, ```bash $ php composer install $ php composer dumpautoload -o $ php artisan config:cache $ php artisan route:cache ``` **Chúc mừng! Bạn đã triển khai thành công một ứng dụng Laravel trên một dịch vụ shared hosting..** ## FAQs > **1. Làm thế nào để lấy được quyền sử dụng SSH cho tài khoản của tôi?** Hãy liên hệ trực tiếp với bên hỗ trợ của dịch vụ bạn sử dụng, họ sẽ cần xác nhận thông tin của bạn và sẽ cho bạn quyền sử dụng SSH một cách nhanh chóng. > **2. Git nằm ở đâu? Tôi không tìm thấy.** `git` thường được đặt ở vị trí này trong các dịch vụ hosting sử dụng CPanel, `/usr/local/cpanel/3rdparty/bin/git`. Vì vậy, bạn cần phải gõ đường dẫn đầy đủ tới `git` nếu bạn muốn thực thi một câu lệnh; hoặc là bạn của thể tạo một alias cho tiện. ```bash alias git="/usr/local/cpanel/3rdparty/bin/git" ``` > **3. Làm thế nào để lấy composer?** Bạn có thể sử dụng FTP hay SCP để upload file `composer.phar` lên host sau khi download trên máy cá nhân. Hoặc cũng có thể sử dụng `wget` hay `curl` để download file trực tiếp về host. ```bash $ wget https://getcomposer.org/composer.phar hoặc $ curl -sS https://getcomposer.org/installer | php — –filename=composer ``` > **4. Cách này có thực hiện được cho Lumen hay không?** Về cơ bản thì Laravel và Lumen như là anh em sinh đôi, vì vậy có thể áp dụng được với Lumen. > **5. Tôi thử chạy `composer` nhưng mà không thấy hiển thị gì cả. Vấn đề ở chỗ nào vậy?** Bạn cần cung cấp đường dẫn tới file cầu hình PHP để thực thi `composer`, nghĩa là, bạn không thể thực thi `composer` trực tiếp trên host. Vì thể để thực thi `composer`, bạn sẽ phải thực hiện như câu lệnh sau, ```bash $ php -c php.ini composer [COMMAND] ``` > **6. Tôi có thể lấy `php.ini` ở đâu để thực thi `composer`?** Bạn có thể copy file cấu hình `php.ini` mặc định, thường nằm tại `/usr/local/lib/php.ini`, hoặc có thể sử dụng câu lệnh sau để tìm kiếm, ```bash $ php -i | grep "php.ini" ``` ## Danh sách các nhà cung cấp dịch vụ đã được thực hiện kiểm tra và hoạt động Các dịch vụ dưới đây đã được thực hiện kiểm tra và hoạt động 100%. * [NameCheap](https://www.namecheap.com/) * [JustHost](https://www.justhost.com/) * [bluehost](https://www.bluehost.com/) * [GoDaddy](https://godaddy.com/) * [HostGator](http://www.hostgator.com/) Nếu như bạn tìm thấy nhà cung cấp dịch vụ nào mà cũng hoạt động, hãy chia sẻ, tôi sẽ cập nhật để cho nhiều người khác cùng biết tới. ## Vẫn gặp vấn đề? Nếu như bạn vẫn thất bại trong việc triển khai ứng dụng Laravel sau khi thực hiện đầy đủ các bước ở trên. Hãy cung cấp cho tôi [nội dung vấn đề của bạn](https://github.com/petehouston/laravel-deploy-on-shared-hosting/issues) một cách chi tiết, tôi sẽ cố gắng để giúp bạn. ## Hướng dẫn đóng góp Hãy thực hiện fork và gửi một [pull request](https://github.com/petehouston/laravel-deploy-on-shared-hosting/pulls). ================================================ FILE: README-zh_CN.md ================================================ # 如何在共享主机上部署Laravel应用程序 [![API Documentation](http://img.shields.io/badge/en-English-brightgreen.svg)](README.md) [![API Documentation](http://img.shields.io/badge/es-Español-yellow.svg)](README-es.md) [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-yellow.svg)](README-vi.md) [![API Documentation](https://img.shields.io/badge/zh_CN-%E4%B8%AD%E6%96%87%EF%BC%88%E4%B8%AD%E5%9B%BD%E5%A4%A7%E9%99%86%EF%BC%89-yellow.svg)](README-zh_CN.md) 本简要指南介绍如何在共享主机上部署Laravel和Lumen应用程序。 本指南有一个更加简明的版本(也许你已经读过),阅读该指南请移步"[在共享主机上部署Laravel 5应用程序的简单指南(英文)](https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.7y3pk6wrm)" ## 系统要求 尝试在共享主机上部署Laravel应用程序之前,需要确保主机服务提供适合[Laravel要求](https://laravel.com/docs/5.2#server-requirements)的环境。 例如,Laravel 5.2的基本要求如下: * PHP >= 5.5.9 * OpenSSL PHP 扩展 * PDO PHP 扩展 * Mbstring PHP 扩展 * Tokenizer PHP 扩展 总之,具体取决于你想安装的Laravel版本,请检查相应版本的[Laravel文档的服务器要求页面](https://laravel.com/docs/master)。 **接下来,你必须拥有虚拟主机的SSH访问权限。否则下面的内容都可以忽略。** 除了PHP和上述必备扩展,下列实用程序可以使部署更加容易。 * [Git](https://git-scm.com/) * [Composer](https://getcomposer.org/) 有了这些就好办了。接下来,请参阅以下内容,详细了解部署Laravel应用程序的更多信息。 ## 部署说明 首先,让我们来了解如何组织Laravel应用程序文件结构。 一开始,您的虚拟主机用户文件夹下,会有类似下列目录和文件: ```bash .bash_history .bash_logout .bash_profile .bashrc .cache .cpanel .htpasswds logs mail public_ftp public_html .ssh tmp etc www -> public_html ... ``` 对于与主域名绑定的主账户,前端代码应该保存在“public_html”或“www”目录中。 我们当然不想将 *Laravel文件* (如.env 等...)暴露给全世界,所以我们要把它们放在其他目录中。 创建一个与“public_html”或“www”平行的目录,将它命名为`projects`或其他适合的名字。 ```bash $ mkdir projects $ cd projects ``` 好了,接下来我们可以利用`git`命令来获取代码。 ```bash $ git clone http://[GIT_SERVER]/awesome-app.git $ cd awesome-app ``` 下一步是要将`awesome-app/public`目录映射到`www`目录。这个时候符号连接(symbolic link)非常有用。不过,首先我们需要备份`public`文件夹。 ```bash $ mv public public_bak $ ln -s ~/www public $ cp -a public_bak/* public/ $ cp public_bak/.htaccess public/ ``` 因为我们把`www`目录映射成项目的*虚拟*`public`目录,所以,我们需要编辑`~/www/index.php`,更新文件路径: ```diff - require __DIR__.’/../bootstrap/autoload.php’; + require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; - $app = require_once __DIR__.’/../bootstrap/app.php’; + $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; ``` 更新后的文件应该是这样: ```php require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; ``` 好了,麻烦的部分到此结束。接下来就似乎一些基本的Laravel设置了。首先,确保`storage`目录可写: ```bash $ chmod -R o+w storage ``` **然后,编辑`.env`文件,确保配置正确。这步不要忘记!** 最后,使用**composer**来安装或更新必要的依赖包,并添加必要的缓存文件: ```bash $ php composer install $ php composer dumpautoload -o $ php artisan config:cache $ php artisan route:cache ``` **恭喜!到此,你已成功在共享虚拟主机上设置Laravel应用程序。** ## 常见问题 > **1. 如何获取我的帐户的SSH访问权限?** 请联系您的主机客服,确认您的身份后,您将立即可以获得SSH访问权限。 > **2. git在哪里? 我怎么找不到。** 在CPanel主机服务中,`git`一般安装在`/usr/local/cpanel/3rdparty/bin/git`。所以,如果想要使用`git`命令,则要提供`git`的完整路径。 当然,也可以创建别名以方便使用: ```bash alias git="/usr/local/cpanel/3rdparty/bin/git" ``` > **3. 如何安装composer?** 可以使用FTP或SCP命令来上传将下载好的`composer.phar`上传到虚拟主机。也可以直接使用`wget`或`curl`在主机上直接下载: ```bash $ wget https://getcomposer.org/composer.phar ``` 或者 ```bash $ curl -sS https://getcomposer.org/installer | php — –filename=composer ``` > **4. 这个指南可以用于Lumen吗?** Laravel和Lumen就像一对双胞胎,所以Lumen也适用。 > **5. 我尝试使用`composer`命令,但什么也没显示。发生了什么?** 运行`composer`需要提供php环境信息。也就是说,在某些虚拟主机上不能直接运行`composer`。要运行`composer`,需要使用如下命令: ```bash $ php -c php.ini composer [命令] ``` > **6. 怎么找到`composer`需要加载的`php.ini`文件?** 你可以将默认`php.ini`文件复制过来。这个文件一般保存在`/usr/local/lib/php.ini`。当然也可以用这个命令来查找: ```bash $ php -i | grep "php.ini" ``` ## 测试可用的提供商 经测试,以下共享主机服务提供商100%可部署Laravel应用。 * [NameCheap](https://www.namecheap.com/) * [JustHost](https://www.justhost.com/) * [bluehost](https://www.bluehost.com/) * [GoDaddy](https://godaddy.com/) * [HostGator](http://www.hostgator.com/) * [GeekStorage](https://www.geekstorage.com/) * [Site5](https://www.site5.com/) 在[GeekStorage](https://www.geekstorage.com/)的共享服务上也可用,不过要通过`.htaccess` 的 `AddHandler application/x-httpd-php56.php`来启用 PHP 5.6。 如果确定其他提供商可用,欢迎添加到此列表。 ## 仍有问题? 如果采用上述步骤还没有解决安装问题,请提出你的详细[问题](https://github.com/petehouston/laravel-deploy-on-shared-hosting/issues),我会来帮你。 ## 如何贡献 欢迎fork这个项目,也欢迎提交[pull request](https://github.com/petehouston/laravel-deploy-on-shared-hosting/pulls). ================================================ FILE: README.md ================================================ # How to deploy Laravel applications on shared hosting [![API Documentation](http://img.shields.io/badge/en-English-brightgreen.svg)](README.md) [![API Documentation](http://img.shields.io/badge/es-Español-yellow.svg)](README-es.md) [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-yellow.svg)](README-vi.md) [![API Documentation](https://img.shields.io/badge/zh_CN-%E4%B8%AD%E6%96%87%EF%BC%88%E4%B8%AD%E5%9B%BD%E5%A4%A7%E9%99%86%EF%BC%89-yellow.svg)](README-zh_CN.md) The simple guide to deploy Laravel and Lumen application on shared hosting. For a quick version of the guide (many of you might already read about it), read my post on medium, "[The simple guide to deploy Laravel 5 application on shared hosting](https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.7y3pk6wrm)" ## Requirements Before trying to deploy a Laravel application on a shared hosting, you need to make sure that the hosting services provide a fit [requirement to Laravel](https://laravel.com/docs/5.2#server-requirements). Basically, following items are required for Laravel 5.2: * PHP >= 5.5.9 * OpenSSL PHP Extension * PDO PHP Extension * Mbstring PHP Extension * Tokenizer PHP Extension Well, it also depends on the Laravel version you want to try to install, checkout the appropriate version of [Laravel server requirements documentation](https://laravel.com/docs/master). **Next, you need to have the SSH access permission for your hosting account; otherwise, none of these will work.** Besides PHP and those required extensions, you might need some utilities to make deployment much easier. * [Git](https://git-scm.com/) * [Composer](https://getcomposer.org/) I guess that's enough for good. Please refer to below sections to learn more about deployment. ## Instruction Let's get started by understanding how we should organize the Laravel application structure. At first, you will have this or similar directories and files in your account, ```bash .bash_history .bash_logout .bash_profile .bashrc .cache .cpanel .htpasswds logs mail public_ftp public_html .ssh tmp etc www -> public_html ... ``` For the main account which tied with the main domain, the front-end code should stay in `public_html` or `www`. Since, we don't want to expose *Laravel things* (such as, .env, ...) to the outside world, we will hide them. Create a new directory to store all the code, name it `projects` or whatever you want to. ```bash $ mkdir projects $ cd projects ``` Alright, from here, just issue a git command to grab the code, ```bash $ git clone http://[GIT_SERVER]/awesome-app.git $ cd awesome-app ``` Next step is to make the `awesome-app/public` directory to map with `www` directory, symbol link is a great help for this, but we need to backup `public` directory first. ```bash $ mv public public_bak $ ln -s ~/www public $ cp -a public_bak/* public/ $ cp public_bak/.htaccess public/ ``` Because we created the symbol link from `www` directory to make it become the *virtual* `public` in project, so we have to update the `~/www/index.php` in order to replace paths with the new ones: ```diff - require __DIR__.’/../bootstrap/autoload.php’; + require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; - $app = require_once __DIR__.’/../bootstrap/app.php’; + $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; ``` The updated file should be: ```php require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; ``` The hard part is done, the rest is to do some basic Laravel setup. Allow write permission to `storage` directory is important, ```bash $ chmod -R o+w storage ``` **Edit your `.env` for proper configuration. Don't miss this!** Lastly, update the required packages for Laravel project using **composer** and add some necessary caches, ```bash $ php composer install $ php composer dumpautoload -o $ php artisan config:cache $ php artisan route:cache ``` **Congratulation! You've successfully set up a Laravel application on a shared hosting service.** ## FAQs > **1. How to acquire SSH access permission for my account?** Just contact your hosting support, they will need to confirm your identity and will permit your SSH access in no time. > **2. Where is git? I can't find it.** `git` is often put under this place in CPanel hosting services, `/usr/local/cpanel/3rdparty/bin/git`. So you need to provide full path to `git` if you want to issue a `git` command; or, you can also create an alias for convenient use, ```bash alias git="/usr/local/cpanel/3rdparty/bin/git" ``` > **3. How to get composer?** You can use FTP or SCP command to upload `composer.phar` to the host after downloading it locally. Or use `wget` and `curl` to get the file directly on host, ```bash $ wget https://getcomposer.org/composer.phar or $ curl -sS https://getcomposer.org/installer | php — –filename=composer ``` > **4. Does this work with Lumen?** Well, Laravel and Lumen are like twins, so it applies the same with Lumen. > **5. I try to run `composer` but it shows nothing. What is the problem?** You need to provide a proper PHP configuration to run `composer`, which means, you cannot execute `composer` directly on some hosting service providers. So to execute `composer`, you will need to issue this command, ```bash $ php -c php.ini composer [COMMAND] ``` > **6. Where can I get the `php.ini` to load for `composer`?** You can copy the default PHP configuration file `php.ini`, which is often at `/usr/local/lib/php.ini`, or find it by this command, ```bash $ php -i | grep "php.ini" ``` ## List of service providers tested and worked The following shared hosting service providers have been tested and worked perfectly 100%. * [NameCheap](https://www.namecheap.com/) * [JustHost](https://www.justhost.com/) * [bluehost](https://www.bluehost.com/) * [GoDaddy](https://godaddy.com/) * [HostGator](http://www.hostgator.com/) * [GeekStorage](https://www.geekstorage.com/) * [Site5](https://www.site5.com/) Works on [GeekStorage](https://www.geekstorage.com/) shared plan but I had to enable PHP 5.6 via `.htaccess` ``` AddHandler application/x-httpd-php56 .php ``` If you found any hosting providers that works, please tell me, I will update the list for others to know about them, too. ## Still trouble? If you still fail to deploy Laravel applications after following all above steps. Provide me [your issue](https://github.com/petehouston/laravel-deploy-on-shared-hosting/issues) in details, I will help you out. ## Contribution Guide Free free to fork the project and submit [a pull request](https://github.com/petehouston/laravel-deploy-on-shared-hosting/pulls).