What if you have installed Ubuntu Linux in your server or droplet, and now you bought a new domain and want to install WordPress in it. In that case, how can you add a new domain in your server? Most of the website owner use AWS, Digital ocean, vultr where they install Ubuntu.
Well, that is the reason I am here with the solution. I will give you some set of commands and instructions and after that, you can able to add a new domain to the Linux server easily.
Login to Server
Now it will ask for password
Note: Whatever you will write there, nothing will show there. So don’t panic.
After that, you have entered the right password you will get a screen like this below.
Now I will list down all the commands and you will have to enter those commands one by one. I will explain a little bit as well.
How to Add New Domain Name to Linux Server
sudo apt-get update
sudo apt-get install apache2
sudo mkdir -p /var/www/yourdomain.com/public_html
This commands creates a directory or folder in your server for your specific domain name.
sudo chmod -R 755 /var/www
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
sudo nano /etc/apache2/sites-available/example.com.conf
It will open a new file to edit on your screen just like the image below.
Now, Copy this below code and add it to below ServerAdmin webmaster@localhost
Make sure to change yourdomain.com to the domain that you have to add.
After that save by pressing Control + X at the same time. Press Enter and then Y
Now enter the command line below
sudo a2ensite example.com.conf
sudo service apache2 restart
Read our Previous article to know how to add wordpress installing file there.
Now create your wordpress database by going to phpmyadmin. Read previous article to know how to add database to phpmyadmin
CREATE USER ‘newuser’@’localhost’ IDENTIFIED BY ‘password’;
GRANT ALL PRIVILEGES ON * . * TO ‘newuser’@’localhost’;
sudo chown -R www-data /var/www/yourdomain.com/public_html
sudo certbot –apache -d example.com -d www.yourdomain.com
This will add a letsencrypt free SSL certificate. Before adding this command line make sure that you have your name servers pointing to hosting and add your domain to hosting as well to properly match DNS.
Now open your filezilla.
Enter IP in the hostname
username as root
enter password given by hosting or that you have chosen.
Now click on Quickconnect. You will see lot of files and folders are coming up. Just like the image below
On left Side it has local files means your own computer files from which you can upload.
On Right Side you have your server’s file where you can change and edit stuff.
Now headover to this directory like this /var/www/yourdomain.com/public_html/wordpress
select all the files from there.
Drag those files to the three dot (…) folder means back folder, here /var/www/yourdomain.com/public_html
Del that empty wordpress folder from there.
Come down find wp-config-sample.php right click on it, View it.
Select all the things from there and copy all the thing. Now, close it,
Create a new file there by clicking right click. Name that file wp-config.php exactly don’t change or add anything in file name.
Now open new file of wp-config.php and paste all the content there.
Now you will have to replace something here. See the above image and find database_name_here replace it to that database name, which you created with phpmyadmin.
username_here replace this with the username that you have made in above mysql command.
password_here replace this with the password which you made in mysql command as well.
After that Open your yourdomain.com and you will see a wordpress installation screen.
Select your Language and you are good at adding a new domain in Linux with ease.