How to set up a Web server and install WordPress on a Raspberry Pi (Raspbian Jessie)

This installation is for Raspbian Jessie, for Raspbian Stretch go here

Update your repository

cd ~
sudo apt-get update

Get the network address of your Raspberry Pi

sudo ifconfig

Note the address in the inet addr field

inet addr:192.168.1.7

Install the apache2 web server

sudo apt-get install apache2 -y	

From your web browser test the apache2 installation using the network address of your Raspberry Pi

http://192.168.1.7

Install php

sudo apt-get install php5 libapache2-mod-php5 php5-mysql -y

Move to the /var/www/html directory

cd /var/www/html

Edit the index.php file

sudo nano index.php

Add a ‘hello world’ message

<?php echo "hello world"; ?>

Save changes and exit the file

press control x
press y
press return 

Remove the index.html file

sudo rm index.html

Restart the apache2 service

sudo service apache2 restart

From your web browser test the php installation using the network address of your Raspberry Pi

http://192.168.1.7

Move to your home directory

cd ~

Install MySQL

sudo apt-get install mysql-server mysql-client -y

When prompted, create a MySQL password

MysqlPassword

Run MySQL Secure Installation

sudo /usr/bin/mysql_secure_installation

Provide your MySQL password

MysqlPassword

Provide the requested parameters

Change root password = n
Remove anonymous users = y
Disallow root login remotely = y
Remove test database and access to it = y
Reload privilege tables now = y

Download WordPress

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

Extract the download

tar -xzvf latest.tar.gz

Move WordPress to the /var/www/html directory

sudo mv wordpress/* /var/www/html

Remove the WordPress download file and remove WordPress from your home directory

sudo rm latest.tar.gz
sudo rm -rf wordpress

Login to MySQL

mysql -uroot -hlocalhost -p

Provide your MySQL password

MysqlPassword

Create a database for WordPress

CREATE DATABASE wordpressDB;

Create a WordPress database user and assign a password to that user

CREATE USER 'morituri'@'localhost' IDENTIFIED BY 'UsersPassword';

Grant privileges to the WordPress database for the WordPress user

GRANT ALL PRIVILEGES ON wordpressDB.* TO 'morituri'@'localhost';

Flush privileges

FLUSH PRIVILEGES;

Close MySQL

exit

Move to the /var/www/html directory

cd /var/www/html

Copy the wp-config-sample.php file to wp-config.php

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

Edit the wp-config.php file

sudo nano wp-config.php

Define the DB_NAME, DB_USER and DB_PASSWORD parameters with your MySQL settings where indicated

wordpressDB
morituri
UsersPassword

Save changes and exit the config file

press control x
press y
press return 

Change the WordPress directory owner to pi

sudo chown -R pi:pi /var/www/html

Create a WordPress uploads directory

sudo mkdir /var/www/html/wp-content/uploads

Change the uploads directory owner to apache2

sudo chown -R www-data:www-data /var/www/html/wp-content/uploads

Edit the apache2 virtual hosts file

sudo nano /etc/apache2/sites-available/000-default.conf

Add AllowOverride All for the /var/www/html directory

<Directory /var/www/html/>					
    AllowOverride All
</Directory>

Save changes and exit the config file

press control x
press y
press return 

Restart the apache2 service

sudo service apache2 restart

Create a .htaccess file

sudo touch /var/www/html/.htaccess

Change the owner to apache2

sudo chown :www-data /var/www/html/.htaccess

Change the permissions for the WordPress directories and the WordPress files

sudo find /var/www/html/ -type d -exec chmod 755 {} \;
sudo find /var/www/html/ -type f -exec chmod 644 {} \;

Move to your home directory

cd ~

Install vsftp

sudo apt-get install vsftpd -y

Edit the vsftp config file

sudo nano /etc/vsftpd.conf

Ensure that both local_enable and write_enable do not have a # at the start of the line and that they are set to yes

local_enable=YES
write_enable=YES

Save changes and exit the config file

press control x
press y
press return 

Restart the vsftp service

sudo service vsftpd restart

From your web browser test the WordPress installation using your Raspberry Pi network address

http://192.168.1.7

Provide a Title for your web site, create both a login Username and a login Password and provide an email address

your web site title
LoginUsername
LoginPassword
email@somewhere.com

Install WordPress

Click Install WordPress

Login to WordPress and provide your Username and Password details

Click Login
LoginUsername
LoginPassword

To login to WordPress in the future use the wp-admin page

http://192.168.1.7/wp-admin