Home PHP Framework Laravel Laravel environment setup: steps on how to deploy laravel to Alibaba Cloud or Tencent Cloud

Laravel environment setup: steps on how to deploy laravel to Alibaba Cloud or Tencent Cloud

Jul 28, 2018 pm 04:41 PM

Many laravel beginners don’t know how to deploy the laravel framework on Alibaba Cloud? There are also many students using Tencent Cloud. Today, PHP Chinese website will explain in detail how to build laravel environment and deploy laravel to Alibaba Cloud and Tencent Cloud. The following is the deployment of laravel to Alibaba Cloud or Tencent Cloud. specific steps above.

Step one: You need an Alibaba Cloud/Tencent Cloud server

PS: I don’t need to teach you how to buy an Alibaba Cloud/Tencent Cloud server Alright~~


Select ubuntu 16.04 for the installation system

Then log in to the remote server through ssh and follow the following steps to configure:

Step 2: Update List

apt-get update
Copy after login

Step 3: Install language pack

sudo apt-get install -y language-pack-en-base
locale-gen en_US.UTF-8
Copy after login

Step 4: Install common software

sudo apt-get install -y vim git zip unzip
Copy after login

Step 5: Install PHP7

Please make sure there are no errors in each step. If there are errors, you can try to install it a few more times


sudo apt-get install -y software-properties-common
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
apt-cache search php7.1
sudo apt-get install -y php7.1
sudo apt-get install -y php7.1-mysql
sudo apt-get install -y php7.1-fpm
sudo apt-get install -y php7.1-curl php7.1-xml php7.1-mcrypt php7.1-json php7.1-gd php7.1-mbstring
Copy after login

Step 6: Install Mysql

sudo apt-get install -y mysql-server
Copy after login
Note: You need to set a password after installation


##Step 7 :Install Nginx

Before installation, you need to confirm whether apache2 is installed. If apache2 is already installed, you need to stop/uninstall apache2

//安装之前需确认是否安装了apache2,如果已经安装了apache2,需要先停止/卸载 apache2
sudo service apache2 stop
//安装 nginx
sudo apt-get install -y nginx
Copy after login

Step 8: Configure PHP7

sudo vim /etc/php/7.1/fpm/php.ini
//修改 cgi.fix_pathinfo=0
sudo vim /etc/php/7.1/fpm/pool.d/www.conf
//修改 listen = /var/run/php7.1-fpm.sock
Copy after login
Part 9: Configure Nginx

sudo vim /etc/nginx/sites-available/default
//修改如下,根据自己的项目情况修改对应信息:'laravel-project'替换为你的项目,'server_domain_or_IP' 替换为你的网站域名或IP地址
server {
    root /var/www/laravel-project/public;
    index index.php index.html index.htm;
    
    server_name server_domain_or_IP;
    
    location / {
        try_files $uri $uri/ /index.php?$query_string;      
    }
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php7.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
Copy after login
Step 10: Pull the code

It is recommended to upload the code to the cloud code warehouse (github, coding) first and then pull it on the server

cd /var/www
git clone 地址
Copy after login

Install Composer and use Composer to install Code dependencies

Visit the composer official website to get the latest version of the following four lines of code, directly paste and execute to install Composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
//然后移动 composer.phar
mv composer.phar /usr/local/bin/composer
//进入项目目录
cd /var/www/laravel-project
//执行 composer install
composer install
Copy after login

Step 11: Create the .env file

cd /var/www/laravel-project
cp .env.example .env
vim .env
Copy after login
Note: Modify the .env file according to the actual situation of the project


Step 12: Generate laravel key

cd /var/www/laravel-project
php artisan key:generate
Copy after login
Step 13: Create database and perform migration

First log in to mysql to create a database corresponding to the project. The name should be consistent with the one in the .env file

cd /var/www/laravel-project
php artisan migrate
Copy after login

Step 14: Modify permissions

sudo chown -R www-data:www-data /var/www
sudo chmod -R 777 /var/www/laravel-project/storage
Copy after login
Step 15: Restart Nginx and PHP7 fpm

service nginx restartservice php7.1-fpm restart
<span style="color:#000000">搞定!</span>
Copy after login
Recommended:

Deploy Laravel project on Alibaba Cloud's ECS

## Use Alibaba Cloud OSS Composer package sharing in Laravel, laraveloss

The above is the detailed content of Laravel environment setup: steps on how to deploy laravel to Alibaba Cloud or Tencent Cloud. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Laravel and the Backend: Powering Web Application Logic Laravel and the Backend: Powering Web Application Logic Apr 11, 2025 am 11:29 AM

How does Laravel play a role in backend logic? It simplifies and enhances backend development through routing systems, EloquentORM, authentication and authorization, event and listeners, and performance optimization. 1. The routing system allows the definition of URL structure and request processing logic. 2.EloquentORM simplifies database interaction. 3. The authentication and authorization system is convenient for user management. 4. The event and listener implement loosely coupled code structure. 5. Performance optimization improves application efficiency through caching and queueing.

Laravel user login function Laravel user login function Apr 18, 2025 pm 12:48 PM

Laravel provides a comprehensive Auth framework for implementing user login functions, including: Defining user models (Eloquent model), creating login forms (Blade template engine), writing login controllers (inheriting Auth\LoginController), verifying login requests (Auth::attempt) Redirecting after login is successful (redirect) considering security factors: hash passwords, anti-CSRF protection, rate limiting and security headers. In addition, the Auth framework also provides functions such as resetting passwords, registering and verifying emails. For details, please refer to the Laravel documentation: https://laravel.com/doc

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

What versions of laravel are there? How to choose the version of laravel for beginners What versions of laravel are there? How to choose the version of laravel for beginners Apr 18, 2025 pm 01:03 PM

In the Laravel framework version selection guide for beginners, this article dives into the version differences of Laravel, designed to assist beginners in making informed choices among many versions. We will focus on the key features of each release, compare their pros and cons, and provide useful advice to help beginners choose the most suitable version of Laravel based on their skill level and project requirements. For beginners, choosing a suitable version of Laravel is crucial because it can significantly impact their learning curve and overall development experience.

How to view the version number of laravel? How to view the version number of laravel How to view the version number of laravel? How to view the version number of laravel Apr 18, 2025 pm 01:00 PM

The Laravel framework has built-in methods to easily view its version number to meet the different needs of developers. This article will explore these methods, including using the Composer command line tool, accessing .env files, or obtaining version information through PHP code. These methods are essential for maintaining and managing versioning of Laravel applications.

How to learn Laravel How to learn Laravel for free How to learn Laravel How to learn Laravel for free Apr 18, 2025 pm 12:51 PM

Want to learn the Laravel framework, but suffer from no resources or economic pressure? This article provides you with free learning of Laravel, teaching you how to use resources such as online platforms, documents and community forums to lay a solid foundation for your PHP development journey from getting started to master.

The difference between laravel and thinkphp The difference between laravel and thinkphp Apr 18, 2025 pm 01:09 PM

Laravel and ThinkPHP are both popular PHP frameworks and have their own advantages and disadvantages in development. This article will compare the two in depth, highlighting their architecture, features, and performance differences to help developers make informed choices based on their specific project needs.

See all articles