Skip to content

Instantly share code, notes, and snippets.

@mrizwan47
Last active August 21, 2024 10:15
Show Gist options
  • Save mrizwan47/f1c7a64d122d850a64e398d33c01da47 to your computer and use it in GitHub Desktop.
Save mrizwan47/f1c7a64d122d850a64e398d33c01da47 to your computer and use it in GitHub Desktop.
Install LEMP (php8.3) on Ubuntu
apt update
apt upgrade
# For Ubuntu older than 24.04:
#apt-get install ca-certificates apt-transport-https software-properties-common
#add-apt-repository ppa:ondrej/php
#apt update
apt install php8.3
apt install nginx
apt install php8.3-fpm
ufw allow 80
ufw allow 443
ufw allow 22
ufw status
ufw enable
apt install mysql-server
apt install phpmyadmin # Install phpmyadmin before securing mysql so you don't run into password validation issues
mysql_secure_installation
nano /etc/nginx/sites-available/example.com
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
# sudo htpasswd -c /etc/nginx/.htpasswd yourusername
sudo nginx -t
# sudo systemctl stop apache2
# sudo systemctl disable apache2
sudo systemctl restart nginx
apt install certbot python3-certbot-nginx
certbot
# htpasswd -c /etc/nginx/.htpasswd iamtesting
nano /var/www/html/index.php
systemctl restart nginx
systemctl restart php8.3-fpm
apt install php-mbstring php-zip php-gd php-json php-curl php-intl unzip curl npm
# Install composer
curl -sS https://getcomposer.org/installer -o composer-setup.php
HASH=$(curl -sS 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;"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
composer --version
# Install Node + NPM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
nvm install stable
ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
CREATE DATABASE database_name;
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON `database_name`.* TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
location ~ /\. {
deny all;
}
# auth_basic "Restricted Content";
# auth_basic_user_file /etc/nginx/.htpasswd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment