Last active
January 21, 2022 16:18
-
-
Save FrangaL/40ee076c53645b53083229c080d76ec4 to your computer and use it in GitHub Desktop.
Installing Laravel Framework on Ubuntu/Debian with Nginx and PHP-FPM 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# Installing Laravel Framework on Ubuntu/Debian with Nginx and PHP-FPM 8.1 | |
git_laravel="https://github.com/laravel/laravel.git" | |
php_version="8.1" | |
apt update | |
# Install dependencies | |
apt -y install lsb-release apt-transport-https ca-certificates git wget curl unzip | |
# Add repository sury | |
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg | |
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list | |
apt update | |
# Install nginx and php | |
apt install -y nginx php${php_version} php${php_version}-{cli,bcmath,bz2,intl,gd,mbstring,mysql,zip,xml,opcache,fpm,curl} | |
# Clone Laravel | |
git clone --depth 1 $git_laravel /var/www/laravel | |
# Configure default site nginx | |
cat <<\EOM >/etc/nginx/sites-available/default | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
access_log off; | |
error_log off; | |
root /var/www/laravel/public; | |
index index.php index.html index.htm index.nginx-debian.html; | |
server_name _; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location ~ \.php$ { | |
try_files $uri =404; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/run/php/php8.0-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} | |
EOM | |
# Restart nginx | |
systemctl restart nginx.service | |
# Install composer | |
EXPECTED_CHECKSUM="$(wget -q -O - https://composer.github.io/installer.sig)" | |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" | |
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ] | |
then | |
>&2 echo 'ERROR: Invalid installer checksum' | |
rm composer-setup.php | |
exit 1 | |
else | |
php composer-setup.php --install-dir=/usr/local/bin --filename=composer | |
rm composer-setup.php | |
fi | |
# Install nodejs | |
curl -sL https://deb.nodesource.com/setup_14.x | bash - | |
apt install -y nodejs | |
# Install yarm | |
curl -sL 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 | |
apt update | |
apt install -y yarn | |
# Finalize Laravel install | |
cd /var/www/laravel | |
composer install --no-dev | |
npm install | |
cp .env.example .env | |
php artisan key:generate | |
# Change permision Laravel files | |
chown www-data:www-data /var/www/laravel -R |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment