-
-
Save junaidulqayyumqureshi/914cd104fd2f9cc1c222f2836f4141e1 to your computer and use it in GitHub Desktop.
Unable to find apache-fpm-fork or something
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install apache2 apache2-doc apache2-utils
PHP Max File size limit
$max_upload = (int)(ini_get('upload_max_filesize'));
$max_post = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
$memory_limit = (int)(ini_get('max_execution_time'));
$upload_mb = min($max_upload, $max_post, $memory_limit);
Above enteries can be changed from
/etc/php/7.4
For apache:
/etc/php/7.4/apache/php.ini
For fpm:
/etc/php/7.4/fpm/php.ini
To restart service
Apache:
systemctl reload apache2
FPM:
service php7.4-fpm restart
Phpmyadmin
If phpmyadmin stops responding or doesn't allow login
or error
#2002 - No such file or directory — The server is not responding (or the local server's socket is not correctly configured).
mysqli_real_connect(): (HY000/2002): No such file or directory
Connection for controluser as defined in your configuration failed.
/etc/phpmyadmin/config.inc.php
Fix#1
Replace this code:
if (empty($dbserver)) $dbserver = 'localhost';
$cfg['Servers'][$i]['host'] = $dbserver;
if (!empty($dbport) || $dbserver != 'localhost') {
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['port'] = $dbport;
}
with
if (empty($dbserver)) $dbserver = '127.0.0.1';
$cfg['Servers'][$i]['host'] = $dbserver;
if (!empty($dbport) || $dbserver != '127.0.0.1') {
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['port'] = $dbport;
}
Fix#2
Maybe your SQL server has been stopped
sudo /etc/init.d/mysql start
or
sudo service mysqld start
and useservice mysql status
to check status
UPGRADE PHPMYADMIN
Restart Ubuntu Server (Digital Ocean droplet)
sudo shutdown -r now
Setup pm2 processes to start if system restarts
const port = process.argv[2] || 3000;
pm2 start server/server.js --name "server-3000" -- 3000
pm2 start server/server.js --name "server-3001" -- 3001
pm2 start server/server.js --name "server-3002" -- 3002
pm2 start server/server.js --name "server-3003" -- 3003
After starting all the processes which you want after startup
pm2 startup ubuntu
pm2 save
PHPMyAdmin 413 Request Entity Too Large
nginx/sites-available/apache
server {
listen 80;
server_name 139.59.37.163;
location / {
client_max_body_size 1024M;
}
}
Angular Website Refresh Page Not Found NGINX
location / {
try_files $uri $uri/ /index.html?$args;
}
If Laravel can't find the class and you are sure that your namespace is correct and class exists then:
composer dumpautoload
Laravel Custom Auth Modifications
laravel-framework-src-illuminate-Auth-EloquentUserProvider
laravel-framework-src-illuminate-Foundation-Auth-AuthenicatesUsers.php
Create a new FTP user and Specify one directory permission
sudo adduser yourftpuser
sudo usermod -d /your/path/for/the/user yourftpuser
sudo chown username: myfolder (To give permission of a folder to user)
Two more commands:
chown -R username directory
chmod -R u+rX directory
The first command makes the user own the directory. The second command gives them full read and access permissions. The r gives read permission, the X gives 'execute' permission to directories, and not files.
Allowed Memory Size Limit Exceeded/Exhausted
COMPOSER_MEMORY_LIMIT=-1 composer require huddledigital/zendesk-laravel
GRANT REMOTE ACCESS TO USER
Backup /etc/mysql/mysql.conf.d/mysqld.cnf file and edit the original file
Navigate to the line that begins with the bind-address directive. It will look like this:
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
bind-address = 0.0.0.0
Add bind-address = 0.0.0.0 & restart mysql service with sudo systemctl restart mysql
RUN ALL BELOW FOR 1 USER
1- CREATE USER 'sendy'@'localhost' IDENTIFIED BY 'buzTq7DdgEbhP33a';
2- GRANT ALL PRIVILEGES ON . TO 'sendy'@'localhost' WITH GRANT OPTION;
3- CREATE USER 'sendy'@'%' IDENTIFIED BY 'buzTq7DdgEbhP33a';
4- GRANT ALL PRIVILEGES ON . TO 'sendy'@'%' WITH GRANT OPTION;
5- FLUSH PRIVILEGES;
Change MYSQL/Phpmyadmin Password
SET PASSWORD FOR root@localhost = PASSWORD('Password');
Change Server Root Password
sudo passwd root
Check Server Load and Usage
top -c
command shows the memory and cpu usage by each application/script
nproc
shows number of processors available
free -h
shows the RAM memory and show how much is used and how much remains
/var/log/mysql
will have a file mysql-slow.log which will have logs of query took minutes which are mentioned in mysqld.cnf file
Angular Cache Reset for deployment
For Ang 10:
ng build --prod --aot --outputHashing=all
For <Ang 10:
ng build --prod --aot --output-hashing=all
Recursively Search String in files/folders
grep -Rw stringToSearch /var/www/project/*;
Recursively Replace string in files/folders
find /var/www/project/ -name \*.php -exec sed -i "s/stringToFind/stringToReplace/g" {} \;
Timezone Change
To change timezone
timedatectl set-timezone Asia/Karachi
To get timezone info:
timedatectl
systemctl restart mysql
systemctl reload apache2
systemctl restart apache2
Disable MYSQL ONLY FULL GROUP BY
Goto /etc/mysql
& search for my.cnf
whether shortcut of file, open terminal and type:
nano /etc/mysql/my.cnf
& append below includedirs:
[mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
PAID SSL (GoDaddy etc) - Not Lets Encrypt
Create a directory & adjust rights:
mkdir /etc/nginx/ssl
sudo chmod -R 600 /etc/nginx/ssl
Generate 2 keys, 1 example.com.key & 2 for example.com.csr
openssl req -newkey rsa:2048 -nodes -keyout example.com.key -out example.com.csr
Fill in the informations or skip by pressing enter, except Common Name FQDN etc. Provide your website name i.e example.com
2 files will be generated:
1- example.com.key
2- example.com.csr
Provide content of this csr file by copying > cat example.com.csr
and provide to SSL provider.
Once SSL zip file is downloaded from SSL Provider. Unzip it and rename with following:
1- randomnumber.crt to example.com.crt
2- xxxbundle.crt to intermediate.crt
Copy both the files to /etc/nginx/ssl
run command:
cat example.com.crt intermediate.crt > example.com.chained.crt
Then change sites-available/site to following:
server {
root /var/www/site;
index index.php index.html index.htm;
client_max_body_size 120M;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
include snippets/fastcgi-php.conf;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/nginx/ssl/example.com.chained.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.example.com) {
return 301 https://$host$request_uri;
}
if ($host = example.com) {
return 301 https://$host$request_uri;
}
server_name example.com www.example.com;
listen 80;
return 404; # managed by Certbot
}
Test nginx & restart by:
nginx -t
systemctl restart nginx
Check processes running linux:
ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%cpu | head
AWS EC2 INSTANCE CREATION
Setting up another website in a subdirectory
server {
root /var/www/example.com;
index index.php index.html index.htm;
client_max_body_size 120M;
server_name example.com www.example.com;
location / {
try_files $uri $uri/ /index.html?$query_string;
}
location /blog {
root /var/www/; //Make sure that project directory is named exactly as "location /blog" i.e. /var/www/blog
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}
}
Deployment on DigitalOcean Apps Platform of a docker react app
1- Create file named "Dockerfile" (Without any extension)
2- Create folder called .docker on root and create a file in it with name "prod.Dockerfile"
Copy below content in both the files
# Use an official Node.js runtime as a parent image
FROM node:14-alpine
# Set the working directory to /app
WORKDIR /build
# Copy the package.json and package-lock.json files to the container
COPY package*.json ./
# Install the dependencies
RUN npm install
# Install the dependencies
RUN npm install -g serve
# Copy the remaining application files to the container
COPY . .
# Build the application
RUN npm run build
# Set the production environment variable
ENV NODE_ENV=production
# Expose port 3000
EXPOSE 3000
# Start the application
CMD ["serve", "-s", "build"]
3- After that, create an app on app platform and choose this repo
4- Remove extra webservice instances, if any, other than Docker WebService.
5- Define a port i.e. 3000 in settings
6- Define start and build scripts in package.json i.e. react-scripts start
Voila!!!
Recover EC2 instance & Connect without key pair
Permission Denied EC2 CodeCommit
sudo chown -R ubuntu .git/
LAMP Stack
Source
LAMP Stack
PHP/FPM/FastCGI Issues
https://askubuntu.com/questions/1319861/how-to-configure-apache-http-to-php-fpm-on-ubuntu-20-10
Php Issues
Php Issues regarding repository
Phpmyadmin User Rights
Source
PHP 7.4
Source
INSTALL NPM/NODE
NPM & NodeJS
Laravel Permissions after deployment
Shared Hosting
SSH
LARAVEL clear everything
Apache SSL
For SSL Expiration information
echo | openssl s_client -connect domain.com:443 2>/dev/null | openssl x509 -noout -dates
For redirection from www.
sudo certbot --apache -d example.com -d www.example.com
NGINX Configuration
Source
Nginx Configuration
Source
Another Source
For node app config in nginx/sites-available
Main domain script
Sub domain script
/etc/apache2/apache.conf
To verify port on which apache is running
sudo netstat -tlpn
NGINX - SSL
Source
SSL Installation Source
SSL ON NGINX UBUNTU v20
Source
For firewall purposes
Source
Firewall Issue
sudo ufw enable
disconnect SSH
Goto digitalocean droplet console
Any nginx error
sudo tail -30 /var/log/nginx/error.log
For nodejs multi instances
const port = process.argv[2] || 3000;