{"id":1910,"date":"2018-10-28T19:27:59","date_gmt":"2018-10-28T19:27:59","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1910"},"modified":"2018-10-31T03:14:31","modified_gmt":"2018-10-31T03:14:31","slug":"how-to-set-up-wordpress-on-a-raspberry-pi","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/28\/how-to-set-up-wordpress-on-a-raspberry-pi\/","title":{"rendered":"How to set up WordPress on a Raspberry Pi"},"content":{"rendered":"<p>WordPress is a popular open source blogging platform and content management system (CMS). It&#8217;s easy to set up and has a thriving community of developers building websites and creating themes and plugins for others to use.<\/p>\n<p>Although getting hosting packages with a &#8220;one-click WordPress setup&#8221; is easy, it&#8217;s also simple to set up your own on a Linux server with only command-line access, and the <a href=\"https:\/\/opensource.com\/sitewide-search?search_api_views_fulltext=raspberry%20pi\">Raspberry Pi<\/a> is a perfect way to try it out and learn something along the way.<\/p>\n<p>The four components of a commonly used web stack are Linux, Apache, MySQL, and PHP. Here&#8217;s what you need to know about each.<\/p>\n<h2>Linux<\/h2>\n<p>The Raspberry Pi runs Raspbian, which is a Linux distribution based on Debian and optimized to run well on Raspberry Pi hardware. It comes with two options to start: Desktop or Lite. The Desktop version boots to a familiar-looking desktop and comes with lots of educational software and programming tools, as well as the LibreOffice suite, Minecraft, and a web browser. The Lite version has no desktop environment, so it&#8217;s command-line only and comes with only the essential software.<\/p>\n<p>This tutorial will work with either version, but if you use the Lite version you&#8217;ll have to use another computer to access your website.<\/p>\n<h2>Apache<\/h2>\n<p>Apache is a popular web server application you can install on the Raspberry Pi to serve web pages. On its own, Apache can serve static HTML files over HTTP. With additional modules, it can serve dynamic web pages using scripting languages such as PHP.<\/p>\n<p>Installing Apache is very simple. Open a terminal window and type the following command:<\/p>\n<p>sudo apt install apache2 -y<\/p>\n<p>By default, Apache puts a test HTML file in a web folder you can view from your Pi or another computer on your network. Just open the web browser and enter the address <a href=\"http:\/\/localhost\">http:\/\/localhost<\/a>. Alternatively (particularly if you&#8217;re using Raspbian Lite), enter the Pi&#8217;s IP address instead of localhost. You should see this in your browser window:<\/p>\n<p>This means you have Apache working!<\/p>\n<p>This default webpage is just an HTML file on the filesystem. It is located at \/var\/www\/html\/index.html. You can try replacing this file with some HTML of your own using the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Leafpad\" target=\"_blank\" rel=\"noopener\">Leafpad<\/a> text editor:<\/p>\n<p>cd \/var\/www\/html\/<br \/>\nsudo leafpad index.html<\/p>\n<p>Save and close Leafpad then refresh the browser to see your changes.<\/p>\n<h2>MySQL<\/h2>\n<p>MySQL (pronounced &#8220;my S-Q-L&#8221; or &#8220;my sequel&#8221;) is a popular database engine. Like PHP, it&#8217;s widely used on web servers, which is why projects like WordPress use it and why those projects are so popular.<\/p>\n<p>Install MySQL Server by entering the following command into the terminal window:<\/p>\n<p>sudo apt-get install mysql-server -y<\/p>\n<p>WordPress uses MySQL to store posts, pages, user data, and lots of other content.<\/p>\n<h2>PHP<\/h2>\n<p>PHP is a preprocessor: it&#8217;s code that runs when the server receives a request for a web page via a web browser. It works out what needs to be shown on the page, then sends that page to the browser. Unlike static HTML, PHP can show different content under different circumstances. PHP is a very popular language on the web; huge projects like Facebook and Wikipedia are written in PHP.<\/p>\n<p>Install PHP and the MySQL extension:<\/p>\n<p>sudo apt-get install php php-mysql -y<\/p>\n<p>Delete the index.html file and create index.php:<\/p>\n<p>sudo rm index.html<br \/>\nsudo leafpad index.php<\/p>\n<p>Add the following line:<\/p>\n<p>&lt;?php phpinfo(); ?&gt;<\/p>\n<p>Save, exit, and refresh your browser. You&#8217;ll see the PHP status page:<\/p>\n<h2>WordPress<\/h2>\n<p>You can download WordPress from <a href=\"http:\/\/wordpress.org\/\" target=\"_blank\" rel=\"noopener\">wordpress.org<\/a> using the wget command. Helpfully, the latest version of WordPress is always available at <a href=\"https:\/\/wordpress.org\/latest.tar.gz\" target=\"_blank\" rel=\"noopener\">wordpress.org\/latest.tar.gz<\/a>, so you can grab it without having to look it up on the website. As I&#8217;m writing, this is version 4.9.8.<\/p>\n<p>Make sure you&#8217;re in \/var\/www\/html and delete everything in it:<\/p>\n<p>cd \/var\/www\/html\/<br \/>\nsudo rm *<\/p>\n<p>Download WordPress using wget, then extract the contents and move the WordPress files to the html directory:<\/p>\n<p>sudo wget http:\/\/wordpress.org\/latest.tar.gz<br \/>\nsudo tar xzf latest.tar.gz<br \/>\nsudo mv wordpress\/* .<\/p>\n<p>Tidy up by removing the tarball and the now-empty wordpress directory:<\/p>\n<p>sudo rm -rf wordpress latest.tar.gz<\/p>\n<p>Running the ls or tree -L 1 command will show the contents of a WordPress project:<\/p>\n<p>.<\/p>\n<p>\u251c\u2500\u2500 index.php<\/p>\n<p>\u251c\u2500\u2500 license.txt<\/p>\n<p>\u251c\u2500\u2500 readme.html<\/p>\n<p>\u251c\u2500\u2500 wp-activate.php<\/p>\n<p>\u251c\u2500\u2500 wp-admin<\/p>\n<p>\u251c\u2500\u2500 wp-blog-header.php<\/p>\n<p>\u251c\u2500\u2500 wp-comments-post.php<\/p>\n<p>\u251c\u2500\u2500 wp-config-sample.php<\/p>\n<p>\u251c\u2500\u2500 wp-content<\/p>\n<p>\u251c\u2500\u2500 wp-cron.php<\/p>\n<p>\u251c\u2500\u2500 wp-includes<\/p>\n<p>\u251c\u2500\u2500 wp-links-opml.php<\/p>\n<p>\u251c\u2500\u2500 wp-load.php<\/p>\n<p>\u251c\u2500\u2500 wp-login.php<\/p>\n<p>\u251c\u2500\u2500 wp-mail.php<\/p>\n<p>\u251c\u2500\u2500 wp-settings.php<\/p>\n<p>\u251c\u2500\u2500 wp-signup.php<\/p>\n<p>\u251c\u2500\u2500 wp-trackback.php<\/p>\n<p>\u2514\u2500\u2500 xmlrpc.php<\/p>\n<p>3 directories, 16 files<\/p>\n<p>This is the source of a default WordPress installation. The files you edit to customize your installation belong in the wp-content folder.<\/p>\n<p>You should now change the ownership of all these files to the Apache user:<\/p>\n<p>sudo chown -R www-data: .<\/p>\n<h2>WordPress database<\/h2>\n<p>To get your WordPress site set up, you need a database. This is where MySQL comes in!<\/p>\n<p>Run the MySQL secure installation command in the terminal window:<\/p>\n<p>sudo mysql_secure_installation<\/p>\n<p>You will be asked a series of questions. There&#8217;s no password set up initially, but you should set one in the second step. Make sure you enter a password you will remember, as you&#8217;ll need it to connect to WordPress. Press Enter to say Yes to each question that follows.<\/p>\n<p>When it&#8217;s complete, you will see the messages &#8220;All done!&#8221; and &#8220;Thanks for using MariaDB!&#8221;<\/p>\n<p>Run mysql in the terminal window:<\/p>\n<p>sudo mysql -uroot -p<\/p>\n<p>Enter the root password you created. You will be greeted by the message &#8220;Welcome to the MariaDB monitor.&#8221; Create the database for your WordPress installation at the MariaDB [(none)]&gt; prompt using:<\/p>\n<p>create database wordpress;<\/p>\n<p>Note the semicolon at the end of the statement. If the command is successful, you should see this:<\/p>\n<p>Query OK, 1 row affected (0.00 sec)<\/p>\n<p>Grant database privileges to the root user, entering your password at the end of the statement:<\/p>\n<p>GRANT ALL PRIVILEGES ON wordpress.* TO &#8216;root&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;YOURPASSWORD&#8217;;<\/p>\n<p>For the changes to take effect, you will need to flush the database privileges:<\/p>\n<p>FLUSH PRIVILEGES;<\/p>\n<p>Exit the MariaDB prompt with Ctrl+D to return to the Bash shell.<\/p>\n<h2>WordPress configuration<\/h2>\n<p>Open the web browser on your Raspberry Pi and open <a href=\"http:\/\/localhost\">http:\/\/localhost<\/a>. You should see a WordPress page asking you to pick your language. Select your language and click Continue. You will be presented with the WordPress welcome screen. Click the Let&#8217;s go! button.<\/p>\n<p>Fill out the basic site information as follows:<\/p>\n<p>Database Name: wordpress<br \/>\nUser Name: root<br \/>\nPassword: &lt;YOUR PASSWORD&gt;<br \/>\nDatabase Host: localhost<br \/>\nTable Prefix: wp_<\/p>\n<p>Click Submit to proceed, then click Run the install.<\/p>\n<p>Fill in the form: Give your site a title, create a username and password, and enter your email address. Hit the Install WordPress button, then log in using the account you just created. Now that you&#8217;re logged in and your site is set up, you can see your website by visiting <a href=\"http:\/\/localhost\/wp-admin\">http:\/\/localhost\/wp-admin<\/a>.<\/p>\n<h2>Permalinks<\/h2>\n<p>It&#8217;s a good idea to change your permalink settings to make your URLs more friendly.<\/p>\n<p>To do this, log into WordPress and go to the dashboard. Go to Settings, then Permalinks. Select the Post name option and click Save Changes. You&#8217;ll need to enable Apache&#8217;s rewrite module:<\/p>\n<p>sudo a2enmod rewrite<\/p>\n<p>You&#8217;ll also need to tell the virtual host serving the site to allow requests to be overwritten. Edit the Apache configuration file for your virtual host:<\/p>\n<p>sudo leafpad \/etc\/apache2\/sites-available\/000-default.conf<\/p>\n<p>Add the following lines after line 1:<\/p>\n<p>&lt;Directory &#8220;\/var\/www\/html&#8221;&gt;<br \/>\nAllowOverride All<br \/>\n&lt;\/Directory&gt;<\/p>\n<p>Ensure it&#8217;s within the &lt;VirtualHost *:80&gt; like so:<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\n&lt;Directory &#8220;\/var\/www\/html&#8221;&gt;<br \/>\nAllowOverride All<br \/>\n&lt;\/Directory&gt;<br \/>\n&#8230;<\/p>\n<p>Save the file and exit, then restart Apache:<\/p>\n<p>sudo systemctl restart apache2<\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>WordPress is very customizable. By clicking your site name in the WordPress banner at the top of the page (when you&#8217;re logged in), you&#8217;ll be taken to the Dashboard. From there, you can change the theme, add pages and posts, edit the menu, add plugins, and do lots more.<\/p>\n<p>Here are some interesting things you can try on the Raspberry Pi&#8217;s web server.<\/p>\n<ul>\n<li>Add pages and posts to your website<\/li>\n<li>Install different themes from the Appearance menu<\/li>\n<li>Customize your website&#8217;s theme or create your own<\/li>\n<li>Use your web server to display useful information for people on your network<\/li>\n<\/ul>\n<p>Don&#8217;t forget, the Raspberry Pi is a Linux computer. You can also follow these instructions to install WordPress on a server running Debian or Ubuntu.<\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=262000\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress is a popular open source blogging platform and content management system (CMS). It&#8217;s easy to set up and has a thriving community of developers building websites and creating themes and plugins for others to use. Although getting hosting packages with a &#8220;one-click WordPress setup&#8221; is easy, it&#8217;s also simple to set up your own &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/28\/how-to-set-up-wordpress-on-a-raspberry-pi\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to set up WordPress on a Raspberry Pi&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1910","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1910","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1910"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1910\/revisions"}],"predecessor-version":[{"id":2032,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1910\/revisions\/2032"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1910"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}