0

I try to install Laravel in Ubuntu 18.04 with Nginx in Amazon AWS.

I follow this nice tutorial: https://linux4one.com/how-to-install-laravel-php-framework-with-nginx-on-ubuntu-18-04/

but in the last instruction:

ngnix -t

I get this error:

nginx: [emerg] open() "/etc/nginx/sites-enabled/laravel" failed (2: No such file or directory) in /etc/nginx/nginx.conf:62 nginx: configuration file /etc/nginx/nginx.conf test failed

And when I go to this file in line 62, I see this:

include /etc/nginx/sites-enabled/*;

    user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

here my file /etc/nginx/sites-available/laravel.conf

server {
         listen 80;
         listen [::]:80 ipv6only=on;

         # Log files for Debugging
         access_log /var/log/nginx/laravel-access.log;
         error_log /var/log/nginx/laravel-error.log;

         # Webroot Directory for Laravel project
         root /var/www/laravel/public;
         index index.php index.html index.htm;

         # Your Domain Name
         server_name 99.80.169.66;

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

         # PHP-FPM Configuration Nginx
         location ~ \.php$ {
                 try_files $uri =404;
                 fastcgi_split_path_info ^(.+\.php)(/.+)$;
                 fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include fastcgi_params;
         }
 }

here is my file /var/www/laravel/.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=laravel
DB_PASSWORD=66345345

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
1
  • here is my file: Commented Sep 8, 2019 at 21:43

1 Answer 1

1

try this 1. install nginx

`apt-get install nginx`
  1. install php 7.3
    sudo add-apt-repository ppa:ondrej/php
    sudo apt-get update
    sudo apt-get install php7.3

    sudo apt install php7.3-cli php7.3-fpm php7.3-json php7.3-pdo php7.3-mysql php7.3-zip php7.3-gd  php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath php7.3-json

3.install mysql server

    sudo apt install mysql-server
    sudo mysql_secure_installation

enter password and y to all

    sudo mysql
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password'

    ;
    FLUSH PRIVILEGES;
    GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';

  1. setup for remote sql server

    nano /etc/mysql/mysql.conf.d/mysqld.cnf

    bind-address = 127.0.0.1 to: bind-address = 0.0.0.0

    systemctl restart mysql.service

    sudo mysql
    CREATE USER 'sid'@'localhost' IDENTIFIED BY 'strong_password';

    GRANT ALL PRIVILEGES ON *.* TO 'sid'@'localhost'
    ->     WITH GRANT OPTION;

    CREATE USER 'sid'@'%' IDENTIFIED BY 'strong_password';

    GRANT ALL PRIVILEGES ON *.* TO 'sid'@'%'
        ->     WITH GRANT OPTION;

  1. install composer

apt-get install composer

  1. install redis server

apt install redis-server

nano /etc/redis/redis.conf

change text `

supervised no
to 
supervised systemd

restart redis

systemctl restart redis.service

testing redis redis-cli ping reply pong

change redis password

nano /etc/redis/redis.conf uncomment # requirepass foobared

full details here https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04

  1. install nodejs server

    Using Ubuntu

curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash - sudo apt-get install -y nodejs

Using Debian, as root

curl -sL https://deb.nodesource.com/setup_11.x | bash - apt-get install -y nodejs

8.upload site 9.grant permission sudo chown -R www-data:www-data storage/ sudo chown -R www-data:www-data public/

server {
    listen 80;
    listen [::]:80;
    root /home/sid/website/searustasia/public;
    index  index.php index.html index.htm;
        listen 443 ssl;
        ssl_certificate /home/sid/website/searustasia/ssl/searustasia.crt;
        ssl_certificate_key /home/sid/website/searustasia/ssl/searustasia.key;
    server_name  api.searustasia.com;

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


    location ~ \.php$ {
       include snippets/fastcgi-php.conf;
       fastcgi_pass             unix:/var/run/php/php7.3-fpm.sock;
       fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

don't forget to restart nginx

Sign up to request clarification or add additional context in comments.

4 Comments

Hi sid heart, for help me, but I follow your instructions and I get many errors. Please with this instructions: linux4one.com/… all work fine for me, except the last step, sure is a small detail to do. Please can check what`s can be wrong?
I added in my comment the code of 2 files: /etc/nginx/sites-available/laravel.conf /var/www/laravel/.env
@fireDevelop.com i can't see file you added to comment
@fireDevelop.com contact me if you still getting problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.