0

Ok, so I'm building a webserver and MySQL server from scratch...

Server A is going to have Apache and PHP Server B is going to have MySQL Both servers are running Ubuntu 12.04 LTS server

I plan on letting my family and friends have their own accounts (like a REAL web host!) and have decided to attempt to script the account creation process. Now, I can do simple one liners in Linux or DOS batch script the heck out of what I want to do, but full blown shell scripts scare me.

So, here's what I have... Will it work without catastrophic meltdown???

REM Lets prompt for the user info...

echo -n "Please enter the new username: "
read user
echo -n "Enter the default password: "
read password
home=/var/www/$user

REM Create the user and assign the password

sudo useradd $user
net user $user $password

REM Create them an account on the MySQL server

database='$user'_db
mysql [mysql-server-hostname] -u root@[hostname] -p [pass] -e "create user '$user'@'%' identified by '$password';"
mysql [mysql-server-hostname] -u root@[hostname] -p [pass] -e "create database $database;"
mysql [mysql-server-hostname] -u root@[hostname] -p [pass] -e "grant all on '$database'.* to '$user'@%;"

REM Making some dirs

mkdir $home
mkdir $home/public_html
mkdir $home/public_ftp
usermod -m -d $home

REM Gotta let them have access

chown -R $user:$user $home
chmod 755 $home/public_html
chmod 755 $home/public_ftp

REM Add to some groups

useradd -G sftp $user
useradd -G ftp $user
useradd -G ssh $user

/etc/init.d/apache2 restart
4
  • I'm asking if it will work because I've written up the script while at work, will test tonight once I get home... just anxious and I know there's at least a million things I didn't do right Jul 5, 2013 at 19:11
  • 2
    bash is not batch: change REM to # (or, to be fancy, add REM() { :; } Jul 5, 2013 at 19:17
  • This question is much too localized in its current form. Questions should be helpful to a broader audience, but posting a full script that you haven't tested and asking others to fix or review it is not within the scope of Super User. Please test the script, and if you have specific issues getting some things to work, feel free to ask about that instead by editing your question. Thanks.
    – slhck
    Jul 5, 2013 at 19:48
  • You might want to post the question on codereview.stackexchange.com Jul 5, 2013 at 19:49

1 Answer 1

0

You're better off using an existing product. One that comes to mind is ISPConfig. I've used it in the past and has worked great. You can even provide a GUI to your end users to manage their portion of the server. You also have Quota restrictions on the number of domains and/or sites that can be hosted.

http://www.howtoforge.com/perfect-server-ubuntu-12.04-lts-apache2-bind-dovecot-ispconfig-3

http://www.ispconfig.org/

1
  • wow, ISPconfig is pretty awesome. A little different (I'm used to cPanel), especially with user management, but overall exactly what I was looking for! Thanks! Jul 8, 2013 at 13:19

Not the answer you're looking for? Browse other questions tagged .