Originally published on bcd.dev
Before you go through the pain and challenge of configuring your own server you should perhaps consider Laravel forge. I trust they would know better how to deploy a laravel app.
For curious minded people, this is part of a bigger series Do it yourself series
Components
- webserver
- nginx
- database
- mysql
- php
- composer
- node
- npm / yarn
- scheduler
- firewall
- log
- papertrail
- search
- elastic search
- algolia
- other third party services
- redis
Basic build
recepee on an ubuntu server (22-10)
- mysql
- php
- composer
- node
- nginx
- queue
Requirements
- VPS Server
- Valid DNS record pointing to your server
Mysql
sudo apt-get install -y mysql-server # Init project by creating a user with a dedicated database name=$1 username=${2:-$name} password=${3:-$name} root_username=${4:-'root'} root_password=${5:-''} echo '' > tmp.sql echo "CREATE USER $name@localhost identified by \"$password\";" >> tmp.sql echo "CREATE DATABASE $name charset utf8 collate utf8_general_ci;" >> tmp.sql echo "GRANT ALL PRIVILEGES ON $name.* to $name@localhost;" >> tmp.sql mysql -u$root_username -p$root_password -e "source tmp.sql" mysql -u$root_username -p$root_password -e "CREATE DATABASE $name charset utf8 collate utf8_general_ci;"
Php
sudo apt install -y software-properties-common sudo add-apt-repository ppa:ondrej/php sudo apt update # php with some extensions PHP_VERSION=${1:-'8.2'} sudo apt-get install -y "php$PHP_VERSION" php$PHP_VERSION-{common,cli,fpm,zip,xml,pdo,mysql,mbstring,tokenizer,ctype,curl,common,curl,gd,intl,sqlite3,xmlrpc,xsl,soap,opcache,readline,xdebug,bcmath}
Composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" # For simplicity purpose, we are skipping the hash check. That is a crucial step you wouldn't want to skip when downloading stuff on the internet # Hash below matches composer version 2.1.3 # php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" php composer-setup.php php -r "unlink('composer-setup.php');" sudo mv composer.phar /usr/local/bin/composer
Node
You can get node on their website but I prefer getting specific version from node version manager (nvm)
version=${1:-'20'} echo "Installing nvm + node $version" wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash source ~/.bashrc nvm install $version # Optional but I like yarn so here we go nvm exec $version npm i yarn -g
Nginx
# Making sure apache is not installed to avoid conflict on port 80 sudo apt-get remove -y apache sudo apt-get install -y nginx rm /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default name=$1 # site.domain webroot=${3:-"/var/www/vhosts/$name"} mkdir -p $webroot touch "/etc/nginx/sites-available/$name.conf" ln -s "/etc/nginx/sites-available/$name.conf" "/etc/nginx/sites-enabled/$name.conf" cat >> "/etc/nginx/sites-available/$name.conf" <h4> Secure traffic using HTTPS </h4> <p>At this point we are running a web server on port 80. However everyone can see the content flowing through the networking. Welcome https.<br> </p> <pre class="brush:php;toolbar:false">domain=$1 email=${2:-"your@email.com"} sudo apt-get install -y python3-certbot-nginx # manual # certbot certonly -a manual --rsa-key-size 4096 --email $email -d $domain -d www.$domain # auto ## With base nginx config certbot certonly --nginx --rsa-key-size 4096 --email $email -d $domain -d www.$domain
When the steps above succeed you can carry on with nginx config for ssl. The following will redirect all non secure connection (80) to secure connection (443)
# Usage ./laravel.sh site.domain 8.2 ~/sites ## Dependencies: letsencrypt, php$php_version, php$php_version-fpm # sudo apt-get install -y php$php_version php$php_version-fpm name=$1 # site.domain user=$2 php_version=${3:-'8.2'} root=${4:-"/var/www/vhosts/$name"} webroot=${5:-"/var/www/vhosts/$name/public"} touch /etc/nginx/sites-available/$name.conf ln -s /etc/nginx/sites-available/$name.conf /etc/nginx/sites-enabled/$name.conf mkdir -p /var/www/vhosts/$name/storage/logs touch /var/www/vhosts/$name/storage/logs/error.log touch /var/www/vhosts/$name/storage/logs/access.log cat >> /etc/nginx/sites-available/$name.conf > /etc/php/$php_version/cli/php.ini <h5> Auto renew certificate </h5> <pre class="brush:php;toolbar:false"># DISCLAIMER: it is safer to edit cron file using crontab dedicated command # That being see given this is a script we likely want to have automated /var/spool/cron/crontabs ## cron job to auto renew every 3 months for you crontab -e # 0 0 1 */3 * /usr/bin/certbot renew --quiet ## I saw people doing it monthly # 0 0 1 * *
Queue
#! /bin/bash user=${0:-$(USER)} root_dir="/home/$user/www/" processes=4 sudo apt get install -y supervisor cat >> /etc/supervisor/conf.d/laravel-worker.conf <h2> Conclusion </h2> <p>No conclusion as this is a starting point only but gets you an operational laravel app.<br> Made a lot of arbitrary choices. Adapt for your usecase.<br> Next up</p>
- automate script using orchestration (ie ansible)
- deploy using aws code deploy
- CI / CD pipeline from github
- tighting security with firewall policies
- monitoring
- load management / balancing
Originally published on bcd.dev
以上が自分のサーバーに Laravel をセットアップする: DIY ガイドの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

絶対セッションのタイムアウトはセッションの作成時に開始され、アイドルセッションタイムアウトはユーザーの操作なしに開始されます。絶対セッションタイムアウトは、金融アプリケーションなど、セッションライフサイクルの厳格な制御が必要なシナリオに適しています。アイドルセッションタイムアウトは、ソーシャルメディアなど、ユーザーが長い間セッションをアクティブに保つことを望んでいるアプリケーションに適しています。

サーバーセッションの障害は、手順に従って解決できます。1。セッションが正しく設定されていることを確認するために、サーバーの構成を確認します。 2.クライアントCookieを確認し、ブラウザがそれをサポートしていることを確認し、正しく送信します。 3. Redisなどのセッションストレージサービスを確認して、それらが正常に動作していることを確認します。 4.アプリケーションコードを確認して、正しいセッションロジックを確認します。これらの手順を通じて、会話の問題を効果的に診断および修復し、ユーザーエクスペリエンスを改善することができます。

session_start()iscrucialinphpformangingusersions.1)itInitiateSanewsessionifnoneExists、2)resumesanexistingsession、および3)SetSessionCookieforcontinuityAcrossRequests、ApplicationslicationSliviseSlikeUserauthicationAnticatent。

HTTPonlyフラグを設定することは、XSS攻撃を効果的に防止し、ユーザーセッション情報を保護することができるため、セッションCookieにとって重要です。具体的には、1)HTTPONLYフラグは、JavaScriptがCookieにアクセスするのを防ぎます。2)Flagは、PHPとFlaskのSetCookiesとMake_Responseを介して設定できます。

phpsessionssolvetheprobrof of maintainsea crossmultiplehttprequestsbyStoringdataontaonsociatingitiTauniquesessionid.1)それらは、通常はヨーロッパの側面、および一般的には、測定されている

phpssionscanStorestrings、numbers、arrays、andobjects.1.strings:textdatalikeusernames.2.numbers:integersorfloatsforcounters.3.arrays:listslikeshoppingcarts.4.objects:complextructuresthataresialized。

tostartaphpsession、outsession_start()atthescript'sbeginning.1)placeitbe foreanyouttosetthesscookie.2)usesionsionsionsionserdatalikelogintatussorshoppingcarts.3)再生セッションインドストップレベントフィックスアタック

セッション再生とは、新しいセッションIDを生成し、セッション固定攻撃の場合にユーザーが機密操作を実行するときに古いIDを無効にすることを指します。実装の手順には次のものが含まれます。1。感度操作を検出、2。新しいセッションIDを生成する、3。古いセッションIDを破壊し、4。ユーザー側のセッション情報を更新します。


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 中国語版
中国語版、とても使いやすい

MantisBT
Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

WebStorm Mac版
便利なJavaScript開発ツール

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。
