Creating WordPress Site from Cli

Reading Time: 2 minutes
 

This page is under the assumption that you have installed:

root or sudo user
apache2
php5
mysql
php5-gd
libssh2-php

1. create new user

sudo adduser (username)

2. create website folder

sudo mkdir -p /var/www/(example.co.uk)/html/

3. change the home directory for the new user

sudo usermod -d /var/www/(example.co.uk)/html/ (username)

4. change ownership of the new directory to the new user

sudo chown -R (username):(username) /var/www/(example.co.uk)/html/

5. change permission to the html folder, so read access is available, this will allow pages and content to be seen

sudo chmod -R 755 /var/www/(example.co.uk)/html/

6. create a basic page as test, so you can check everything is working as expected

sudo nano /var/www/(example.co.uk)/html/index.php

Can use a simple php code

Simple Code
<?php
//* This is basic code so that i can check that everything is working as expected *//

echo “I am such a hero as this works XD ” ;

?>

7. create a virtual host for the website, by copying and renaming the default configuration file in apache

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/(exmaple.co.uk).conf

8. edit virtual host conf file

sudo nano /etc/apache2/sites-available/(example.co.uk).conf

The config file should look like this in the end:

ServerAdmin [email protected]
DocumentRoot /var/www/(example.co.uk)/html
ServerName (example.co.uk)
ServerAlias (example.co.uk)
<Directory /var/www/(example.co.uk)/html/>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

9. enable the virtual hosts

sudo a2ensite (example.co.uk).conf

You will get the message below:

Enabling site (example.co.uk).
To activate the new configuration, you need to run:
service apache2 reload

10. reload apache

sudo service apache2 restart

11. Test by browsering the web address
http://example.co.uk

You should see your php code if everything went as expected

Now thats the virtual host has been created we will need to create database for the wordpress site to use:

12. create a MYSQL Databse and User for the wordpress website

mysql -u root -p

You will be prompted for the MYSQL password that you had previously set, this will put you into the MYSQL

13. create the database

mysql> create database (database name);

14. create a user for the database

mysql> create user (database user)@localhost identified by '(password)';

15. link the database and user together

mysql> grant all privileges on (database).* to (database user)@localhost;

16. need to flush the current privileges, so that mysql can see the change in privileges

mysql> flush privileges;

17. all the mysql steps are done now, so can exit

mysql> exit

Database created, we can now install the wordpress files

18. ssh as user, (this is so that you don’t need to mess about with changing permission) and download the wordpress package

wget http://wordpress.org/latest.tar.gz

19. extract the files from .gz

tar xzvf latest.tar.gz

20. copy and move extracted files from the latest.tar.gz (which is extracted to the folder wordpress)

mv wordpress/* ..

This would move all the files up one directory level

21. copy and rename the wp-config-sample.php to wp-config.php

cp wp-config-sample.php wp-config.php

22. edit the wp-config.php with the MYSQL database details that had been created, this will link the database with the wordpress site

nano wp-config.php

You will need to look and change the following details only

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', '(database)');

/** MySQL database username */
define('DB_USER', '(database user)';

/** MySQL database password */
define('DB_PASSWORD', '(password)');

23. create a new folder for uploads of content (pictures, music files etc)

mkdir -p wp-content/uploads

24. create a .htacess file (this is so that you can have permlinks)

touch .htaccess

25. create the permissions on the .htaccess, do allow automatic rewrite of rules when editing via the wordpress control panel

chmod 664 .htaccess

26. browser to your domain name now and complete the wordpress installation via the control panel and you will be good to go 🙂
For more in-depth detail:

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
The following two tabs change content below.

Keeran Marquis

Network Engineer
Keeran Marquis is a Network Engineer. His main goal is to learn everything within the Networking field, pick up a little bit of scripting, be a poor man sysadmin and share whatever he knows! All Posts are his own views, opinions and experiences, no guarantees they will work for you but point you in the right direction 🙂
Share this:
Share

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.