Example tutorial of deploying Laravel on cloud server
This article mainly introduces in detail how to deploy Laravel on the cloud server, which has certain reference value. Interested friends can refer to it
It has been a while since I learned PHP and Laravel, but All the code ran on the local virtual host, so I went to Tencent Cloud to apply for a free cloud host for one month, and wanted to deploy the project to the cloud server.
I have to say that there are a lot of pitfalls here, which makes me, a novice who comes into contact with the server for the first time, confused. After configuring the server, deploying a Laravel project is even more difficult, so I wanted to record the process of deploying the Laravel project.
PS: Linux is really a system that feels better the more you use it. You should install Linux on your desktop computer to type code when you go home.
Environment Introduction
In terms of the choice of operating system, I chose the Linux ubuntu16.04 system and used the LNMP environment, that is, Linux + Nginx + Mysql + PHP environment.
Delete Apache
1 2 3 |
|
Use these three commands to delete Apaceh first and then update the package list
1 |
|
1. Install Nginx
1 |
|
After installing Nginx, you need to restart nginx
1 |
|
After execution, enter the public IP assigned to you by the cloud server in the browser, and you can see the welcome to nginx The interface is
2. During the installation of Mysql
1 |
|
, you will be prompted to set the Mysql password, just like the usual password settings, enter it once and confirm it once. After the password is confirmed, the installation will basically take a while. Try
1 |
|
If the login is successful, Mysql is installed correctly.
3. Install PHP
1 |
|
Only through php5-fpm, PHP can run normally under Nginx, so install it.
As for php5-mcrypt, some PHP frameworks will depend on this, such as Laravel, so it is also installed.
Off topic, I installed php7 myself during deployment of php5 here. If you want to try it, you can also try it.
4. Configure PHP
1 |
|
Open the PHP configuration file, find the cgi.fix_pathinfo option, remove the comment semicolon; in front of it, and then Set its value to 0, as follows
1 |
|
5. Enable php5-mcrypt:
1 |
|
6.Restart php5-fpm:
1 |
|
After setting up the LEMP environment, you must first clarify two important directories
Nginx’s default root folder
##/usr/ share/nginx/html
The directory where Nginx’s server configuration file is located
/etc/nginx/sites-available/
The following is a step-by-step deployment of Laravel on the cloud server
1. Create the root directory of the website
1 |
|
2. Configure the nginx server
1 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
root modification
1 |
|
index modification
1 |
|
server_name modification
1 |
|
location modification
1 2 3 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
location ~ \.php$ was added by yourself:
1 |
|
3. Create a Laravel project
After configuring nginx, how toget the Laravel project code? There are several methods:
(1). Direct composer installation Install directly through composer. You can execute1 2 |
|
1 |
|
1 |
|
(2). Upload the code directly
Use the following command to upload1 |
|
1 |
|
(3). Use Git and Coding platform
I personally prefer to use git to upload code, which can easily update the code and roll back. Once the version When bugs are updated, I can use Git's powerful version management capabilities to fix them. The process is roughly like this: Local code---->Github---->Cloud server既然要使用git,那么先在云服务器上安装git:
1 |
|
安装完成就可以使用git了,然后在Github上创建一个私有项目laravel,里面包含所有该Laravel项目所需代码。
一旦本地代码都推送到Coding,然后在/var/www目录下直接使用
1 |
|
your-project-git-link替换为你Github上的laravel项目地址
5.BINGO
在浏览器输入:server_domain_or_IP
至此,你可以在服务器上随意地用Laravel了,keep coding!
The above is the detailed content of Example tutorial of deploying Laravel on cloud server. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide
