Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #For Centos 7
- #chmod +x script
- #./script
- #Testat si verificat pe CentOS 7.3.1611
- if [ "$(id -u)" != "0" ];
- then
- printf "Sorry, sudo required.\n"
- exit
- fi
- public_ip=`curl -s http://icanhazip.com`
- private_ip=`ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'`
- height=15
- width=40
- choice_height=4
- backtitle="LAMP+WORDPRESS INSTALL"
- title="LAMP+WORDPRESS INSTALL"
- menu="Choose one of the following options:"
- OPTIONS=(1 "Install&configure LAMP"
- 2 "Set HOSTS"
- 3 "Set VirtualHosts"
- 4 "Install&configure Wordpress")
- choice=$(dialog --clear \
- --backtitle "$backtitle" \
- --title "$title" \
- --menu "$menu" \
- $height $width $choice_height \
- "${OPTIONS[@]}" \
- 2>&1 >/dev/tty)
- clear
- case $choice in
- 1)
- clear
- yes | yum install httpd
- systemctl enable httpd
- systemctl start httpd
- yes | yum install mariadb-server mariadb
- systemctl start mariadb
- systemctl enable mariadb
- printf "Set root password if you have one and enter yes all time\n"
- mysql_secure_installation
- yes | yum install php php-mysql php-fpm
- systemctl restart httpd
- if cat /etc/redhat-release | grep -q "CentOS Linux release 7." && rpm -q firewalld > /dev/null;
- then
- printf "Adding port 80:"
- firewall-cmd --permanent --zone=public --add-service=http
- printf "\nAdding port 443:"
- firewall-cmd --permanent --zone=public --add-service=https
- printf "\nReloading firewalld:"
- firewall-cmd --reload
- printf "\n"
- fi
- touch /var/www/html/info.php
- printf "<?php echo "succes"; ?>" > /var/www/html/info.php
- printf "Checking /var/www/html/info.php\n"
- tmp_ip=$public_ip
- tmp_ip+="/"
- tmp_ip+="info.php"
- site=$(curl -s $tmp_ip)
- if [[ $site = "succes" ]] > /dev/null;
- then
- printf "php has been verified&instaled!\n"
- else
- printf "error verifying php ( $site)\n"
- fi
- rm /var/www/html/info.php
- ;;
- 2)
- clear
- printf "Set custom hosts?(y/n)\n"
- read -e hostss
- if [ "$hostss" == y ] ;
- then
- printf "[custom host]enter ip: "
- read -e ip
- printf "[custom host]enter host: "
- read -e host
- printf "$ip $host" >> /etc/hosts
- printf "$ip $host added on /etc/hosts\n"
- fi
- ;;
- 3)
- clear
- printf "Set virtual host domain?(y/n)"
- read -e virtual
- if [ "$virtual" == y ] ;
- then
- printf "Enter the name of virtual domain: "
- read -e domain
- mkdir -p /var/www/$domain/public_html
- chown -R $USER:$USER /var/www/$domain/public_html
- chmod -R 755 /var/www
- printf "<html>
- <head>
- <title>Welcome to $domain!</title>
- </head>
- <body>
- <h1>Success! The $domain virtual host is working!</h1>
- <h1>Public ip: $public_ip</h1>
- <h1>Private ip: $private_ip</h1>
- </body>
- </html>" > /var/www/$domain/public_html/index.html
- mkdir -p /etc/httpd/sites-available
- mkdir -p /etc/httpd/sites-enabled
- if ! grep -q "IncludeOptional sites-enabled/*.conf" /etc/httpd/conf/httpd.conf;
- then
- printf "IncludeOptional sites-enabled/*.conf" >> /etc/httpd/conf/httpd.conf
- fi
- printf "<VirtualHost *:80>
- ServerName www.$domain
- ServerAlias $domain
- DocumentRoot /var/www/$domain/public_html
- ErrorLog /var/www/$domain/error.log
- CustomLog /var/www/$domain/requests.log combined
- </VirtualHost>" > /etc/httpd/sites-available/$domain.conf
- sudo ln -s /etc/httpd/sites-available/$domain.conf /etc/httpd/sites-enabled/$domain.conf
- printf "$private_ip $domain\n" >> /etc/hosts
- printf "Done $domain\n"
- fi
- ;;
- 4)
- clear
- printf "WordPress Install Script\n"
- printf "Create database, user, password for wordpress? (y/n)\n"
- read -e sql
- if [ "$sql" == y ] ;
- then
- printf "Creating database:\n"
- printf "ENTER ROOT PASSWORD: "
- read -s root_password
- printf "\nDatabase Name: "
- read -e db_name
- printf "\nDatabase User: "
- read -e db_user
- printf "\nDatabase Password: "
- read -s db_pass
- mysql -u root -p$root_password -e "
- CREATE DATABASE $db_name;
- CREATE USER '$db_user'@'localhost' IDENTIFIED BY '$db_pass';
- GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'localhost';
- FLUSH PRIVILEGES; "
- printf "MySQL info:\n"
- printf "DataBase Name: $db_name\n"
- printf "Username: $db_user\n"
- printf "Password: $db_pass\n"
- fi
- printf "Enter Wordpress Database:\n"
- printf "Database Name: "
- read -e dbname
- printf "Database User: "
- read -e dbuser
- printf "Database Password: "
- read -s dbpass
- curl -O https://wordpress.org/latest.tar.gz
- tar -zxvf latest.tar.gz
- mv wordpress wps
- cp -rf wps /var/www/html
- cp /var/www/html/wps/wp-config-sample.php /var/www/html/wps/wp-config.php
- perl -pi -e "s/database_name_here/$dbname/g" /var/www/html/wps/wp-config.php
- perl -pi -e "s/username_here/$dbuser/g" /var/www/html/wps/wp-config.php
- perl -pi -e "s/password_here/$dbpass/g" /var/www/html/wps/wp-config.php
- perl -i -pe'
- BEGIN {
- @chars = ("a" .. "z", "A" .. "Z", 0 .. 9);
- push @chars, split //, "!@#$%^&*()-_ []{}<>~\`+=,.;:/?|";
- sub salt { join "", map $chars[ rand @chars ], 1 .. 64 }
- }
- s/put your unique phrase here/salt()/ge
- ' /var/www/html/wps/wp-config.php
- mkdir /var/www/html/wps/wp-content/uploads
- chmod 775 /var/www/html/wps/wp-content/uploads
- rm latest.tar.gz
- rm -Rf wps
- printf "Wordpress Installation is complete.\n"
- if [ ! -f /usr/local/bin/wp ];
- then
- printf "Downloading & Installing WP-CLI\n"
- curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
- chmod +x wp-cli.phar
- sudo mv wp-cli.phar /usr/local/bin/wp
- printf "Done\n"
- fi
- printf "Site Title: "
- read -e site_title
- printf "Site Username: "
- read -e site_username
- printf "Site Email: "
- read -e site_email
- site_password=$(openssl rand -base64 12)
- pushd $PWD
- cd /var/www/html/wps
- /usr/local/bin/wp --allow-root core install --url=$public_ip/wps --title=$site_title --admin_user=$site_username --admin_email=$site_email --admin_password=$site_password
- printf "Complete: \nSite title: $site_title \nUsername: $site_username \nEmail: $site_email \nPasswd: $site_password \n To see ur website visit: ${public_ip}/wps"
- rm -f /usr/local/bin/wp
- ;;
- esac
Add Comment
Please, Sign In to add comment