DEV Community

Pradeep Kumar
Pradeep Kumar

Posted on • Updated on

Install Laravel on Cloud Server

https://www.linode.com/docs/guides/how-to-install-and-use-nginx-on-ubuntu-20-04/

sudo apt update && sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode
sudo apt install nginx
Enter fullscreen mode Exit fullscreen mode
sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode
sudo ufw allow http
Enter fullscreen mode Exit fullscreen mode
sudo ufw reload
Enter fullscreen mode Exit fullscreen mode

https://www.rosehosting.com/blog/install-laravel-on-ubuntu-20-04/

apt-get install php8.0 libapache2-mod-php8.0 php8.0-curl php-pear php8.0-gd php8.0-dev php8.0-zip php8.0-mbstring php8.0-mysql php8.0-fpm libapache2-mod-fcgid php8.0-xml curl -y
Enter fullscreen mode Exit fullscreen mode
curl -sS https://getcomposer.org/installer | php
Enter fullscreen mode Exit fullscreen mode
mv composer.phar /usr/local/bin/composer
Enter fullscreen mode Exit fullscreen mode
chmod +x /usr/local/bin/composer
Enter fullscreen mode Exit fullscreen mode
composer --version
Enter fullscreen mode Exit fullscreen mode
cd /var/www/
Enter fullscreen mode Exit fullscreen mode

Replace domain.com to your domain.

composer create-project laravel/laravel domain.com --prefer-dist
Enter fullscreen mode Exit fullscreen mode
cd domain.com
Enter fullscreen mode Exit fullscreen mode
php artisan
Enter fullscreen mode Exit fullscreen mode
chown -R www-data:www-data /var/www/domain.com
Enter fullscreen mode Exit fullscreen mode
chmod -R 777 /var/www/domain.com/storage
Enter fullscreen mode Exit fullscreen mode
sudo nano /etc/nginx/sites-available/domain.com
Enter fullscreen mode Exit fullscreen mode
server {
    listen 80;
    listen [::]:80;
    server_name  domain.com;

    root /var/www/domain.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php index.html;

    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_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;
    }

}
Enter fullscreen mode Exit fullscreen mode
sudo ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled/
Enter fullscreen mode Exit fullscreen mode

Top comments (0)