Creating Wordpress Site from Cli
This page is under the assumption that you have installed:
root or sudo user
apache2
php5
mysql
php5-gd
libssh2-php
- Create new user
sudo adduser (username)
- Create website folder
sudo mkdir -p /var/www/(example.co.uk)/html/
- Change the home directory for the new user
sudo usermod -d /var/www/(example.co.uk)/html/ (username)
- Change ownership of the new directory to the new user
sudo chown -R (username):(username) /var/www/(example.co.uk)/html/
- 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/
- 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
echo "I am such a hero as this works XD " ;
- 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
- 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 webmaster@localhost
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
- 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
- Reload apache
sudo service apache2 restart
- Test by browsering the web address https://my_some_domain.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:
- 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
- Create the database
mysql> create database (database name);
- Create a user for the database
mysql> create user (database user)@localhost identified by '(password)';
- Link the database and user together
mysql> grant all privileges on (database).\* to (database user)@localhost;
- Need to flush the current privileges, so that mysql can see the change in privileges
mysql> flush privileges;
- All the mysql steps are done now, so can exit
mysql> exit
Database created, we can now install the wordpress files
- 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
- Extract the files from .gz
tar xzvf latest.tar.gz
- 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
- Copy and rename the wp-config-sample.php to wp-config.php
cp wp-config-sample.php wp-config.php
- 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)');
- Create a new folder for uploads of content (pictures, music files etc)
mkdir -p wp-content/uploads
- Create a .htacess file (this is so that you can have permlinks)
touch .htaccess
- Create the permissions on the .htaccess, do allow automatic rewrite of rules when editing via the wordpress control panel
chmod 664 .htaccess
- 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: