Automated Apache PHP and MySQL for FreeBSD and CentOS7 servers

This script will automatically check OS type and version. If OS version is CentOS7 script will continue works for CentOS7 or if OS version FreeBSD10 script will continue works for FreeBSD.

We have admin laptop with installed Python2.7 and Python3.4 with needed libraries. And we have two servers for tests. One of servers is CentOS7 and other is FreeBSD10.

First of all we must clone scripts to the local folder and change folder to downloaded. But if git client is not exists you cannot to do this.

For that we ill install git to our machine:
fpyvenv ~ # apt-get install git
or
fpyvenv ~ # yum -y install git

fpyvenv ~ # git clone https://github.com/jamalshahverdiev/freebsd-centos7-amp.git
fpyvenv ~ # cd freebsd-centos7-amp/

But before check this script you must install and configure python2.7 or Python3.4 with libraries to the admin server or admin laptop. For that I wrote one bash script which automatically install Python’s and libraries to your server.

If your server is fresh and you are using this script first time, then it will install Apache24 MySQL and PHP with extensions to your server automatically. If you want to add new Virtual Host to already configured web server by this script, then you must use the add-vhost-apmyph.py file. Second script will check FQDN entered by you and if this domain is exists on the server, script will prompt to you information about this.

Lets check scripts….
Firstly I will try to install new server for CentOS7 and for FreeBSD10. The hostname’s for server is cweb for CentOS7 and fweb for FreeBSD10.

Before execute this script we must do chmod +x scriptname:
fpyvenv apngmysqlphpng # ./apmyph.py
Please enter WEB server IP address: 172.16.100.20
Please enter username for UNIX/Linux server: root

Enter root password for your server two times:
Password:

Enter FQDN which you want to configure:
Please enter site name: unixmen.com

As we see script already detected our server type:
This is CentOS server…
Apache 24 server installed and configured…
If you want install and configure MySQL PHP just press “Enter”!!!
If you want to exit from script write “n” and press Enter button.

Here I have entered “Enter” button:
Please select:
You are selected “Enter” button
MySQL service already running…

I entered dbname, login and pass for PHP site:
Enter name for new database: unixmendb
Enter new mysql user name: unixmenuser
Enter pass for unixmenuser:
Repeat pass for unixmenuser:
MySQL, Apache24 and PHP installed and configured…

Note: For FreeBSD servers we have needs bash shell environment because, Fabric library needs this.  Change SHELL environment to bash and copy bash binary file to the /bin/bash. If you want beautiful features in bash then, download from this link all bash needed files to the root user home folder. For that use the following commands.


[email protected]:~ # pkg install -y vim bash
[email protected]:~ # echo "fdesc /dev/fd fdescfs rw 0 0" >> /etc/fstab
[email protected]:~ # mount -a
[email protected]:~ # chsh -s /usr/local/bin/bash root
[email protected]:~ # cp /usr/local/bin/bash /bin/bash

Same thing for FreeBSD server:
fpyvenv apngmysqlphpng # ./apmyph.py
Please enter WEB server IP address: 172.16.100.40
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: unixmen.com
This is FreeBSD server...
Apache 24 server installed and configured...
If you want install and configure MySQL PHP just press "Enter"!!!
If you want to exit from script write "n" and press Enter button.
Please select:
You are selected "Enter" button
MySQL service already running...
Enter name for new database: unixmendb
Enter new mysql user name: unixmenuser
Enter pass for unixmenuser:
Repeat pass for unixmenuser:
MySQL, Apache24 and PHP installed and configured...

Now I will try to add new virtual host to existing server(I will do the same thing for both servers).
As we can see I have tried add existing domain for both servers with apmyph.py script. The our script told me you must use python-add-virtualhost.py script for add new virtual host:
fpyvenv apngmysqlphpng # ./apmyph.py
Please enter WEB server IP address: 172.16.100.20
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: unixmen.com
This is CentOS server...
You have already installed and running Apache web server...
If you want add new VirtualHost, please use ./add-vhost-apmyph.py script.

fpyvenv apngmysqlphpng # ./apmyph.py
Please enter WEB server IP address: 172.16.100.40
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: unixmen.com
This is FreeBSD server...
You have already installed and running Apache web server...
If you want add new VirtualHost, please use ./add-vhost-apmyph.py script.

If you will try to add existing virtual host with add-vhost-apmyph.py script, the answer for both servers will be follows:
fpyvenv apngmysqlphpng # ./add-vhost-apmyph.py
Please enter WEB server IP address: 172.16.100.20
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: unixmen.com
This is CentOS server...
Apache web server installed and working...
Entered domain name unixmen.com is already exists on the 172.16.100.20 server!!!

fpyvenv apngmysqlphpng # ./add-vhost-apmyph.py
Please enter WEB server IP address: 172.16.100.40
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: unixmen.com
This is FreeBSD server...
Apache web server installed and working...
Entered domain name unixmen.com is already exists on the 172.16.100.40 server!!!

Now I will try to add new virtual host for both servers:
fpyvenv apngmysqlphpng # ./add-vhost-apmyph.py
Please enter WEB server IP address: 172.16.100.20
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: linuxmen.com
This is CentOS server...
Apache web server installed and working...
Virtualhost linuxmen.com already configured...
If you want to configure database for linuxmen.com virtualhost just press "Enter"!!!
If you want to exit from script write "n" and press Enter button.
Please select:
You are selected "Enter" button
MySQL service already configured and running...
Enter name for new database: linuxmendb
Enter new mysql user name: linuxmenuser
Enter pass for linuxmenuser:
Repeat pass for linuxmenuser:
MySQL database for linuxmen.com already configured...

fpyvenv apngmysqlphpng # ./add-vhost-apmyph.py
Please enter WEB server IP address: 172.16.100.40
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: linuxmen.com
This is FreeBSD server...
Apache web server installed and working...
Virtualhost linuxmen.com already configured...
If you want to configure database for linuxmen.com virtualhost just press "Enter"!!!
If you want to exit from script write "n" and press Enter button.
Please select:
You are selected "Enter" button
MySQL service already running...
Enter name for new database: linuxmendb
Enter new mysql user name: linuxmenuser
Enter pass for linuxmenuser:
Repeat pass for linuxmenuser:
MySQL database for linuxmen.com already configured...

In the future I am planning to do the same thing for Nginx PHP-FPM and MySQL for CentOS7 and FreeBSD.