├── README-es.md ├── README-vi.md ├── README-zh_CN.md └── README.md /README-es.md: -------------------------------------------------------------------------------- 1 | # Cómo desplegar aplicaciones Laravel en hosting compartido 2 | [![API Documentation](http://img.shields.io/badge/en-English-yellow.svg)](README.md) 3 | [![API Documentation](http://img.shields.io/badge/es-Español-brightgreen.svg)](README-es.md) 4 | [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-yellow.svg)](README-vi.md) 5 | [![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) 6 | 7 | Guía simple de cómo desplegar aplicaciones Laravel y Lumen en servicios de alojamiento compartidos. 8 | 9 | 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). 10 | 11 | ## Requisitos 12 | 13 | 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: 14 | 15 | - PHP >= `5.5.9` 16 | - Extensiones PHP: 17 | - OpenSSL 18 | - PDO 19 | - Mbstring 20 | - Tokenizer 21 | 22 | > 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). 23 | 24 | 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á.** 25 | 26 | Además de PHP y esas extensiones requeridas, podrías necesitaralgunas utilidades para hacer tu despliegue más fácil: 27 | 28 | - [Git](https://git-scm.com/) 29 | - [Composer](https://getcomposer.org/) 30 | 31 | Eso es todo por ahora. Por favor, sírvase leer las siguientes secciones para aprender más acerca del despliegue (deployment). 32 | 33 | ## Intrucciones 34 | 35 | Iniciemos por entender cómo deberíamos organizar la estructura de nuestra aplicación Laravel. 36 | 37 | En primer lugar, deberías tener algo similar a estos archivos y carpetas en tu cuenta de tu alojamiento: 38 | 39 | 40 | ```bash 41 | .bash_history 42 | .bash_logout 43 | .bash_profile 44 | .bashrc 45 | .cache 46 | .cpanel 47 | .htpasswds 48 | logs 49 | mail 50 | public_ftp 51 | public_html 52 | .ssh 53 | tmp 54 | etc 55 | www -> public_html 56 | ``` 57 | 58 | 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. 59 | 60 | Crea un nuevo directorio para almacenar todo el código; colócale el nombre `projects` o cualquiera que desees. 61 | 62 | ```bash 63 | $ mkdir projects 64 | $ cd projects 65 | ``` 66 | 67 | Bien. Desde aquí, simplemente ejecuta un comando `git` para obtener tu código: 68 | 69 | ```bash 70 | $ git clone http://[GIT_SERVER]/awesome-app.git 71 | $ cd awesome-app 72 | ``` 73 | 74 | 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. 75 | 76 | ```bash 77 | $ mv public public_bak 78 | $ ln -s ~/www public 79 | $ cp -a public_bak/* public/ 80 | $ cp public_bak/.htaccess public/ 81 | ``` 82 | 83 | 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: 84 | 85 | ```diff 86 | - require __DIR__.’/../bootstrap/autoload.php’; 87 | + require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; 88 | 89 | - $app = require_once __DIR__.’/../bootstrap/app.php’; 90 | + $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; 91 | ``` 92 | 93 | El archivo actualizado debera quedar así: 94 | 95 | ```php 96 | require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; 97 | 98 | $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; 99 | ``` 100 | 101 | Ya lo difícil está hecho. El resto es hacer algunas configuraciones básicas de Laravel. 102 | 103 | Permitir permisos de escritura al directorio `storage` es importante: 104 | 105 | ```bash 106 | $ chmod -R o+w storage 107 | ``` 108 | 109 | **Edita tu archivo`.env` con la configuración apropiada. ¡No lo pases por alto!** 110 | 111 | Por último, actualiza los paquetes requeridos por tu proyecto Laravel usando **composer** y agrega algunas caché necesarias: 112 | 113 | ```bash 114 | $ php composer install 115 | $ php composer dumpautoload -o 116 | $ php artisan config:cache 117 | $ php artisan route:cache 118 | ``` 119 | 120 | 121 | **¡Felicidades! Has configurado exitosamente una aplicación Laravel en un servicio de alojamiento web compartido.** 122 | 123 | ## Preguntas Frecuentes (FAQ) 124 | 125 | > **1. ¿Cómo adquiero permiso de acceso SSH para mi cuenta?** 126 | 127 | Simplemente contacta con el soporte de tu proveedor de hospedaje. Necesitarán confirmar tu identidad y te permitirán acceso SSH inmediatamente. 128 | 129 | > **2. ¿En dónde está `git`? No lo piedo encontrar.** 130 | 131 | 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: 132 | 133 | ```bash 134 | alias git="/usr/local/cpanel/3rdparty/bin/git" 135 | ``` 136 | 137 | > **3. ¿Cómo obtener composer?** 138 | 139 | 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: 140 | 141 | ```bash 142 | $ wget https://getcomposer.org/composer.phar 143 | ``` 144 | 145 | ó 146 | 147 | ```bash 148 | $ curl -sS https://getcomposer.org/installer | php — –filename=composer 149 | ``` 150 | 151 | > **4. ¿Estas instrucciones funciona con Lumen?** 152 | 153 | Laravel y Lumen son como gemelos, así que lo mismo aplica para Lumen. 154 | 155 | > **5. Intento ejecutar `composer` pero no muestra nada. ¿Cuál es el problema?** 156 | 157 | 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: 158 | 159 | ```bash 160 | $ php -c php.ini composer [COMMAND] 161 | ``` 162 | 163 | > **6. ¿De dónde puedo obtener el `php.ini` para cargar con `composer`?** 164 | 165 | 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: 166 | 167 | ```bash 168 | $ php -i | grep "php.ini" 169 | ``` 170 | 171 | ## Lista de proveedores de servicio comprobados en los que funciona 172 | 173 | Los siguientes servicios de alojamiento compartidos han sido probadas estas instrucciones y funcionado perfectamente al 100%. 174 | 175 | * [NameCheap](https://www.namecheap.com/) 176 | * [JustHost](https://www.justhost.com/) 177 | * [bluehost](https://www.bluehost.com/) 178 | * [GoDaddy](https://godaddy.com/) 179 | * [HostGator](http://www.hostgator.com/) 180 | * [GeekStorage](https://www.geekstorage.com/) 181 | 182 | 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` 183 | 184 | 185 | 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. 186 | 187 | ## ¿Aún tienes problemas? 188 | 189 | 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. 190 | 191 | ## Guía de Contribución 192 | 193 | 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). 194 | -------------------------------------------------------------------------------- /README-vi.md: -------------------------------------------------------------------------------- 1 | # Phương pháp triển khai ứng dụng Laravel trên shared hosting 2 | [![API Documentation](http://img.shields.io/badge/en-English-yellow.svg)](README.md) 3 | [![API Documentation](http://img.shields.io/badge/es-Español-yellow.svg)](README-es.md) 4 | [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-brightgreen.svg)](README-vi.md) 5 | [![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) 6 | 7 | Hướng dẫn đơn giản để triển khai ứng dụng Laravel và Lumen trên shared hosting. 8 | 9 | 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)" 10 | 11 | ## Yêu cầu 12 | 13 | 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: 14 | 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: 15 | 16 | * PHP >= 5.5.9 17 | * OpenSSL PHP Extension 18 | * PDO PHP Extension 19 | * Mbstring PHP Extension 20 | * Tokenizer PHP Extension 21 | 22 | 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). 23 | 24 | **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.** 25 | 26 | 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. 27 | 28 | * [Git](https://git-scm.com/) 29 | * [Composer](https://getcomposer.org/) 30 | 31 | 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. 32 | 33 | ## Hướng dẫn 34 | 35 | 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. 36 | 37 | ```bash 38 | .bash_history 39 | .bash_logout 40 | .bash_profile 41 | .bashrc 42 | .cache 43 | .cpanel 44 | .htpasswds 45 | logs 46 | mail 47 | public_ftp 48 | public_html 49 | .ssh 50 | tmp 51 | etc 52 | www -> public_html 53 | ... 54 | ``` 55 | 56 | 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. 57 | 58 | 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. 59 | 60 | ```bash 61 | $ mkdir projects 62 | $ cd projects 63 | ``` 64 | 65 | Từ đây, chúng ta sẽ sử dụng câu lệnh git để lấy code về, 66 | 67 | ```bash 68 | $ git clone http://[GIT_SERVER]/awesome-app.git 69 | $ cd awesome-app 70 | ``` 71 | 72 | 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 đã. 73 | 74 | ```bash 75 | $ mv public public_bak 76 | $ ln -s ~/www public 77 | $ cp -a public_bak/* public/ 78 | $ cp public_bak/.htaccess public/ 79 | ``` 80 | 81 | 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, 82 | 83 | ```bash 84 | $ chmod -R o+w storage 85 | ``` 86 | 87 | **Hãy chỉnh cấu hình trong file `.env`. Đừng bỏ quên điều này!** 88 | 89 | 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, 90 | 91 | ```bash 92 | $ php composer install 93 | $ php composer dumpautoload -o 94 | $ php artisan config:cache 95 | $ php artisan route:cache 96 | ``` 97 | 98 | **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..** 99 | 100 | ## FAQs 101 | 102 | > **1. Làm thế nào để lấy được quyền sử dụng SSH cho tài khoản của tôi?** 103 | 104 | 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. 105 | 106 | > **2. Git nằm ở đâu? Tôi không tìm thấy.** 107 | 108 | `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. 109 | 110 | ```bash 111 | alias git="/usr/local/cpanel/3rdparty/bin/git" 112 | ``` 113 | 114 | > **3. Làm thế nào để lấy composer?** 115 | 116 | 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. 117 | 118 | ```bash 119 | $ wget https://getcomposer.org/composer.phar 120 | 121 | hoặc 122 | 123 | $ curl -sS https://getcomposer.org/installer | php — –filename=composer 124 | ``` 125 | 126 | > **4. Cách này có thực hiện được cho Lumen hay không?** 127 | 128 | 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. 129 | 130 | > **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?** 131 | 132 | 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, 133 | 134 | ```bash 135 | $ php -c php.ini composer [COMMAND] 136 | ``` 137 | 138 | > **6. Tôi có thể lấy `php.ini` ở đâu để thực thi `composer`?** 139 | 140 | 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, 141 | 142 | ```bash 143 | $ php -i | grep "php.ini" 144 | ``` 145 | 146 | ## Danh sách các nhà cung cấp dịch vụ đã được thực hiện kiểm tra và hoạt động 147 | 148 | Các dịch vụ dưới đây đã được thực hiện kiểm tra và hoạt động 100%. 149 | 150 | * [NameCheap](https://www.namecheap.com/) 151 | * [JustHost](https://www.justhost.com/) 152 | * [bluehost](https://www.bluehost.com/) 153 | * [GoDaddy](https://godaddy.com/) 154 | * [HostGator](http://www.hostgator.com/) 155 | 156 | 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. 157 | 158 | ## Vẫn gặp vấn đề? 159 | 160 | 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. 161 | 162 | ## Hướng dẫn đóng góp 163 | 164 | Hãy thực hiện fork và gửi một [pull request](https://github.com/petehouston/laravel-deploy-on-shared-hosting/pulls). 165 | -------------------------------------------------------------------------------- /README-zh_CN.md: -------------------------------------------------------------------------------- 1 | # 如何在共享主机上部署Laravel应用程序 2 | [![API Documentation](http://img.shields.io/badge/en-English-brightgreen.svg)](README.md) 3 | [![API Documentation](http://img.shields.io/badge/es-Español-yellow.svg)](README-es.md) 4 | [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-yellow.svg)](README-vi.md) 5 | [![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) 6 | 7 | 本简要指南介绍如何在共享主机上部署Laravel和Lumen应用程序。 8 | 9 | 本指南有一个更加简明的版本(也许你已经读过),阅读该指南请移步"[在共享主机上部署Laravel 5应用程序的简单指南(英文)](https://medium.com/laravel-news/the-simple-guide-to-deploy-laravel-5-application-on-shared-hosting-1a8d0aee923e#.7y3pk6wrm)" 10 | 11 | ## 系统要求 12 | 13 | 尝试在共享主机上部署Laravel应用程序之前,需要确保主机服务提供适合[Laravel要求](https://laravel.com/docs/5.2#server-requirements)的环境。 例如,Laravel 5.2的基本要求如下: 14 | 15 | * PHP >= 5.5.9 16 | * OpenSSL PHP 扩展 17 | * PDO PHP 扩展 18 | * Mbstring PHP 扩展 19 | * Tokenizer PHP 扩展 20 | 21 | 总之,具体取决于你想安装的Laravel版本,请检查相应版本的[Laravel文档的服务器要求页面](https://laravel.com/docs/master)。 22 | 23 | **接下来,你必须拥有虚拟主机的SSH访问权限。否则下面的内容都可以忽略。** 24 | 25 | 除了PHP和上述必备扩展,下列实用程序可以使部署更加容易。 26 | 27 | * [Git](https://git-scm.com/) 28 | * [Composer](https://getcomposer.org/) 29 | 30 | 有了这些就好办了。接下来,请参阅以下内容,详细了解部署Laravel应用程序的更多信息。 31 | 32 | ## 部署说明 33 | 34 | 首先,让我们来了解如何组织Laravel应用程序文件结构。 一开始,您的虚拟主机用户文件夹下,会有类似下列目录和文件: 35 | 36 | ```bash 37 | .bash_history 38 | .bash_logout 39 | .bash_profile 40 | .bashrc 41 | .cache 42 | .cpanel 43 | .htpasswds 44 | logs 45 | mail 46 | public_ftp 47 | public_html 48 | .ssh 49 | tmp 50 | etc 51 | www -> public_html 52 | ... 53 | ``` 54 | 55 | 对于与主域名绑定的主账户,前端代码应该保存在“public_html”或“www”目录中。 我们当然不想将 *Laravel文件* (如.env 等...)暴露给全世界,所以我们要把它们放在其他目录中。 56 | 57 | 创建一个与“public_html”或“www”平行的目录,将它命名为`projects`或其他适合的名字。 58 | 59 | ```bash 60 | $ mkdir projects 61 | $ cd projects 62 | ``` 63 | 64 | 好了,接下来我们可以利用`git`命令来获取代码。 65 | 66 | ```bash 67 | $ git clone http://[GIT_SERVER]/awesome-app.git 68 | $ cd awesome-app 69 | ``` 70 | 71 | 下一步是要将`awesome-app/public`目录映射到`www`目录。这个时候符号连接(symbolic link)非常有用。不过,首先我们需要备份`public`文件夹。 72 | 73 | ```bash 74 | $ mv public public_bak 75 | $ ln -s ~/www public 76 | $ cp -a public_bak/* public/ 77 | $ cp public_bak/.htaccess public/ 78 | ``` 79 | 80 | 因为我们把`www`目录映射成项目的*虚拟*`public`目录,所以,我们需要编辑`~/www/index.php`,更新文件路径: 81 | 82 | ```diff 83 | - require __DIR__.’/../bootstrap/autoload.php’; 84 | + require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; 85 | 86 | - $app = require_once __DIR__.’/../bootstrap/app.php’; 87 | + $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; 88 | ``` 89 | 90 | 更新后的文件应该是这样: 91 | 92 | ```php 93 | require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; 94 | 95 | $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; 96 | ``` 97 | 98 | 好了,麻烦的部分到此结束。接下来就似乎一些基本的Laravel设置了。首先,确保`storage`目录可写: 99 | 100 | ```bash 101 | $ chmod -R o+w storage 102 | ``` 103 | 104 | **然后,编辑`.env`文件,确保配置正确。这步不要忘记!** 105 | 106 | 最后,使用**composer**来安装或更新必要的依赖包,并添加必要的缓存文件: 107 | 108 | ```bash 109 | $ php composer install 110 | $ php composer dumpautoload -o 111 | $ php artisan config:cache 112 | $ php artisan route:cache 113 | ``` 114 | 115 | **恭喜!到此,你已成功在共享虚拟主机上设置Laravel应用程序。** 116 | 117 | ## 常见问题 118 | 119 | > **1. 如何获取我的帐户的SSH访问权限?** 120 | 121 | 请联系您的主机客服,确认您的身份后,您将立即可以获得SSH访问权限。 122 | 123 | > **2. git在哪里? 我怎么找不到。** 124 | 125 | 在CPanel主机服务中,`git`一般安装在`/usr/local/cpanel/3rdparty/bin/git`。所以,如果想要使用`git`命令,则要提供`git`的完整路径。 当然,也可以创建别名以方便使用: 126 | 127 | ```bash 128 | alias git="/usr/local/cpanel/3rdparty/bin/git" 129 | ``` 130 | 131 | > **3. 如何安装composer?** 132 | 133 | 可以使用FTP或SCP命令来上传将下载好的`composer.phar`上传到虚拟主机。也可以直接使用`wget`或`curl`在主机上直接下载: 134 | 135 | ```bash 136 | $ wget https://getcomposer.org/composer.phar 137 | ``` 138 | 139 | 或者 140 | 141 | ```bash 142 | $ curl -sS https://getcomposer.org/installer | php — –filename=composer 143 | ``` 144 | 145 | > **4. 这个指南可以用于Lumen吗?** 146 | 147 | Laravel和Lumen就像一对双胞胎,所以Lumen也适用。 148 | 149 | > **5. 我尝试使用`composer`命令,但什么也没显示。发生了什么?** 150 | 151 | 运行`composer`需要提供php环境信息。也就是说,在某些虚拟主机上不能直接运行`composer`。要运行`composer`,需要使用如下命令: 152 | 153 | ```bash 154 | $ php -c php.ini composer [命令] 155 | ``` 156 | 157 | > **6. 怎么找到`composer`需要加载的`php.ini`文件?** 158 | 159 | 你可以将默认`php.ini`文件复制过来。这个文件一般保存在`/usr/local/lib/php.ini`。当然也可以用这个命令来查找: 160 | 161 | ```bash 162 | $ php -i | grep "php.ini" 163 | ``` 164 | 165 | ## 测试可用的提供商 166 | 167 | 经测试,以下共享主机服务提供商100%可部署Laravel应用。 168 | 169 | * [NameCheap](https://www.namecheap.com/) 170 | * [JustHost](https://www.justhost.com/) 171 | * [bluehost](https://www.bluehost.com/) 172 | * [GoDaddy](https://godaddy.com/) 173 | * [HostGator](http://www.hostgator.com/) 174 | * [GeekStorage](https://www.geekstorage.com/) 175 | * [Site5](https://www.site5.com/) 176 | 177 | 在[GeekStorage](https://www.geekstorage.com/)的共享服务上也可用,不过要通过`.htaccess` 的 178 | `AddHandler application/x-httpd-php56.php`来启用 PHP 5.6。 179 | 180 | 如果确定其他提供商可用,欢迎添加到此列表。 181 | 182 | ## 仍有问题? 183 | 184 | 如果采用上述步骤还没有解决安装问题,请提出你的详细[问题](https://github.com/petehouston/laravel-deploy-on-shared-hosting/issues),我会来帮你。 185 | 186 | ## 如何贡献 187 | 188 | 欢迎fork这个项目,也欢迎提交[pull request](https://github.com/petehouston/laravel-deploy-on-shared-hosting/pulls). 189 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to deploy Laravel applications on shared hosting 2 | [![API Documentation](http://img.shields.io/badge/en-English-brightgreen.svg)](README.md) 3 | [![API Documentation](http://img.shields.io/badge/es-Español-yellow.svg)](README-es.md) 4 | [![API Documentation](http://img.shields.io/badge/vi-Ti%E1%BA%BFng%20Vi%E1%BB%87t-yellow.svg)](README-vi.md) 5 | [![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) 6 | 7 | The simple guide to deploy Laravel and Lumen application on shared hosting. 8 | 9 | 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)" 10 | 11 | ## Requirements 12 | 13 | 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: 14 | 15 | * PHP >= 5.5.9 16 | * OpenSSL PHP Extension 17 | * PDO PHP Extension 18 | * Mbstring PHP Extension 19 | * Tokenizer PHP Extension 20 | 21 | 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). 22 | 23 | **Next, you need to have the SSH access permission for your hosting account; otherwise, none of these will work.** 24 | 25 | Besides PHP and those required extensions, you might need some utilities to make deployment much easier. 26 | 27 | * [Git](https://git-scm.com/) 28 | * [Composer](https://getcomposer.org/) 29 | 30 | I guess that's enough for good. Please refer to below sections to learn more about deployment. 31 | 32 | ## Instruction 33 | 34 | 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, 35 | 36 | ```bash 37 | .bash_history 38 | .bash_logout 39 | .bash_profile 40 | .bashrc 41 | .cache 42 | .cpanel 43 | .htpasswds 44 | logs 45 | mail 46 | public_ftp 47 | public_html 48 | .ssh 49 | tmp 50 | etc 51 | www -> public_html 52 | ... 53 | ``` 54 | 55 | 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. 56 | 57 | Create a new directory to store all the code, name it `projects` or whatever you want to. 58 | 59 | ```bash 60 | $ mkdir projects 61 | $ cd projects 62 | ``` 63 | 64 | Alright, from here, just issue a git command to grab the code, 65 | 66 | ```bash 67 | $ git clone http://[GIT_SERVER]/awesome-app.git 68 | $ cd awesome-app 69 | ``` 70 | 71 | 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. 72 | 73 | ```bash 74 | $ mv public public_bak 75 | $ ln -s ~/www public 76 | $ cp -a public_bak/* public/ 77 | $ cp public_bak/.htaccess public/ 78 | ``` 79 | 80 | 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: 81 | 82 | ```diff 83 | - require __DIR__.’/../bootstrap/autoload.php’; 84 | + require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; 85 | 86 | - $app = require_once __DIR__.’/../bootstrap/app.php’; 87 | + $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; 88 | ``` 89 | 90 | The updated file should be: 91 | 92 | ```php 93 | require __DIR__.'/../projects/awesome-app/bootstrap/autoload.php'; 94 | 95 | $app = require_once __DIR__.'/../projects/awesome-app/bootstrap/app.php'; 96 | ``` 97 | 98 | The hard part is done, the rest is to do some basic Laravel setup. Allow write permission to `storage` directory is important, 99 | 100 | ```bash 101 | $ chmod -R o+w storage 102 | ``` 103 | 104 | **Edit your `.env` for proper configuration. Don't miss this!** 105 | 106 | Lastly, update the required packages for Laravel project using **composer** and add some necessary caches, 107 | 108 | ```bash 109 | $ php composer install 110 | $ php composer dumpautoload -o 111 | $ php artisan config:cache 112 | $ php artisan route:cache 113 | ``` 114 | 115 | **Congratulation! You've successfully set up a Laravel application on a shared hosting service.** 116 | 117 | ## FAQs 118 | 119 | > **1. How to acquire SSH access permission for my account?** 120 | 121 | Just contact your hosting support, they will need to confirm your identity and will permit your SSH access in no time. 122 | 123 | > **2. Where is git? I can't find it.** 124 | 125 | `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, 126 | 127 | ```bash 128 | alias git="/usr/local/cpanel/3rdparty/bin/git" 129 | ``` 130 | 131 | > **3. How to get composer?** 132 | 133 | 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, 134 | 135 | ```bash 136 | $ wget https://getcomposer.org/composer.phar 137 | 138 | or 139 | 140 | $ curl -sS https://getcomposer.org/installer | php — –filename=composer 141 | ``` 142 | 143 | > **4. Does this work with Lumen?** 144 | 145 | Well, Laravel and Lumen are like twins, so it applies the same with Lumen. 146 | 147 | > **5. I try to run `composer` but it shows nothing. What is the problem?** 148 | 149 | 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, 150 | 151 | ```bash 152 | $ php -c php.ini composer [COMMAND] 153 | ``` 154 | 155 | > **6. Where can I get the `php.ini` to load for `composer`?** 156 | 157 | 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, 158 | 159 | ```bash 160 | $ php -i | grep "php.ini" 161 | ``` 162 | 163 | ## List of service providers tested and worked 164 | 165 | The following shared hosting service providers have been tested and worked perfectly 100%. 166 | 167 | * [NameCheap](https://www.namecheap.com/) 168 | * [JustHost](https://www.justhost.com/) 169 | * [bluehost](https://www.bluehost.com/) 170 | * [GoDaddy](https://godaddy.com/) 171 | * [HostGator](http://www.hostgator.com/) 172 | * [GeekStorage](https://www.geekstorage.com/) 173 | * [Site5](https://www.site5.com/) 174 | 175 | Works on [GeekStorage](https://www.geekstorage.com/) shared plan but I had to enable PHP 5.6 via `.htaccess` 176 | 177 | ``` 178 | AddHandler application/x-httpd-php56 .php 179 | ``` 180 | 181 | If you found any hosting providers that works, please tell me, I will update the list for others to know about them, too. 182 | 183 | ## Still trouble? 184 | 185 | 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. 186 | 187 | ## Contribution Guide 188 | 189 | Free free to fork the project and submit [a pull request](https://github.com/petehouston/laravel-deploy-on-shared-hosting/pulls). 190 | --------------------------------------------------------------------------------