Deploying Wordpress: Difference between revisions

From The Opensource Knowledgebase
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 25: Line 25:
Webserver is a container having an ip adress of 10.0.3.233 and is a private IP address. This container is not reachable from any machine except the host server (infrabase1). To be able to access the webserver from any machine on the network that is able to reach the host (infrabase1) server, two things have been done
Webserver is a container having an ip adress of 10.0.3.233 and is a private IP address. This container is not reachable from any machine except the host server (infrabase1). To be able to access the webserver from any machine on the network that is able to reach the host (infrabase1) server, two things have been done
* '''For ssh access''' from User PC (Details mentioned in Infobox on the right, top corner), iptables have been used on host server (infrabase1) for port forwarding. The rule ensures that any request on the host (infrabase1 server), on port number 61300 will be port forwarded to 10.0.3.233 on port number 22.
* '''For ssh access''' from User PC (Details mentioned in Infobox on the right, top corner), iptables have been used on host server (infrabase1) for port forwarding. The rule ensures that any request on the host (infrabase1 server), on port number 61300 will be port forwarded to 10.0.3.233 on port number 22.
: <code> sudo iptables -t nat -A PREROUTING -p tcp -i eno1 --dport 61300 -j DNAT --to-destination 10.0.3.233:22 </code>
<syntaxhighlight lang="apacheconf">
: <code> sudo iptables -t nat -A PREROUTING -p tcp -i eno1 --dport 61301 -j DNAT --to-destination 10.0.3.137:22 </code>
sudo iptables -t nat -A PREROUTING -p tcp -i eno1 --dport 61300 -j DNAT --to-destination 10.0.3.233:22
: <code> sudo iptables-save </code>
sudo iptables -t nat -A PREROUTING -p tcp -i eno1 --dport 61301 -j DNAT --to-destination 10.0.3.137:22
: <code> sudo service netfilter-persistent save </code>
sudo iptables-save
sudo service netfilter-persistent save
</syntaxhighlight>
If an error is observed while executing the last two commands, install the below two packages and execute the above commands again
If an error is observed while executing the last two commands, install the below two packages and execute the above commands again
: <code> sudo apt install netfilter-persistent iptables-persistent </code>
: <code> sudo apt install netfilter-persistent iptables-persistent </code>
Line 35: Line 37:
=Prep the webserver=
=Prep the webserver=
* Log into the webserver. In this case the host name of the webserver is apache.
* Log into the webserver. In this case the host name of the webserver is apache.
: <code> ssh kedar@10.0.3.233:61300 </code>
<syntaxhighlight lang="apacheconf">
: <code> sudo apt install apache2 php7.2 php7.2-curl php7.2-gd php7.2-intl php7.2-json php7.2-mbstring php7.2-mysql php7.2-soap php7.2-xml php7.2-zip libapache2-mod-php7.2 </code>
ssh kedar@10.0.3.233:61300
: <code> sudo apt install rsync nano openssl </code>
sudo apt install apache2 php7.2 php7.2-curl php7.2-gd php7.2-intl php7.2-json php7.2-mbstring php7.2-mysql php7.2-soap php7.2-xml php7.2-zip libapache2-mod-php7.2 rsync nano openssl
: <code> sudo systemctl status apache2 </code>
sudo systemctl status apache2
</syntaxhighlight>
=Database Creation=
=Database Creation=
Assuming mariadb database has been installed on the db server (hostname is db1) run the following commands
Assuming mariadb database has been installed on the db server (hostname is db1) run the following commands
Line 49: Line 52:
</syntaxhighlight>
</syntaxhighlight>
=Download Wordpress=
=Download Wordpress=
: <code> wget https://wordpress.org/latest.tar.gz </code>
<syntaxhighlight lang="apacheconf">
: <code> tar -zxvf latest.tar.gz <code>
wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
</syntaxhighlight>
=Deploy Wordpress=
=Deploy Wordpress=
* Create a folder in /var/www/html directory
* Create a folder in /var/www/html directory
Line 60: Line 65:
: <code> sudo chown -R www-data:www-data /data </code>
: <code> sudo chown -R www-data:www-data /data </code>
* Create virtual host for the website
* Create virtual host for the website
<code> cd /etC/apache2/sites-available </code>
<syntaxhighlight lang="apacheconf">
: <code> sudo a2dissite 000-default.conf </code>
cd /etC/apache2/sites-available
: <code> sudo cp 000-default.conf connect.conf </code>
sudo a2dissite 000-default.conf
: <code> sudo nano connect.conf </code>
sudo cp 000-default.conf connect.conf
: <syntaxhighlight lang="apacheconf">
sudo nano connect.conf
</syntaxhighlight>


Add the below configuration in the connect.conf file
<syntaxhighlight lang="apacheconf">
<VirtualHost connect.networked.com:80>
<VirtualHost connect.networked.com:80>
ServerAdmin admin@networked.com
ServerAdmin admin@networked.com
Line 76: Line 84:
</VirtualHost>
</VirtualHost>
</syntaxhighlight>
</syntaxhighlight>


=Important Plugins=
=Important Plugins=
=Conclusion=
=Conclusion=
[[Category: Intranet Applications]]
[[Category: Intranet Applications]]

Revision as of 07:14, 9 January 2020

Setup Details
Container hostname: apache
Network: 10.0.3.0/24
IP Address : 10.0.3.233
Subnet Mask: 255.255.255.0
Gateway: 10.0.3.1
DNS: 8.8.8.8

Container: Ubuntu 18.04
sudo user: kedar

User PC Details
PC type: Desktop
OS: Ubuntu Desktop
IP Address: 172.16.162.65
sudo user:kedar 

SSH into the webserver

Webserver is a container having an ip adress of 10.0.3.233 and is a private IP address. This container is not reachable from any machine except the host server (infrabase1). To be able to access the webserver from any machine on the network that is able to reach the host (infrabase1) server, two things have been done

  • For ssh access from User PC (Details mentioned in Infobox on the right, top corner), iptables have been used on host server (infrabase1) for port forwarding. The rule ensures that any request on the host (infrabase1 server), on port number 61300 will be port forwarded to 10.0.3.233 on port number 22.
sudo iptables -t nat -A PREROUTING -p tcp -i eno1 --dport 61300 -j DNAT --to-destination 10.0.3.233:22
sudo iptables -t nat -A PREROUTING -p tcp -i eno1 --dport 61301 -j DNAT --to-destination 10.0.3.137:22
sudo iptables-save
sudo service netfilter-persistent save

If an error is observed while executing the last two commands, install the below two packages and execute the above commands again

sudo apt install netfilter-persistent iptables-persistent

The second iptable rule is for port forwarding for the database server.

  • For http access - This is required because wordpress sites will be served on port 80 on the webserver container. Nginx web server has been installed on host server (inrabase1) and is configured as a reverse proxy. This ensures that any port 80 request that hits the infrabase1 server will be redirected to the webserver container ip. Since the webserver container is running an apache webserver, depending on the header and configured virtual hosts, apache on webserver container will serve the necessary website. Nginx configuration as a reverse proxy can be found here.

Prep the webserver

  • Log into the webserver. In this case the host name of the webserver is apache.
ssh kedar@10.0.3.233:61300
sudo apt install apache2 php7.2 php7.2-curl php7.2-gd php7.2-intl php7.2-json php7.2-mbstring php7.2-mysql php7.2-soap php7.2-xml php7.2-zip libapache2-mod-php7.2 rsync nano openssl
sudo systemctl status apache2

Database Creation

Assuming mariadb database has been installed on the db server (hostname is db1) run the following commands

sudo mysql -u root -p
CREATE DATABASE connect;
GRANT ALL PRIVILEGES ON connect.* TO "connect"@"%" IDENTIFIED BY "123456";
FLUSH PRIVILEGES;
quit;

Download Wordpress

wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz

Deploy Wordpress

  • Create a folder in /var/www/html directory
cd /var/www/html
sudo mkdir connect
  • Change the owner of the folder to be www-data
sudo chown -R www-data:www-data /data
  • Create virtual host for the website
cd /etC/apache2/sites-available
sudo a2dissite 000-default.conf
sudo cp 000-default.conf connect.conf
sudo nano connect.conf

Add the below configuration in the connect.conf file

<VirtualHost connect.networked.com:80>
	ServerAdmin		admin@networked.com
	ServerName		connect.networked.com
	ServerAlias		connect
    DocumentRoot            /var/www/html/connect/

	ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Important Plugins

Conclusion