I recently came across a project that taught me how to create a sub-domain and install wordpress on the sub-domain. It was a great experience where I had to do some research because it was something I was learning for the first time.
At this time all I had was an objective which was creating a sub-domain for the client and the rest was up to just doing research and delivering the work based on the objective.
Before we begin with there are a couple of assumptions I am making in this article
1. Your using Digital Ocean as your VPS Service provider
2. Your having Apache Server Running
Login in your digital ocean account and directly go to your domain name as shown below and on your right hand side you will see three dots as shown in the below image.
Click on the 3 dots and a drop down menu will appear, and just select the manage domain.
Once you have selected the manage domain tab you will be redirected to the create a new record page. Here is where we fill the information of your sub-domain your trying to create. In number 1 you write the name of your liking for your sub-domain, number 2 you select the server that you want your sub-domain name to run in and finally number 3 you create the record and your done for this step.
After setting up everything in Digital Ocean the next step is to login to your server via ssh and make the following configurations in your server. Once you have logged in you go to the web directory which is /var/www/ and create a directory for your sub-domain where in my case I named it testing and then change the permissions to user www-data or it could be your user is called $USER depending on how you had setup your user is the permission your going to give that username.
Next I had to create an index.html file inside the directory I had created called testing.
Here just add the below html codes and save the file, if you want you could edit them according to your liking.
Then just for verification purpose I had to check whether the index.html file was successfully created.
Next is to go to the server configuration file’s and create a new configuration file for the sub-domain. I change directory to /etc/apache2/sites-available/ and copied the default configuration file 000-default.conf and created a new one which I named it after the name of my sub-directory which in our case is testing and always remember to add .conf at the end of your file name.
After successfully copying and renaming the file I had open the file using nano text editor and made changes in the following places
- Document root – change the path to you sub-domain path
- ServerName – provide your sub-domain url (testing.com)
- ServerALias – provide your sub-domain url (www.testing.com)
- Redirect Permanent – delete this section in your sub-domain configurations file, if you don’t it would be redirecting to the url you provided every time you try to load the home page
Once that’s done go to your web browser and type in your sub-domain name, and if everything went well then you will see your message that you had created in your index.html file in the web directory.
Next I went to the directory which I created in the web root which was testing and downloaded wordpress in there, unzipped the downloaded file and got all the wordpress files and directory.
After that I went and created a new database for the sub-domain and this is how I did it.
Am assuming you logged in using the root account, if so when you just type in the command Mysql you will be logged in the database automatically. Here is where the important part is.
Once the database setup was done I went to the browser, in the url I typed in sitename/wp-admin and now is when you start to configure the wordpress and installing it.