This article will help all of us to automatically install, configure Nginx with PHP-FPM, configure virtual host and will rpovide us choose one of MySQL or PostgreSQL databases.
We have two server. CentOS7 and FreeBSD10.
GIT repository for codes. To download codes from GIT repository you must be install GIT and use the following command:
# git clone https://github.com/jamalshahverdiev/nginx-phphpm-mysql-postgresql.git
To install and configure Python2.7 or Python3.4 in laptop or in server we can use this script.
./ngphfpmypg.py script require input from console for IP, login, pass, virtual host name, db name, db user and for db pass.
If entered Virtual Host is exists on server script will provide new script with name ./add-vhost-ngphfpmypg.py for add virtual host.
Scripts working on CentOS7 and FreeBSD10 servers. I am doing tests for each of servers.
Lets start install and configure Nginx with MySQL and PHP-FPM for each of servers:
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>linux.com</strong></span>
This is CentOS server...
Please be patient, installing nginx server...
Nginx server installed and configured...
1. If you want install and configure MySQL with PHP-FPM write 1 and press "Enter"!!!
2. If you want install and configure PostgreSQL with PHP-FPM write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>1</strong></span>
You have selected "Enter" button!!!
Please be patient, it will take some time...
SQL service already running...
Enter name for new database: <span style="color: #0000ff"><strong>linuxdb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>linuxuser</strong></span>
Enter pass for linuxuser:
Repeat pass for linuxuser:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
The password set successfully!
MySQL, Nginx and PHP-FPM installed and configured...
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>linux.com</strong></span>
This is FreeBSD server...
Please be patient, installing nginx server...
Nginx server installed and configured...
1. If you want install and configure MySQL with PHP-FPM write 1 and press "Enter"!!!
2. If you want install and configure PostgreSQL with PHP-FPM write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>1</strong></span>
You have chose MySQL with PHP-FPM!
Please be patient, it will take some time...
SQL service already running...
Enter name for new database: <span style="color: #0000ff"><strong>linuxdb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>linuxuser</strong></span>
Enter pass for linuxuser:
Repeat pass for linuxuser:
MySQL, Nginx and PHP-FPM installed and configured...
Now I will install and configure Nginx with php-fpm and PostgreSQL for each of sevrers:
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>linux.com</strong></span>
This is CentOS server...
Please be patient, installing nginx server...
Nginx server installed and configured...
1. If you want install and configure MySQL with PHP-FPM write 1 and press "Enter"!!!
2. If you want install and configure PostgreSQL with PHP-FPM write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>2</strong></span>
You have chose PostgreSQL with PHP-FPM!
Please be patient, it will take some time...
SQL service already running...
Enter name for new database: <span style="color: #0000ff"><strong>linuxdb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>linuxuser</strong></span>
Enter pass for linuxuser:
Repeat pass for linuxuser:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
The password set successfully!
PostgreSQL, Nginx and PHP-FPM installed and configured...
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>linux.com</strong></span>
This is FreeBSD server...
Please be patient, installing nginx server...
Nginx server installed and configured...
1. If you want install and configure MySQL with PHP-FPM write 1 and press "Enter"!!!
2. If you want install and configure PostgreSQL with PHP-FPM write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>2</strong></span>
You have chose PostgreSQL with PHP-FPM!
Please be patient, it will take some time...
SQL service already running...
Enter name for new database: <span style="color: #0000ff"><strong>linuxdb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>linuxuser</strong></span>
Enter pass for linuxuser:
Repeat pass for linuxuser:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
The password set successfully!
PostgreSQL, Nginx and PHP-FPM installed and configured...
Try to add existing virtual host for each of servers:
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>linux.com</strong></span>
This is CentOS server...
You have already installed and running Nginx web server...
If you want add new VirtualHost, please use <strong>./add-vhost-ngphfpmypg.py</strong> script.
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>linux.com</strong></span>
This is FreeBSD server...
You have already installed and running Nginx web server...
If you want add new VirtualHost, please use <strong>./add-vhost-ngphfpmypg.py</strong> script.
Try to add new virtual host and not install any of database:
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>linux.com</strong></span>
This is CentOS server...
Please be patient, installing nginx server...
Nginx server installed and configured...
1. If you want install and configure MySQL with PHP-FPM write 1 and press "Enter"!!!
2. If you want install and configure PostgreSQL with PHP-FPM write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select:
You pressed "Enter" button, exiting!!!
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>linux.com</strong></span>
This is FreeBSD server...
Please be patient, installing nginx server...
Nginx server installed and configured...
1. If you want install and configure MySQL with PHP-FPM write 1 and press "Enter"!!!
2. If you want install and configure PostgreSQL with PHP-FPM write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select:
You pressed "Enter" button, exiting!!!
Now I will use ./add-vhost-ngphfpmypg.py script for each of server to add new virtual host.
Try to add existing virtual host name:
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>linux.com</strong></span>
This is CentOS server...
Entered domain name linux.com is already exists on the 172.16.100.20 server!!!
Please enter different name than "linux.com" !!!
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>linux.com</strong></span>
This is FreeBSD server...
Entered domain name linux.com is already exists on the 172.16.100.40 server!!!
Please enter different name than "linux.com" !!!
Try to add new virtual host with not configured MySQL database:
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: <strong>unixmen.com</strong>
This is CentOS server...
You have already running Nginx web server...
Virtual host unixmen.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>1</strong></span>
You have chose MySQL with PHP-FPM!
Please check SQL service!!!
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 FreeBSD server...
You have already running Nginx web server...
Virtual host unixmen.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>1</strong></span>
You have chose MySQL with PHP-FPM!
Please check SQL service!!!
Try to add new virtual host with already configured PostgreSQL database:
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 CentOS server...
You have already running Nginx web server...
Virtual host linuxmen.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>2</strong></span>
You have chose PostgreSQL with PHP-FPM!
You have already running PostgreSQL database server...
Enter name for new database: <span style="color: #0000ff"><strong>linuxmendb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>linuxmenuser</strong></span>
Enter pass for linuxmenuser:
Repeat pass for linuxmenuser:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
The password set successfully!
PostgreSQL database and Nginx configured for your site: linuxmen.com
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 FreeBSD server...
You have already running Nginx web server...
Virtual host linuxmen.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>2</strong></span>
You have chose PostgreSQL with PHP-FPM!
You have already running PostgreSQL database server...
Enter name for new database: <span style="color: #0000ff"><strong>linuxmendb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>linuxmenuser</strong></span>
Enter pass for linuxmenuser:
Repeat pass for linuxmenuser:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
The password set successfully!
PostgreSQL database and Nginx configured for your site: <strong>linuxmen.com</strong>
Try to add new virtual host with not configured PostgreSQL database:
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>freebsd.com</strong></span>
This is CentOS server...
You have already running Nginx web server...
Virtual host freebsd.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>2</strong></span>
You have chose PostgreSQL with PHP-FPM!
Please check SQL service!!!
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>freebsd.com</strong></span>
This is CentOS server...
You have already running Nginx web server...
Virtual host freebsd.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>2</strong></span>
You have chose PostgreSQL with PHP-FPM!
Please check SQL service!!!
At the end, try to add new virtual host with already configured MySQL database:
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 CentOS server...
You have already running Nginx web server...
Virtual host unixmen.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>1</strong></span>
You have chose MySQL with PHP-FPM!
You have already running MySQL database server...
Enter name for new database: <span style="color: #0000ff"><strong>unixmendb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>unixmenuser</strong></span>
Enter pass for unixmenuser:
Repeat pass for unixmenuser:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
The password set successfully!
MySQL database and Nginx configured for your site: unixmen.com
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 FreeBSD server...
You have already running Nginx web server...
Virtual host unixmen.com already configured...
1. To add MySQL database for this virtual host write 1 and press "Enter"!!!
2. To add PostgreSQL database for this virtual host write 2 and press "Enter"!!!
3. If you want to exit from script just press "Enter" button.
Please select: <span style="color: #0000ff"><strong>1</strong></span>
You have chose MySQL with PHP-FPM!
You have already running MySQL database server...
Enter name for new database: <span style="color: #0000ff"><strong>unixmendb</strong></span>
Enter user name for database: <span style="color: #0000ff"><strong>unixmenuser</strong></span>
Enter pass for unixmenuser:
Repeat pass for unixmenuser:
Entered passwords must be the same. Please enter passwords again.
Please enter password:
Please repeat password:
The password set successfully!
MySQL database and Nginx configured for your site: <strong>unixmen.com</strong>