Wednesday, August 26, 2020

Laravel linux server setup process steps

 "nano /etc/ssh/sshd_config" and "PermitRootLogin yes" for PUTTY access


passwd ----for password change


sudo adduser USERNAME ---for adding new user

usermod -aG sudo USERNAME ---for permission new user


sudo a2ensite your_domain.conf

sudo a2dissite 000-default.conf




https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04

https://www.cloudbooklet.com/upgrade-php-version-to-php-7-4-on-ubuntu/


sudo apt update


sudo apt install curl wget php-cli php-zip php-mbstring git unzip php-xml php7.2-gd


sudo service apache2 restart



php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"


HASH="$(wget -q -O - https://composer.github.io/installer.sig)"


php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"


sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer




sudo a2enmod rewrite


sudo chown -R www-data:www-data /var/www/html/sitedomain


sudo nano /etc/apache2/sites-available/000-default.conf 


then


DocumentRoot /var/www/html/sitedomain/public

ServerName sitedomain.com

CustomLog /var/log/apache2/sitedomain.com-access.log combined

ErrorLog /var/log/apache2/sitedomain.com-error.log

<Directory /var/www/html/sitedomain/public/>

Options +Indexes +Includes +FollowSymLinks +MultiViews

AllowOverride All

Require all granted

</Directory>


sudo service apache2 restart


https://docs.beyondco.de/laravel-websockets/1.0/basic-usage/starting.html#using-a-different-port


MAIL_HOST=smtp.sendgrid.net

MAIL_PORT=587

MAIL_USERNAME=apikey

MAIL_PASSWORD=pass

MAIL_ENCRYPTION=null


truncate -s0 error.log //for truncate any file

rm storage/logs/laravel-*.log //delete all log file


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

systemctl restart mysql.service



[program:websockets]

command=/usr/bin/php /var/www/html/sitedomain/artisan websockets:serve --port=3030

numprocs=1

autostart=true

autorestart=true

user=root

stdout_logfile=/var/www/html/sitedomain/websockets.log


[program:websockets]

command=/usr/bin/php /var/www/sitedomainlive/artisan websockets:serve --port=3030

numprocs=1

autostart=true

autorestart=true

user=root

stdout_logfile=/var/www/sitedomainlive/websockets.log




[program:laravel-worker]

process_name=%(program_name)s_%(process_num)02d

command=php /var/www/html/sitedomain/artisan queue:work --sleep=3 --tries=3

autostart=true

autorestart=true

user=root

numprocs=8

redirect_stderr=true

stdout_logfile=/var/www/html/sitedomain/worker.log

stopwaitsecs=3600



https://stillat.com/blog/2016/12/07/laravel-task-scheduling-running-the-task-scheduler


crontab -e //adding cron entry to cron tab

sudo service cron restart



[program:laravel_corn]

command=* * * * * php /var/www/html/sitedomain/artisan schedule:run >> /dev/null 2>&1

process_name=%(program_name)s_%(process_num)02d

numprocs=1

autostart=true

autorestart=true

startsecs=0

user=www-data

redirect_stderr=true

stderr_logfile = /var/www/html/sitedomain/laravel_corn_err.log

stdout_logfile = /var/www/html/sitedomain/laravel_corn_stdout.log

stdout_logfile_maxbytes=10MB

stdout_logfile_backups=10



sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start laravel-worker:*

sudo supervisorctl start websockets


sudo ufw allow 3030/tcp



nano /etc/php/7.2/apache2/php.ini


max_execution_time = 120

max_input_vars = 2500

memory_limit = 128M

post_max_size = 32M

upload_max_filesize = 24M

max_file_uploads = 100


sudo service apache2 restart


ab -k -n 500 -c 50 http://sitedomain.com/ //apache branch mark testing for 500 request and 50 concurent user


sudo chown -R $USER:www-data storage

sudo chown -R $USER:www-data bootstrap/cache

chmod -R 775 storage

chmod -R 775 bootstrap/cache

ps aux | egrep '(apache|httpd)'


MAIL_DRIVER=smtp

MAIL_HOST=smtp.sendgrid.net

MAIL_PORT=587

MAIL_USERNAME=apikey

MAIL_PASSWORD=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

MAIL_ENCRYPTION=null



Include /etc/letsencrypt/options-ssl-apache.conf


sudo chown -R $USER:www-data /etc/letsencrypt/live/sitedomain.com

chmod -R 775 /etc/letsencrypt/live/sitedomain.com


//for ssl 

LARAVEL_WEBSOCKETS_HOST=sitedomain.com

LARAVEL_WEBSOCKETS_SCHEME=https

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=/etc/letsencrypt/live/sitedomain.com/fullchain.pem

LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=/etc/letsencrypt/live/sitedomain.com/privkey.pem

LARAVEL_WEBSOCKETS_ENCRYPTED=true

MIX_LARAVEL_WEBSOCKETS_ENCRYPTED="${LARAVEL_WEBSOCKETS_ENCRYPTED}"


//withour ssl

LARAVEL_WEBSOCKETS_HOST=

LARAVEL_WEBSOCKETS_SCHEME=

LARAVEL_WEBSOCKETS_SSL_LOCAL_CERT=

LARAVEL_WEBSOCKETS_SSL_LOCAL_PK=

LARAVEL_WEBSOCKETS_ENCRYPTED=false

MIX_LARAVEL_WEBSOCKETS_ENCRYPTED="${LARAVEL_WEBSOCKETS_ENCRYPTED}"