Skip to content

Instantly share code, notes, and snippets.

@thomijasir
Last active July 30, 2018 12:02
Show Gist options
  • Save thomijasir/d87b1ce637245bf48d6b9005f2ada996 to your computer and use it in GitHub Desktop.
Save thomijasir/d87b1ce637245bf48d6b9005f2ada996 to your computer and use it in GitHub Desktop.
Install LEMP in Debin 9 with newer PHP
## Install Requiriment And update System
apt-get -y update
apt-get -y upgrade
apt-get -y dist-upgrade
apt-get -y install sudo nano git zip net-tools sudo wget curl bash-completion
apt-get -y install software-properties-common dirmngr
apt-get -y install apt-transport-https lsb-release ca-certificates
## Add Nginx Source List
echo "deb http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
echo "deb-src http://nginx.org/packages/debian/ stretch nginx" >> /etc/apt/sources.list
## Add MariaDB Source List
echo "deb [arch=amd64,i386,ppc64el] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.2/debian stretch main" >> /etc/apt/sources.list
echo "deb-src http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.2/debian stretch main" >> /etc/apt/sources.list
## Add Repo For PHP 7.2
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
## Nginx Key Pairing
wget https://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
## MariaDB Key Pairing
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
apt-get -y update
apt-get -y install nginx
apt-get -y install mariadb-server
apt-get -y install php7.2 php7.2-common php7.2-cli php7.2-fpm php7.2-mysql php7.2-curl php7.2-gd php7.2-cgi php7.2-json php7.2-mbstring php7.2-dom php-imagick
## Optional Secue Instalation
sudo mysql_secure_installation
# Make Sure All System Set
systemctl restart nginx
systemctl restart php7.2-fpm
# Set System On Boot
systemctl enable nginx
# Install Composer PHP
cd
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer
# Other Info
# if you get some error message like
# 2014/09/17 00:17:30 [crit] 11909#0: *34 connect() to unix:/var/run/php-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: www.ehowstuff.com, request: "GET /feed/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php-fpm.sock:", host: "www.ehowstuff.com"
# You Have To Edit on php pool config /etc/php/7.2/fpm/pool.d/www.conf and change + uncomment line blow
# listen.owner = www-data
# listen.group = www-data
# listen.mode = 0666
# Don't forget to give permisson to working or sever diectory
# chown -R www-data:www-data /to/your/directory
# Lets Setup The VHost Sample Code Virtual Host
server {
listen 80;
server_name localhost;
root /srv/default;
index index.html index.php index.htm;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
# NodeJS 8
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
# Add SSL By LestEncrypt
echo "deb http://ftp.debian.org/debian stretch-backports main" >> /etc/apt/sources.list
sudo apt-get -y update
sudo apt-get install python-certbot-nginx -t stretch-backports
# use command below if you want to setup for new domain
sudo certbot --authenticator webroot --installer nginx
# run only one time
sudo certbot renew --dry-run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment