Building Your Own Website Using:
Install & configure LAMP. Download WordPress and run it as a local website on your Raspberry Pi. Configure WordPress and make your website accessible to the class on your local network. GOALS FOR TODAY
STEP ONE: SET UP APACHE WEB SERVER sudo apt-get install apache2 -y
TEST THE WEB SERVER By default, Apache puts a test HTML in the web folder. This default page is served when you browse to on the Pi itself, or from another computer on the network. Find your ip address by typing hostname -I TAKE NOTE OF YOUR IP ADDRESS! Once you type this information into your web browser you should see the default page on the following slide….
IF YOU SEE THIS PAGE, THIS IS GOOD!
STEP TWO: INSTALL PHP sudo apt-get install php5 libapache2-mod-php5 -y
TEST PHP Before we test PHP, we must know where to put our file that we’ll use to test it. First, type in the following commands: cd /var/www/html ls -al Now that we are in the right directory, we can create or first file which will be a.php file. So now, we’ll create the file “index.php”, but first, let’s install an editor. Let’s use “vim”: sudo apt-get install vim “vim” is one of the many editor’s you can use in linux. Linux comes with the editor “nano”, however, I think “vim” is a lot better! Now that we got that done, let’s create our “index.php” file by typing the following command: sudo vim index.php
TEST PHP CONTINUED Press the button “insert” on your keyboard which will allow you to start coding. Afterwards type: One finished, press the “esc” button to exit editor mode, and then type: :x! to save your new file. Now type ls -al again. Notice that you have two files with “index” as their file names. Lets remove the.html one by typing: sudo rm index.html Refresh your browser. You should see “hello world”. If you want to see something that changes automatically, type in:
STEP THREE: INSTALL MYSQL sudo apt-get install mysql-server php5-mysql -y
TECHNOLOGIES TO LOOK INTO IN ADDITION TO MYSQL
STEP FOUR: DOWNLOAD WORDPRESS
THE PROCESS We will download WordPress in our “html” folder. If you aren’t there, type exit, open a new terminal, and type the following command: cd/var/www/html We will now remove all contents of this folder and change the ownership of this folder to us so that it recognizes us as the root user. Type in the following commands: sudo chown pi:. sudo rm *; wget
THE PROCESS… Now extract the tarball, move the contents of the folder it extracted (wordpress) to the current directory and remove the (now empty) folder and the tarball to tidy up: tar xzf latest.tar.gz mv wordpress/*. rm –rf wordpress latest.tar.gz Running the ls or (tree -L 1) command here will show you the contents of a WordPress project.
STEP FIVE: SETUP YOUR WORD PRESS DATABASE
SETTING UP YOUR DATABASE To get your WordPress site set up, you need a database. Run the mysql command in the terminal and provide your login credentials (e.g. username root, password password): mysql -uroot -p(your password) Here I have provided my password (the word password) on the command line; there is no space between -p and your password. Alternatively you can simply supply an empty -p flag and wait to be asked for a password: mysql -uroot -p Now you will be prompted to enter the root user password you created earlier.
SETTING UP YOUR DATABASE… Once you're connected to MySQL, you can create the database your WordPress installation will use: mysql> create database wordpress; Note the semi-colon ending the statement. On success you should see the following message: Query OK, 1 row affected (0.00 sec) Exit out of MySQL prompt with Ctrl + D.
STEP SIX: WORD PRESS CONFIGURATION
WORD PRESS CONFIGURATION Navigate to e.g. in the web browser on your Pi. You may possibly see an error. This is because a specific extension is not found that connects PHP to MySQL. To do this, we have to uncomment a specific line of code. We will now go to the directory that has the file we need to edit which is “php.ini”: exit cd /etc/php5/apache2 sudo vim php.ini
WORD PRESS CONFIGURATION… Now we need to find the line of code we need to uncomment. Comments in this php file are marked with “;”. The line you need to find is “;extension=php_mysql.dll” or something similar to it. Once you find it, delete the “;” sign, then press “esc” and to save, press “:” then “x” and lastly “!” and press enter. Now we must restart the apache2 server. Type: sudo /etc/init.d/apache2 restart Once it’s finished, type in your IP address in your browser. You should see a WordPress error page; this is good! Click the big button marked “Create a Configuration File” followed by the “Let's go!” button on the next page.
STILL CONFIGURING GUYS Now fill out the basic site information as follows: Database Name: wordpress User Name: root Password: Database Host: localhost Table Prefix: wp_ Upon successful database connection, you will be given the contents of your wp- config.php file:
YOU SHOULD SEE THIS PAGE NOW
AAAAND BACK TO EDITING Copy this text, return to the terminal on the Pi and edit the file with: vim wp-config.php Paste the text into this file, and save and exit with: :x! Now hit the Run the install button.
WELCOME SCREEN Fill out the information: give your site a title, create a username and password, put in your address and untick the search engines box. Hit the Install WordPress button, then log in using the account you just created. Now you're logged in and have your site set up, you can see the website by visiting your IP address in the browser on the Pi or another computer on the network. To log in again (or on another computer), type in your browser:
FRIENDLY PERMALINKS It's recommended that you change your permalink settings to make your URLs more friendly. To do this, log in to WordPress and go to the dashboard. Go to Settings then Permalinks. Select the Post name option and click Save Changes. After saving, you will be prompted to update your.htaccess file. You probably don't have one yet, so add one in /var/www/html/ by typing: vim.htaccess note this is a hidden file, so it starts with a dot. Then paste in the contents provided: RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule. /index.php [L]
FRIENDLY PERMALINKS CONTINUTED… Save the file and return to the website homepage. Click on the post title or the sample page link and you'll probably see a Not Found error page. This is because the rewrite module has not been enabled in Apache. To do this, type in: sudo a2enmod rewrite You'll also need to tell the virtual host serving the site to allow requests to be overwritten. Do this by editing the virtual host file (with root permissions): sudo vim /etc/apache2/sites-available/default also, change the AllowOverride setting on line 11 (inside the block) from None to All. Save the file and then restart Apache with: sudo service apache2 restart
RESULT OF THE RESTART Once it's restarted, refresh the page and it should load successfully. Now posts have URLs like /hello-world/ instead of /?p=123, and pages have URLs like /sample-page/ instead of /?page_id=2.
STEP SEVEN: CUSTOMIZATION
CUSTOMIZATION WordPress is very customizable. By clicking your site name in the WordPress banner along the top of the page (when logged in), you'll be taken to the Dashboard. From here you can change the theme, add pages and posts, edit the menu, add plugins and lots more. This is just a taster for getting something interesting set up on the Raspberry Pi's web server.
NEXT SET OF GOALS Try adding pages and posts to your website. Try installing different themes from the appearance menu. Try customizing your theme, or creating your own. Try using your web server to display useful information to people on your network.