Create WordPress Databases And Users
Now if you setup LEMP properly, Now we need to create databases for as many sites we have we take the example of two websites. If you have more then two you can create more than 2 databases.
Run the commands below to sign onto MySQL server using the password previous tutorial.
$ sudo mysql -u root -pThen run the commands below to create a new database called arohamwp1 and arohamwp2 for WordPress site #1 & #2
mysql > CREATE DATABASE arohamwp1; mysql > CREATE DATABASE arohamwp2;Next, we need to create new database users called “arohamdb” and grant him access to both database, you can create different user as well
//Create User mysql > CREATE USER 'arohamdb'@'localhost' IDENTIFIED BY '__PASSWORD__'; //Grant Access mysql > GRANT ALL PRIVILEGES ON arohamwp1.* TO 'arohamdb'@'localhost'; mysql > GRANT ALL PRIVILEGES ON arohamwp2.* TO 'arohamdb'@'localhost'; //Flush Privileges & exit mysql > FLUSH PRIVILEGES; mysql > exit;
Create server blocks as many required
Server blocks are just individual site configuration file. Each site will have its own server block file. So the trick is to copy the default server block config and create as many required. So, let’s create two WordPress websites called arohamexample.com and arohamexample.in from the default config file by running the commands below.
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/arohamexample.com sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/arohamexample.inAfter creating the server blocks or site configuration files, open each file and make the highlighted file to match each domain.
sudo nano /etc/nginx/sites-available/arohamexample.comMake below changes and save.
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html/arohamexample.com; index index.php index.html index.htm index.nginx-debian.html; server_name arohamexample.com www.arohamexample.com; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }Do the same for arohamexample.in and replace all arohamexample.com references with arohamexample.in and save the file. Run the commands below to edit arohamexample.in file.
sudo nano /etc/nginx/sites-available/arohamexample.inThen change arohamexample.com references with arohamexample.in and save. When you’re done, run the commands below to enable both server blocks and delete the default configuration.
sudo ln -s /etc/nginx/sites-available/arohamexample.com /etc/nginx/sites-enabled/ sudo ln -s /etc/nginx/sites-available/arohamexample.in /etc/nginx/sites-enabled/ sudo rm /etc/nginx/sites-available/default
Create Multiple DocRoot
In each of the server block, there’s a root location. This is where each website content should be stored and that need to be different for all websites. Now we need to defined the root locations for all our site, go and create them below.
sudo mkdir -p /var/www/html/arohamexample.com sudo mkdir -p /var/www/html/arohamexample.in
Setup WordPress
Now download WordPress extract into the root directory for each site. To do that run the commands below
cd /tmp/ && wget http://wordpress.org/latest.tar.gz //extract the downloaded file. tar -xzvf latest.tar.gz //Copy to each root folder for each site sudo cp -R wordpress/* /var/www/html/arohamexample.com sudo cp -R wordpress/* /var/www/html/arohamexample.inNext, we need to change the directory permissions so WordPress can function properly.
sudo chown -R www-data:www-data /var/www/html sudo chmod -R 755 /var/www/htmlNext, just restart Nginx web server
sudo nginx -t sudo systemctl restart nginxAfter restarting Nginx with no errors, you should be able to access your sites through domain names and see WordPress default setup page.