-
-
Save ajayfroiden/5ef6c3d8f662bb425fde71d46404de74 to your computer and use it in GitHub Desktop.
#!/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 | |
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.
Symb Link
sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/
Change or SET mysql Password
After running above command your will see below screen
Now TEST logging by
You will be prompted to
Enter Password: yourpassword