Last active
April 29, 2024 14:06
-
-
Save dhanar98/45b3ed3f8cc3227a2f3dd2de05d0ebff to your computer and use it in GitHub Desktop.
Install PHP 7.4 , Nginx and Install Phalcon Framework in Single Bash Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set DEBIAN_FRONTEND to noninteractive to avoid prompts | |
export DEBIAN_FRONTEND=noninteractive | |
# Update package list and upgrade existing packages | |
sudo apt update && sudo apt upgrade -y | |
# Install Nginx | |
sudo apt install nginx -y | |
sudo systemctl status nginx | |
sudo apt install curl -y | |
echo "NGINX INSTLATTION SUCCESSFULL" | |
# Install PHP and required modules | |
sudo apt update && sudo apt upgrade | |
sudo apt install software-properties-common | |
sudo add-apt-repository ppa:ondrej/php | |
sudo apt update | |
sudo apt install -y php7.4 | |
#Other Additional Packages | |
sudo apt install php7.4-curl php7.4-gd php7.4-json php7.4-mbstring php7.4-zip php7.4-fpm php7.4-cli php7.4-dev | |
sudo apt install libpcre3-dev php7.4-xml php7.4-mysql php7.4-imagick php7.4-mysql php7.4-pgsql php7.4-psr | |
echo "PHP 7.4 INSTLATTION WITH MODULES - SUCCESSFULL" | |
sudo apt install gcc | |
curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash | |
# Navigate to the temporary directory | |
cd /tmp | |
# Download Phalcon from GitHub | |
curl -sLO https://github.com/phalcon/cphalcon/archive/refs/tags/v4.1.2.zip | |
# Unzip the downloaded file | |
unzip v4.1.2.zip | |
# Navigate to the Phalcon source directory | |
cd cphalcon-4.1.2/build | |
# Run the installation script | |
./install | |
# Clean up downloaded files (optional) | |
rm /tmp/v4.1.2.zip | |
rm -r /tmp/cphalcon-4.1.2 | |
echo "PHALCON COMPILATION AND INSTALLATION SUCCESSFULL" | |
# Create 30-phalcon.ini file in /etc/php/7.4/fpm/conf.d/ | |
echo "extension=phalcon.so" | sudo tee /etc/php/7.4/fpm/conf.d/30-phalcon.ini | |
# Create 30-phalcon.ini file in /etc/php/7.4/cli/conf.d/ | |
echo "extension=phalcon.so" | sudo tee /etc/php/7.4/cli/conf.d/30-phalcon.ini | |
# Create phalcon.ini file in mods-available path | |
echo "extension=phalcon.so" | sudo tee /etc/php/7.4/mods-available/phalcon.ini | |
# Create a symbolic link to enable the Phalcon extension | |
sudo ln -s /etc/php/7.4/mods-available/phalcon.ini /etc/php/7.4/fpm/conf.d/30-phalcon.ini | |
sudo ln -s /etc/php/7.4/mods-available/phalcon.ini /etc/php/7.4/cli/conf.d/30-phalcon.ini | |
echo "PHALCON SYMLINK CREATION SUCCESSFULL FOR PHP.INI" | |
# Start and enable Nginx and PHP-FPM | |
sudo systemctl start nginx | |
sudo systemctl enable nginx | |
sudo systemctl start php7.4-fpm # Adjust version as needed | |
sudo systemctl enable php7.4-fpm # Adjust version as needed | |
# Test Nginx configuration and reload Nginx | |
sudo nginx -t | |
sudo systemctl reload nginx | |
# Create the Nginx configuration file | |
sudo bash -c 'cat > /etc/nginx/sites-available/phalcon-pro.conf <<EOF | |
server { | |
listen 80; | |
server_name localhost; | |
root /var/www/phalcon/public; | |
index index.php; | |
charset utf-8; | |
location / { | |
try_files \$uri \$uri/ /index.php?\_url=\$uri&\$args; | |
} | |
location ~ \.php { | |
fastcgi_pass unix:/run/php/php7.4-fpm.sock; | |
fastcgi_index /index.php; | |
include fastcgi_params; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_param PATH_INFO \$fastcgi_path_info; | |
fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info; | |
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
} | |
EOF' | |
# Create a symbolic link to enable the site | |
sudo ln -s /etc/nginx/sites-available/phalcon-pro.conf /etc/nginx/sites-enabled/ | |
# Reload Nginx to apply the new configuration | |
sudo systemctl reload nginx | |
echo "RESTART ALL THE SERVERS AND RELOAD THE CONFIGURATION SUCCESSFULL" | |
sudo service php7.4-fpm restart | |
php -m | |
echo "PHP and Nginx installation complete." | |
#Check Phalcon is installed or not | |
php -m | grep phalcon | |
echo "REMINDER : CHANGE ROOT PATH IN NGINX CONF" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment