Script: Install Joomla 3.7 on a CentOS/Fedora VPS

 

 

In one of our previous posts, we explained how to install Joomla 3 on Ubuntu 14.04. Joomla is a Content Management System (CMS for short) – this is user-friendly software that allows you to build websites and manage the content on your websites easier than ever before.

In this tutorial, unlike the previous Joomla install guide, we wrote a script for you to help make the installation of Joomla 3.7 on a CentOS/Fedora VPS even faster and easier. This script will automatically do everything that should be done on your server, including the creation of a MySQL database while also creating an Apache virtual host for your Joomla website. All you need to do is to create a file on your server containing the script below, then simply execute the script and enter your details when prompted to.

(Note: You will need to have MySQL and Apache installed on your server in order for this script to work correctly.)

Create a file on your server with your favorite text editor and copy this script into your file:

#!/bin/bash
# Install Joomla on a CentoOS/Fedora VPS
#

# Create MySQL database
read -p "Enter your MySQL root password: " rootpass
read -p "Database name: " dbname
read -p "Database username: " dbuser
read -p "Enter a password for user $dbuser: " userpass
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE $dbname;
delete from mysql.user
where user='$dbuser'
and host = 'localhost';
flush privileges;
CREATE USER $dbuser@localhost;
GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost IDENTIFIED BY '$userpass';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "New MySQL database has been successfully created"
sleep 2

# Download, unpack and configure Joomla
read -r -p "Enter your Joomla URL? [e.g. mydomain.com]: " joomlaurl
mkdir -p /var/www/html/$joomlaurl && 
wget -P /var/www/html/$joomlaurl 
https://downloads.joomla.org/cms/joomla3/3-7-2/Joomla_3-7.2-Stable-Full_Package.zip && 
cd /var/www/html/$joomlaurl
echo "Installing unzip package if necessary..." && yum -yq install unzip
sleep 3
unzip Joomla*.zip && rm -f Joomla_*.zip && 
chown apache: -R /var/www/html/$joomlaurl
killall httpd

# Create the Apache virtual host
echo "

<VirtualHost $(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'):80>
 ServerName www.$joomlaurl
 DocumentRoot "/var/www/html/$joomlaurl"
 DirectoryIndex index.php
 Options FollowSymLinks
 ErrorLog logs/$joomlaurl-error_log
 CustomLog logs/$joomlaurl-access_log common
</VirtualHost>

" >> /etc/httpd/conf/httpd.conf
service httpd restart

echo -en "aPlease go to http://www.$joomlaurl and finish the installationn"

#End of script

Make the script executable, then execute the script:

chmod +x <script name> && ./<script name>

(Replace <script name> with the name that you have given to your file)

After running the script, you will have successfully installed Joomla 3.7 on your CentOS or Fedora VPS! All that is left to do is to set up the remainder of Joomla at your web domain.

Source