Home > PHP Framework > Laravel > body text

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

不言
Release: 2019-06-13 22:16:22
Original
4806 people have browsed it

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!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!