Skip to content

Instantly share code, notes, and snippets.

@ajayfroiden
Last active February 4, 2025 09:54
Show Gist options
  • Save ajayfroiden/5ef6c3d8f662bb425fde71d46404de74 to your computer and use it in GitHub Desktop.
Save ajayfroiden/5ef6c3d8f662bb425fde71d46404de74 to your computer and use it in GitHub Desktop.
Install LEMP
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
# Ubuntu 24.04 dev Server
# Run like (without sudo) - bash install_lamp.sh
# Script should auto terminate on errors
export DEBIAN_FRONTEND=noninteractive
echo -e "\e[96m Adding PPA \e[39m"
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update
echo -e "\e[96m Installing nginx \e[39m"
sudo apt-get -y install nginx
echo -e "\e[96m Installing php - 8.3 \e[39m"
sudo apt-get -y install php8.3-fpm
sudo apt-get -y install curl zip unzip
echo -e "\e[96m Installing supervisor \e[39m"
sudo apt-get -y install supervisor
echo -e "\e[96m Installing php extensions \e[39m"
sudo apt-get -y install php8.3-cli php8.3-curl php8.3-ctype php8.3-uuid \
php8.3-pgsql php8.3-gd \
php8.3-imap php8.3-mysql php8.3-mbstring php8.3-iconv \
php8.3-xml php8.3-zip php8.3-bcmath php8.3-soap php8.3-gettext \
php8.3-intl php8.3-readline \
php8.3-msgpack php8.3-igbinary php8.3-ldap \
php8.3-redis php8.3-grpc
echo -e "\e[96m Restart nginx server to reflect changes \e[39m"
sudo service nginx restart
# Download and install composer
echo -e "\e[96m Installing composer \e[39m"
# Notice: Still using the good old way
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --force --filename=composer
# Add this line to your .bash_profile
# export PATH=~/.composer/vendor/bin:$PATH
echo -e "\e[96m Installing mysql client \e[39m"
sudo apt install -y mysql-client
echo -e "\e[96m Installing mysql server \e[39m"
sudo apt install -y mysql-server
# Check php version
php -v
# Check if php is working or not
php -r 'echo "\nYour PHP installation is working fine.\n";'
# Fix composer folder permissions
mkdir -p ~/.composer
sudo chown -R "$USER" "$HOME/.composer"
# Check composer version
composer --version
echo -e "\e[92m Open http://localhost/ to check if nginx is working or not. \e[39m"
# Clean up cache
sudo apt-get clean
@ajayfroiden
Copy link
Author

ajayfroiden commented Jan 23, 2025

Installing LEMP Stack on Ubuntu

There are two methods to install the LEMP stack on your Ubuntu system:

Method 1

You can run them in the terminal like this:

curl -o- https://gist.githubusercontent.com/ajayfroiden/5ef6c3d8f662bb425fde71d46404de74/raw/19819046355747cc4e2fd302b960a974cf263700/install_lemp_ubuntu.sh | bash

Method 2

You can try this method to run it in the terminal

wget https://gist.githubusercontent.com/ajayfroiden/5ef6c3d8f662bb425fde71d46404de74/raw/19819046355747cc4e2fd302b960a974cf263700/install_lemp_ubuntu.sh

chmod +x install_lamp_ubuntu.sh
 
./install_lamp_ubuntu

@ajayfroiden
Copy link
Author

Change or SET mysql Password

sudo mysql -uroot

After running above command your will see below screen

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 264
Server version: 8.0.30-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'yourpasswd';
mysql> FLUSH PRIVILEGES;
mysql> exit;

Now TEST logging by

mysql -u root -p

You will be prompted to
Enter Password: yourpassword

@ajayfroiden
Copy link
Author

ajayfroiden commented Jan 29, 2025

Add an SSL Certificate for HTTPS

This is the last step in this tutorial If you do not have a domain name yet, you can skip this part.
If you have a domain name assigned to the application, we can install a Free SSL certificate using Let’s Encrypt. It is always recommended to secure your website with an SSL certificate.

We need to install the Certbot client on our server.

sudo apt install certbot python3-certbot-nginx -y

Once Certbot is installed, you can now request an SSL certificate for your domain name

sudo certbot --nginx -d example.com

This will generate an SSL certificate for you and certbot will rewrite your Nginx configuration file to handle redirects from HTTP to HTTPS and also set the path to the SSL certificates.

By default Let’s Encrypt certificates expire after 90 days and we might want to renew them as soon as they expire.

@ajayfroiden
Copy link
Author

Symb Link

sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment