Skip to content

Instantly share code, notes, and snippets.

@ebnhxcode
Forked from Yekutiel/centos7_ps_install.sh
Created November 26, 2018 00:42
Show Gist options
  • Save ebnhxcode/9ca266108a4a2e913fcee9a5d46688cd to your computer and use it in GitHub Desktop.
Save ebnhxcode/9ca266108a4a2e913fcee9a5d46688cd to your computer and use it in GitHub Desktop.
CentOS 7: PrestaShop 1.7.2.0 installer
#!/bin/bash
PS_VERSON=1.7.2.0
prompt_confirm() {
while true; do
read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
case $REPLY in
[yY]) echo ; return 0 ;;
[nN]) echo ; return 1 ;;
*) printf " \033[31m %s \n\033[0m" "invalid input"
esac
done
}
while true; do
echo "======================"
echo " 1 - Install"
echo " 2 - Post-installation"
echo " q - Quit"
echo "======================"
read -r -n 1 -p "Select: " PS_OPTION
echo ;
if [ "$PS_OPTION" = "q" ]; then exit 0; fi
if [ "$PS_OPTION" = "1" ]; then
while true; do
echo "If developing you may find using the catch-all option,"
echo " however, it is NOT recommended for production use."
echo "If using multi-stores with multiple domains, specify here"
echo " with each domain separated with a space."
echo " For example: storeone.com storetwo.com store.example.com"
read -r -p "Hostname (eg example.com) [catch-all]: " PS_HOSTNAME
echo ;
PS_HOSTNAME=${PS_HOSTNAME:-_}
read -r -p "MySQL Database [prestashop]: " DATABASE_NAME
echo ;
DATABASE_NAME=${DATABASE_NAME:-prestashop}
read -r -s -p "MySQL Password [auto-generate]: " DATABASE_PASS
echo ;
DATABASE_PASS_GEN="$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 20)"
DATABASE_PASS=${DATABASE_PASS:-$DATABASE_PASS_GEN}
echo "------------"
if [ "$PS_HOSTNAME" = "_" ]
then
echo "Hostname: [catch-all]"
else
echo "Hostname: $PS_HOSTNAME"
fi
echo "Database name: $DATABASE_NAME"
if [ "$DATABASE_PASS" = "$DATABASE_PASS_GEN" ]
then
echo "Database password: [auto-generated]"
else
echo "Database password: $DATABASE_PASS"
fi
echo "------------"
if prompt_confirm "Do these settings look ok?"
then
break
fi
done
echo "---- Updating System ----"
yum -y update
yum -y install epel-release
echo "---- Installing deps ----"
yum -y install firewalld unzip
# Disable SELINUX
sed -i 's/enforcing/disabled/g' /etc/selinux/config
#https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/
echo "---- Installing MySQL (MariaDB) ----"
yum -y install mariadb mariadb-server net-tools
systemctl enable mariadb.service
systemctl start mariadb.service
echo "---- Setting up MySQL ----"
mysqladmin -u root password "$DATABASE_PASS"
mysql -u root -p"$DATABASE_PASS" -e "UPDATE mysql.user SET Password=PASSWORD('$DATABASE_PASS') WHERE User='root'"
mysql -u root -p"$DATABASE_PASS" -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')"
mysql -u root -p"$DATABASE_PASS" -e "DELETE FROM mysql.user WHERE User=''"
mysql -u root -p"$DATABASE_PASS" -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%'"
mysql -u root -p"$DATABASE_PASS" -e "FLUSH PRIVILEGES"
mysql -u root -p"$DATABASE_PASS" -e "CREATE DATABASE $DATABASE_NAME"
echo "---- Installing Nginx ----"
yum -y install nginx
echo "---- Configuring Nginx ----"
cat <<'EOM' > /etc/nginx/nginx.conf
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 2;
include /etc/nginx/conf.d/*.conf;
}
EOM
cat <<'EOM' | sed -e "s/PS_HOSTNAME/$PS_HOSTNAME/g" | cat > /etc/nginx/conf.d/default.conf
server {
listen 80;
#listen [::]:80; #IPv6 support
server_name PS_HOSTNAME; # example.com www.example.com
root /var/www/prestashop;
access_log /var/log/nginx/prestashop.access.log;
error_log /var/log/nginx/prestashop.error.log;
index index.php index.html; # Letting nginx know which files to try when requesting a folder
location = /favicon.ico {
log_not_found off; # PrestaShop by default does not provide a favicon.ico
access_log off; # Disable logging to prevent excessive log sizes
}
location = /robots.txt {
auth_basic off; # Whatever happens, always let bots know about your policy
allow all;
log_not_found off; # Prevent excessive log size
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
error_page 500 502 503 504 /error500.html;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6"; # Do people still use Internet Explorer 6? In that case, disable gzip and hope for the best!
gzip_vary on; # Also compress content with other MIME types than "text/html"
gzip_types application/json text/css application/javascript; # We only want to compress json, css and js. Compressing images and such isn't worth it
gzip_proxied any;
gzip_comp_level 6; # Set desired compression ratio, higher is better compression, but slower
gzip_buffers 16 8k; # Gzip buffer size
gzip_http_version 1.0; # Compress every type of HTTP request
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
try_files $uri =404;
fastcgi_keep_conn on;
fastcgi_pass unix:/var/run/php-fpm.sock;
include fastcgi.conf;
}
}
EOM
systemctl enable nginx.service
systemctl start nginx.service
echo "---- Installing PHP ----"
sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php71w php71w-fpm php71w-mysql php71w-mcrypt php71w-gd php71w-mbstring php71w-dom php71w-soap
echo "---- Configuring PHP ----"
cat <<EOM >> /etc/php.ini
safe_mode = Off
safe_mode_gid = Off
file_uploads = On
allow_url_fopen = On
allow_url_include = Off
register_globals = Off
zlib.output_compression = On
zlib.output_compression_level = 6
memory_limit = 128M
max_execution_time = 3
upload_max_filesize = 16M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
EOM
cat <<EOM >> /etc/php-fpm.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm.sock
EOM
systemctl enable php-fpm.service
systemctl start php-fpm.service
echo "---- Installing firewall ----"
yum -y install firewalld
systemctl enable firewalld.service
systemctl start firewalld.service
echo "---- Setting up firewall ----"
#firewall-cmd --zone=public --change-interface=eth0
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
echo "---- Installing PrestaShop ----"
mkdir /var/www
cd /var/www || exit
PS_FILE="prestashop_$PS_VERSON.zip"
wget "https://download.prestashop.com/download/releases/$PS_FILE"
unzip -q $PS_FILE
rm -f $PS_FILE
rm -f ./Install_PrestaShop.html
chown -R nginx:nginx ./prestashop
chmod -R 0755 ./prestashop
echo "============================"
echo " WRITE THESE DOWN SOMEWHERE "
echo "----------------------------"
echo "Hostname: $PS_HOSTNAME"
echo "Database name: $DATABASE_NAME"
echo "Database password: $DATABASE_PASS"
echo "============================"
echo "Navigate to 'http://host_or_ip/install' and complete installation"
PS_OPTION=2
fi
if [ "$PS_OPTION" = "2" ]; then
if prompt_confirm "Remove installation folder?"
then
rm -rf ./prestashop/install
fi
if prompt_confirm "Enable SEO friendly URLs?"
then
if [ "${#DATABASE_NAME}" -ge "1" ]; then
read -r -p "Database name: " DATABASE_NAME
fi
if [ "${#DATABASE_PASS}" -ge "1" ]; then
read -r -p "Database password: " DATABASE_PASS
fi
mysql -u root -p"$DATABASE_PASS" -e "UPDATE $DATABASE_NAME.ps_configuration SET value = '1' WHERE name = 'PS_REWRITING_SETTINGS'"
fi
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment