Alibaba cloud ECS: Ubuntu 20 04 installing laravel operating environment

Time:2022-5-5
  1. Create www users and user groups and / data / www, / data / log directory

    useradd www  -m
    chown -R www:www /data
    ssh-keygen -t rsa -C "[email protected]"
  2. Initialize system
    export LC_ALL="en_US.UTF-8"
    echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale
    locale-gen en_US.UTF-8
    locale-gen zh_CN.UTF-8

    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

    apt-get update
    apt-get install -y software-properties-common
  1. Initialize software source
add-apt-repository -y ppa:ondrej/php
    add-apt-repository -y ppa:nginx/stable
    grep -rl ppa.launchpad.net /etc/apt/sources.list.d/ | xargs sed -i 's/http:\/\/ppa.launchpad.net/https:\/\/launchpad.proxy.ustclug.org/g'

    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
    echo "deb https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list

    # https://mirrors.tuna.tsinghua.edu.cn/ 2021-02-05 remove nodesource image

    curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
    echo 'deb https://deb.nodesource.com/node_10.x focal main' > /etc/apt/sources.list.d/nodesource.list
    echo 'deb-src https://deb.nodesource.com/node_10.x focal main' >> /etc/apt/sources.list.d/nodesource.list

    apt-get update
  1. Install basic software
apt-get install -y curl git build-essential unzip supervisor
  1. Install php8 0
apt-get install -y php8.0-bcmath php8.0-cli php8.0-curl php8.0-fpm php8.0-gd php8.0-mbstring php8.0-mysql php8.0-opcache php8.0-pgsql php8.0-readline php8.0-xml php8.0-zip php8.0-sqlite3 php8.0-redis
  1. Install nginx redis server memcached SQLite3
   apt-get remove -y apache2
   apt-get install -y nginx redis-server memcached sqlite3
  1. Install node

     apt-get install -y nodejs yarn
    su - www
     yarn config set registry https://registry.npm.taobao.org'
  2. Install composer

      curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer
     chmod +x /usr/local/bin/composer
    su - www
     composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/'
    }
  3. Laravel site configuration

    touch /etc/nginx/sites-enabled/zhoujiping_backend
    vim /etc/nginx/sites-enabled/zhoujiping_backend
server {
    listen 80;
    listen 443 ssl;
    server_name api.zhoujiping.com;
    root "/data/www/zhoujiping_backend/public";
    ssl_certificate   /data/ssl/zhoujiping_com/qiyitu.pem;
    ssl_certificate_key  /data/ssl/zhoujiping_com/private.key;

    #Prevent pages from being nested by frames of other stations
    add_header X-Frame-Options "SAMEORIGIN"; 
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    error_log  /data/logs/nginx/zhoujiping_backend_error.log error;
    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
  1. Vue site

    server {
    listen 443 ssl;
    server_name system.zhoujiping.com;
    root "/data/www/zhoujiping_frontend_system";
    
    ssl_certificate   /data/ssl/qiyitu_com/1bgm.pem;
    ssl_certificate_key  /data/ssl/qiyitu_com/private.key;
    
    charset utf-8;
    location / {
        # vue h5 history mode
        try_files $uri $uri/ /;
        index index.html index.htm;
    }
    access_log off;
    error_log  off;
    }
    
    server {
    listen 80;
    server_name system.zhoujiping.com;
    return 301 https://system.zhoujiping.com$request_uri;
    }