Skip to main content

快取指令

安裝laravel

php & composer
sudo apt install php composer php-cli php-common php-mbstring php-xml php-zip php-mysql php-json php-bcmath php-curl php-gd php-tokenizer php8.1-xml php-fpm mariadb-server nginx

這裡要是需要或習慣安裝apache or nginx,nginx需要使用php-fpm

php -v
sudo apt install curl php-cli php-mbstring git unzip
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
composer --version
install laravel
composer create-project --prefer-dist laravel/laravel your-project-name
cd your-project-name

install apache2 or nginx

apache
sudo vi /etc/apache2/sites-available/your-project-name.conf
<VirtualHost *:80>
    ServerName your-domain-or-ip
    DocumentRoot /var/www/html/your-project-name/public
    <Directory /var/www/html/your-project-name>
        AllowOverride All
    </Directory>
</VirtualHost>
sudo a2enmod rewrite

Enable the virtual host:

sudo a2ensite your-project-name.conf

Restart Apache for the changes to take effect:

sudo systemctl restart apache2
nginx
sudo vi /etc/nginx/sites-available/your-project-name
server {
    listen 80 default_server;
    server_name your-domain-or-ip;
    return 301 https://$server_name$request_uri;
    }

server {
    listen 443 ssl default_server;
    server_name your-domain-or-ip;

    include snippets/ssl;
    include snippets/ssl;

    root /var/www/html/your-project-name/public;
    index index.php;

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

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /var/www/html;
    }
    
        location ~ \.php$ {
               include snippets/fastcgi-php.conf;
        #      With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #

        add_header X-XSS-Protection "1; mode=block";
#       add_header 'Access-Control-Allow-Origin' *;
#       add_header 'Access-Control-Allow-Credentials' true;
#       add_header Strict-Transport-Security "max-age=31536000; includeSubdomains; preload";
#       add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;

        location ~*  \.(jpg|jpeg|gif|png|svg)$ {
                expires 365d;
        }

        location ~*  \.(pdf|css|html|js|swf)$ {
                expires 2d;
        }

        location ~ /\.ht {
                deny all;
        }

        location ~ ^/\.user\.ini {
                deny all;
        }

       location ~ /.well-known/acme-challenge {
        root /var/www/html;
               allow all;
        }

        location ~ /\.ht {
                deny all;
        }
}

Replace your-domain-or-ip with your actual domain name or server IP address.
Enable the Nginx server block:

sudo ln -s /etc/nginx/sites-available/your-project-name /etc/nginx/sites-enabled/

Test the Nginx configuration for any syntax errors:

sudo nginx -t

Restart Nginx for the changes to take effect:

sudo systemctl restart nginx