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 # <span style="color: #0000ff"><strong>./apmyph.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.20</strong></span>
Please enter username for UNIX/Linux server: <strong><span style="color: #0000ff">root</span></strong>

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.

root@fweb:~ # <strong>pkg install -y vim bash</strong>
root@fweb:~ # <strong>echo "fdesc /dev/fd fdescfs rw 0 0" &gt;&gt; /etc/fstab</strong>
root@fweb:~ # <strong>mount -a</strong>
root@fweb:~ # <strong>chsh -s /usr/local/bin/bash root</strong>
root@fweb:~ # <strong>cp /usr/local/bin/bash /bin/bash</strong>

Same thing for FreeBSD server:

fpyvenv apngmysqlphpng # <strong><span style="color: #0000ff">./apmyph.py</span></strong>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.40</strong></span>
Please enter username for UNIX/Linux server: <strong>root</strong>
Password:
Please enter site name: <span style="color: #0000ff"><strong>unixmen.com</strong></span>
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: <strong><span style="color: #0000ff">unixmendb</span></strong>
Enter new mysql user name: <span style="color: #0000ff"><strong>unixmenuser</strong></span>
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 # <span style="color: #0000ff"><strong>./apmyph.py</strong></span>
Please enter WEB server IP address: 172.16.100.20
Please enter username for UNIX/Linux server: root
Password:
Please enter site name: <strong>unixmen.com</strong>
This is CentOS server...
You have already installed and running Apache web server...
If you want add new VirtualHost, please use <strong>./add-vhost-apmyph.py</strong> script.
fpyvenv apngmysqlphpng # <strong>./apmyph.py</strong>
Please enter WEB server IP address: <strong>172.16.100.40</strong>
Please enter username for UNIX/Linux server: <strong>root</strong>
Password:
Please enter site name: <strong>unixmen.com</strong>
This is FreeBSD server...
You have already installed and running Apache web server...
If you want add new VirtualHost, please use <strong>./add-vhost-apmyph.py</strong> 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 # <span style="color: #0000ff"><strong>./add-vhost-apmyph.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.20</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>unixmen.com</strong></span>
This is <strong>CentOS</strong> server...
Apache web server installed and working...
Entered domain name <strong>unixmen.com</strong> is already exists on the <strong>172.16.100.20</strong> server!!!
fpyvenv apngmysqlphpng # <span style="color: #0000ff"><strong>./add-vhost-apmyph.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.40</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>unixmen.com</strong></span>
This is <strong>FreeBSD</strong> server...
Apache web server installed and working...
Entered domain name <strong>unixmen.com</strong> is already exists on the <strong>172.16.100.40</strong> server!!!

Now I will try to add new virtual host for both servers:

fpyvenv apngmysqlphpng # <span style="color: #0000ff"><strong>./add-vhost-apmyph.py</strong></span>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.20</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>linuxmen.com</strong></span>
This is <strong>CentOS</strong> 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: <span style="color: #0000ff"><strong>linuxmendb</strong></span>
Enter new mysql user name: <span style="color: #0000ff"><strong>linuxmenuser</strong></span>
Enter pass for linuxmenuser:
Repeat pass for linuxmenuser:
MySQL database for linuxmen.com already configured...
fpyvenv apngmysqlphpng # <strong><span style="color: #0000ff">./add-vhost-apmyph.py</span></strong>
Please enter WEB server IP address: <span style="color: #0000ff"><strong>172.16.100.40</strong></span>
Please enter username for UNIX/Linux server: <span style="color: #0000ff"><strong>root</strong></span>
Password:
Please enter site name: <span style="color: #0000ff"><strong>linuxmen.com</strong></span>
This is <strong>FreeBSD</strong> 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: <span style="color: #0000ff"><strong>linuxmendb</strong></span>
Enter new mysql user name: <span style="color: #0000ff"><strong>linuxmenuser</strong></span>
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.