How to Install Wordpress on Ubuntu 14

Embed Size (px)

Citation preview

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    1/26

    How To Install Wordpress on Ubuntu 14.04

    Apr 24, 2014WordPressUbuntu

    Introduction

    At this time, WordPress is the most popular CMS (content management system) on the internet.It allows you to easily set up flexible blogs and websites on top of a MySQL backend with PHPprocessing. WordPress has seen incredible adoption and is a great choice for getting a website upand running quickly.

    In this guide, we'll focus on getting a WordPress instance set up with an Apache web server onUbuntu 14.04.

    Prerequisites

    Before you begin this guide, there are some important steps that you need to complete on yourserver.

    We will be proceeding through these steps as a non-root user with sudo privileges, so you willneed to have one available. You can find out how to create a user with sudo privileges byfollowing steps 1-4 in ourUbuntu 14.04 initial server setupguide.

    Additionally, you'll need to have a LAMP (Linux, Apache, MySQL, and PHP) stack installed onyour VPS instance. If you don't have these components already installed and configured, you canuse this guide to learnhow to install LAMP on Ubuntu 14.04.

    When you are finished with these steps, you can continue with this guide.

    Step OneCreate a MySQL Database and User for

    WordPress

    The first step that we will take is a preparatory one. WordPress uses a relational database tomanage and store site and user information.

    We have MySQL installed, which can provide this functionality, but we need to make a database

    and a user for WordPress to work with.

    To get started, log into the MySQL root (administrative) account by issuing this command:

    mysql -u root -p

    You will be prompted for the password you set for the MySQL root account when you installedthe software. You will then be given a MySQL command prompt.

    https://www.digitalocean.com/community/tags/wordpress?type=tutorialshttps://www.digitalocean.com/community/tags/wordpress?type=tutorialshttps://www.digitalocean.com/community/tags/ubuntu?type=tutorialshttps://www.digitalocean.com/community/tags/ubuntu?type=tutorialshttps://www.digitalocean.com/community/tags/ubuntu?type=tutorialshttps://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/tags/ubuntu?type=tutorialshttps://www.digitalocean.com/community/tags/wordpress?type=tutorials
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    2/26

    First, we can create a separate database that WordPress can control. You can call this whatever

    you would like, but I will be calling it wordpressbecause it is descriptive and simple. Enter thiscommand to create the database:

    CREATE DATABASE wordpress;

    Every MySQL statement must end in a semi-colon (;), so check to make sure this is present ifyou are running into any issues.

    Next, we are going to create a separate MySQL user account that we will use exclusively tooperate on our new database. Creating one-function databases and accounts is a good idea from amanagement and security standpoint.

    I am going to call the new account that I'm making wordpressuserand will assign it a password

    of password. You should definitely change the password for your installation and can name theuser whatever you'd like. This is the command you need to create the user:

    CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';

    At this point, you have a database and a user account, each made specifically for WordPress.However, these two components have no relationship yet. The user has no access to the database.

    Let's fix that by granting our user account access to our database with this command:

    GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost;

    Now the user has access to the database. We need to flush the privileges so that the currentinstance of MySQL knows about the recent privilege changes we've made:

    FLUSH PRIVILEGES;

    We're all set now. We can exit out of the MySQL prompt by typing:

    exit

    You should now be back to your regular command prompt.

    Step TwoDownload WordPress

    Next, we will download the actual WordPress files from the project's website.

    Luckily, the WordPress team always links the most recent stable version of their software to thesame URL, so we can get the most up-to-date version of WordPress by typing this:

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

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    3/26

    This will download a compressed file that contains the archived directory contents of theWordPress files to our home directory.

    We can extract the files to rebuild the WordPress directory we need by typing:

    tar xzvf latest.tar.gz

    This will create a directory called wordpressin your home directory.

    While we are downloading things, we should also get a few more packages that we need. We canget these directly from Ubuntu's default repositories after we update our local package index:

    sudo apt-get updatesudo apt-get install php5-gd libssh2-php

    This will allow you to work with images and will also allow you to install plugins and updateportions of your site using your SSH login credentials.

    Step ThreeConfigure WordPress

    Most of the configuration that we will be doing will be through a web interface later on.However, we do need to do some work from the command line before we can get this up andrunning.

    Begin by moving into the WordPress directory that you just unpacked:

    cd ~/wordpress

    A sample configuration file that mostly matches the configuration we need is included bydefault. However, we need to copy it to the default configuration file location to get WordPressto recognize the file. Do that now by typing:

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

    Now that we have a configuration file to work with, let's open it in a text editor:

    nano wp-config.php

    As I said before, this file is almost entirely suitable for our needs already. The only modifications

    we need to make are to the parameters that hold our database information.

    We will need to find the settings for DB_NAME, DB_USER, and DB_PASSWORDin order forWordPress to correctly connect and authenticate to the database we created.

    Fill in the values of these parameters with the information for the database you created. It shouldlook like this:

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    4/26

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

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

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

    These are the only values that you need to change.

    When you are finished, save and close the file.

    Step FourCopy Files to the Document Root

    Now that we have our application configured, we need to copy it into Apache's document root,where it can be served to visitors of our website.

    One of the easiest and most reliable way of transferring files from directory to directory is with

    the rsynccommand. This preserves permissions and has good data integrity features.

    The location of the document root inthe Ubuntu 14.04 LAMP guideis /var/www/html/. Wecan transfer our WordPress files there by typing:

    sudo rsync -avP ~/wordpress/ /var/www/html/

    This will safely copy all of the contents from the directory you unpacked to the document root.

    We should now move into the document root to make some final permissions changes

    cd /var/www/html

    You will need to change the ownership of our files for increased security.

    We want to give user ownership to the regular, non-root user (with sudo privileges) that you planon using to interact with your site. This can be your regular user if you wish, but some maysuggest that you create an additional user for this process. It is up to you which you choose.

    For this guide, we will use the same account that we set up during theinitial server setupguide,

    which we called demo. This is the account I am performing all of the actions of this guide as.

    The group ownership we will give to our web server process, which is www-data. This will allowApache to interact with the content as necessary.

    We can quickly assign these ownership values by typing:

    sudo chown -R demo:www-data *

    https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/articles/initial-server-setup-with-ubuntu-14-04https://www.digitalocean.com/community/articles/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    5/26

    This will set up the ownership properties that we are looking for.

    While we are dealing with ownership and permissions, we should also look into assigningcorrect ownership on our uploads directory. This will allow us to upload images and othercontent to our site. Currently, the permissions are too restrictive.

    First, let's manually create the uploadsdirectory beneath the wp-contentdirectory at ourdocument root. This will be the parent directory of our content:

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

    We have a directory now to house uploaded files, however the permissions are still toorestrictive. We need to allow the web server itself to write to this directory. We can do this byassigning group ownership of this directory to our web server, like this:

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

    This will allow the web server to create files and directories under this directory, which willpermit us to upload content to the server.

    Step FiveComplete Installation through the Web

    Interface

    Now that you have your files in place and your software is configured, you can complete theinstallation through the web interface.

    In your web browser, navigate to your server's domain name or public IP address:

    http://server_domain_name_or_IP

    You will see the WordPress initial configuration page, where you will create an initialadministrator account:

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    6/26

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    7/26

    Fill out the information for the site and the administrative account you wish to make. When youare finished, click on the install button at the bottom.

    WordPress will confirm the installation, and then ask you to log in with the account you justcreated:

    Hit the button at the bottom and then fill out your account information:

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    8/26

    You will be presented with the WordPress interface:

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    9/26

    Step Six (Optional)Configure Pretty Permalinks for

    WordPress

    By default, WordPress creates URLs dynamically that look something like this:

    http://server_domain_name_or_IP/?p=1

    This isn't exactly the most useful interface for visitors or search engines, so most users want tomodify this. WordPress has the ability to create "pretty" permalinks which will clean up the URLinto a more human-friendly format.

    There are a few things we need to do to get this to work with Apache on Ubuntu 14.04.

    Modifying Apache to Allow URL Rewrites

    First, we need to modify the Apache virtual host file for WordPress to allow for .htaccessoverrides. You can do this by editing the virtual host file.

    By default, this is 000-default.conf, but your file might be different if you created anotherconfiguration file:

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

    Inside of this file, we want to set up a few things. We should set the ServerNameand create adirectory section where we allow overrides. This should look something like this:

    ServerAdmin webmaster@localhostDocumentRoot /var/www/htmlServerName server_domain_name_or_IP

    AllowOverride All. . .

    When you are finished, save and close the file.

    Next, we need to enable the rewrite module, which allows you to modify URLs. You can do thisby typing:

    sudo a2enmod rewrite

    After you have made these changes, restart Apache:

    sudo service apache2 restart

    Create an .htaccess File

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    10/26

    Now that Apache is configured to allow rewrites through .htaccessfiles, we need to create anactual file.

    You need to place this file in your document root. Type this to create an empty file:

    touch /var/www/html/.htaccess

    This will be created with your username and user group. We need the web server to be the groupowner though, so we should adjust the ownership by typing:

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

    We now have the correct ownership of this file.

    We may need to adjust the permissions however. This depends on how you prefer to work.WordPress will generate the necessary rewrite rules for you. If it has write permissions to thisfile, it can implement the rules automatically. If it does not, you will have to manually edit thisfile to add the correct rules.

    Which configuration you choose depends on how much you value convenience over security.Allowing the web server write access to this file will definitely be more convenient, but somesay that it is an unnecessary security risk.

    If you want WordPress to automatically update this file with rewrite rules, you can ensure that ithas the correct permissions to do so by typing:

    chmod 664 /var/www/html/.htaccess

    If you want to update this file manually for the sake of a small security gain, you can allow theweb server only read privileges by typing:

    chmod 644 /var/www/html/.htaccess

    Change the Permalink Settings in WordPress

    When you are finished doing the server-side changes, you can easily adjust the permalinksettings through the WordPress administration interface.

    On the left-hand side, under the Settingsmenu, you can select Permalinks:

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    11/26

    You can choose any of the preconfigured settings to organize URLs, or you can create your own.

    When you have made your selection, click "Save Changes" to generate the rewrite rules.

    If you allowed the web server write access to your .htaccessfile, you should see a message likethis:

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    12/26

    If you did notallow the web server write access to your .htaccessfile, you will be providedwith the rewrite rules you need to add to the file manually.

    Copy the lines that WordPress gives you and then edit file on your server:

    nano /var/www/html/.htaccess

    This should give you the same functionality.

    Conclusion

    You should now have a WordPress instance up and running on your Ubuntu 14.04 VPS. Thereare many avenues you can take from here. Below we've listed some options:

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    13/26

    ApacheMySQLPHP

    Hint: Server Guide

    To find the Ubuntu Server Guide related to your specific version, please go to:https://help.ubuntu.com/,select your Ubuntu version and then click on Ubuntu Server Guide.For the latest LTS version (14.04.1 LTS) of Ubuntu Server, please go tohttps://help.ubuntu.com/14.04/serverguide/index.html

    Parent page:Programming Applications

    This is to help people set up and install aLAMP(Linux-Apache-MySQL-PHP) server inUbuntu, including Apache 2, PHP 5 and MySQL 4.1 or 5.0.

    To install the default LAMP stack in Ubuntu 10.04 and

    above

    First refresh your package index...

    $ sudo apt-get update

    ... and then install the LAMP stack:

    $ sudo apt-get install lamp-server^

    Mind the caret (^) at the end.

    Starting over: How to remove the LAMP stack

    To remove the LAMP stack remove the following packages:

    Note: This assumes you have no other programs that require any of these packages. Youmight wish to simulate this removal first, and only remove the packages that don't causeremoval of something desired.

    apache2 apache2-mpm-prefork apache2-utils apache2.2-common libapache2-mod-php5 libapr1 libaprutil1 libdbd-mysql-perl libdbi-perl libnet-daemon-perllibplrpc-perl libpq5 mysql-client-5.5 mysql-common mysql-server mysql-server-5.5 php5-common php5-mysql

    To also remove the debconf data, use the purge option when removing. To get rid of anyconfigurations you may have made to apache, manually remove the /etc/apache2 directory oncethe packages have been removed.

    https://help.ubuntu.com/community/ApacheMySQLPHP?action=fullsearch&value=linkto%3A%22ApacheMySQLPHP%22&context=180https://help.ubuntu.com/https://help.ubuntu.com/https://help.ubuntu.com/14.04/serverguide/index.htmlhttps://help.ubuntu.com/14.04/serverguide/index.htmlhttps://help.ubuntu.com/community/Programminghttps://help.ubuntu.com/community/Programminghttps://help.ubuntu.com/community/Programminghttp://en.wikipedia.org/wiki/LAMP_%28software_bundle%29http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29https://help.ubuntu.com/community/Programminghttps://help.ubuntu.com/14.04/serverguide/index.htmlhttps://help.ubuntu.com/https://help.ubuntu.com/community/ApacheMySQLPHP?action=fullsearch&value=linkto%3A%22ApacheMySQLPHP%22&context=180
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    14/26

    You may also want to purge these packages:

    mysql-client-core-5.5 mysql-server-core-5.5

    Installing Apache 2

    To only install the apache2 webserver, useany methodto install:

    apache2

    It requires a restart for it to work:

    $ sudo /etc/init.d/apache2 restart

    or

    $ sudo service apache2 restart

    Checking Apache 2 installation

    With your web browser, go to the URI http://localhost : if you read "It works!", which is thecontent of the file /var/www/index.html , this proves Apache works.

    Troubleshooting Apache

    If you get this error:

    apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 forServerName

    Ubuntu 13.10+

    Use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop tocreate a new file,

    $ sudo nano /etc/apache2/conf-available/fqdn.conf

    or

    $ gksu "gedit /etc/apache2/conf-available/fqdn.conf"

    then add

    ServerName localhost

    to the file, save it, and enable your new configuration file by running the command below.

    https://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/ServerNamehttps://help.ubuntu.com/community/ServerNamehttps://help.ubuntu.com/community/ServerNamehttps://help.ubuntu.com/community/InstallingSoftware
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    15/26

    sudo a2enconf fqdn

    This can all be done in a single command with the following:

    $ echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf && sudo a2enconf fqdn

    Ubuntu 13.04 and below

    In older versions of Apache, the configuration files were located in a different directory. Use atext editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop to create anew file,

    $ sudo nano /etc/apache2/conf.d/fqdn

    or

    $ gksu "gedit /etc/apache2/conf.d/fqdn"

    then add

    ServerName localhost

    to the file and save. This can all be done in a single command with the following:

    $ echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn

    Virtual Hosts

    Apache2 has the concept of sites, which are separate configuration files that Apache2 will read.

    These are available in /etc/apache2/sites-available . By default, there is one site availablecalled 000-default. This is what you will see when you browse tohttp://localhostorhttp://127.0.0.1.You can have many different site configurations available, and activate onlythose that you need.

    As an example, we want the default site to be /home/user/public_html/. To do this, we mustcreate a new site and then enable it in Apache2.

    To create a new site:

    Copy the default website as a starting point. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.conf

    Edit the new configuration file in a text editor "sudo nano" on the command line or

    "gksudo gedit", for example: gksudo gedit /etc/apache2/sites-available/mysite.conf

    Change the DocumentRootto point to the new location. For example,/home/user/public_html/

    http://localhost/http://localhost/http://localhost/http://127.0.0.1/http://127.0.0.1/http://127.0.0.1/http://localhost/
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    16/26

    In the file: /etc/apache2/apache2.conf, change the Directorydirective, replace

    to

    You can also set separate logs for each site. To do this, change the ErrorLogand

    CustomLogdirectives. This is optional, but handy if you have many sites Save the file

    Now, we must deactivate the old site, and activate our new one. Ubuntu provides two smallutilities that take care of this: a2ensite (apache2enable site) and a2dissite (apache2disable site).

    $ sudo a2dissite 000-default && sudo a2ensite mysite

    Finally, we restart Apache2:

    $ sudo /etc/init.d/apache2 restart

    If you have not created /home/user/public_html/, you will receive an warning message

    To test the new site, create a file in /home/user/public_html/:

    $ echo 'Hello! It is working!' > /home/user/public_html/index.html

    Finally, browse tohttp://localhost/

    Installing PHP 5

    To only install PHP5. useany methodto install the package

    libapache2-mod-php5

    Enable this module by doing

    $ sudo a2enmod php5

    which creates a symbolic link /etc/apache2/mods-enabled/php5 pointing to /etc/apache2/mods-availble/php5 .

    Except if you use deprecated PHP code beginning only by "

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    17/26

    Checking PHP 5 installation

    In /var/www , create a text file called "test.php", grant the world (or, at least, Ubuntu user"apache") permission to read it, write in it the only line: "" (without thequotation marks) then, with your web browser, go to the URI "http://localhost/test.php": if you

    can see a description of PHP5 configuration, it proves PHP 5 works with Apache.

    Troubleshooting PHP 5

    Does your browser ask if you want to download the phpfile instead of displaying it? If Apache

    is not actually parsing the php after you restarted it, install libapache2-mod-php5. It is installed

    when you install the php5package, but may have been removed inadvertently by packageswhich need to run a different version of php.

    If sudo a2enmod php5returns "$ This module does not exist!", you should purge (not just

    remove) the libapache2-mod-php5package and reinstall it.

    Be sure to clear your browser's cache before testing your site again. To do this in Firefox 4: Edit Preferences Privacy History: clear your recent history Details : choose "Everything"

    in "Time range to clean" and check only "cache", then click on "Clear now".

    Remember that, for Apache to be called, the URI in your web browser must begin with "http://".If it begins with "file://", then the file is read directly by the browser, without Apache, so you get(X)HTML and CSS, but no PHP. If you didn't configure any host alias or virtual host, then alocal URI begins with "http://localhost", "http://127.0.0.1"orhttp://" followed by your IPnumber.

    If the problem persists, check your PHP file authorisations (it should be readable at least byUbuntu user "apache"), and check if the PHP code is correct. For instance, copy your PHP file,replace your whole PHP file content by "" (without the quotation marks): ifyou get the PHP test page in your web browser, then the problem is in your PHP code, not inApache or PHP configuration nor in file permissions. If this doesn't work, then it is a problem offile authorisation, Apache or PHP configuration, cache not emptied, or Apache not running ornot restarted. Use the display of that test file in your web browser to see the list of filesinfluencing PHP behaviour.

    php.ini development vs. production

    After standard installation, php configuration file/etc/php5/apache2/php.iniis set so as"production settings" which means, among others, that no error messages are displayed. So ifyou e.g. make a syntax error in your php source file, apache server would return HTTP 500 errorinstead of displaying the php syntax error debug message.

    If you want to debug your scripts, it might be better to use the "development" settings. Bothdevelopment and production settings ini's are located in /usr/share/php5/

    http://localhost/test.phphttp://localhost/test.phphttp://localhost/test.phphttp://localhost/var/www/apps/conversion/tmp/scratch_4/http://localhost/var/www/apps/conversion/tmp/scratch_4/http://localhost/var/www/apps/conversion/tmp/scratch_4/http://localhost/http://localhost/http://127.0.0.1/http://127.0.0.1/http://127.0.0.1/http://localhost/http://localhost/var/www/apps/conversion/tmp/scratch_4/http://localhost/test.php
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    18/26

    /usr/share/php5/php.ini-development/usr/share/php5/php.ini-production

    so you can compare them and see the exact differences.

    To make the "development" settings active, just backup your original php.ini

    sudo mv /etc/php5/apache2/php.ini /etc/php5/apache2/php.ini.bak

    and create a symlink to your desired settings:

    sudo cp -s /usr/share/php5/php.ini-development /etc/php5/apache2/php.ini

    or you may of course also edit the/etc/php5/apache2/php.inidirectly on your own, if you wish.

    PHP in user directories

    According tothis blog,newer versions of Ubuntu do nothave PHP enabled by default for userdirectories (your public_htmlfolder). See the blog for instructions on how to change this back.

    Installing MYSQL with PHP 5

    Useany methodto install

    mysql-server libapache2-mod-auth-mysql php5-mysql

    After installing PHP

    You may need to increase the memory limit that PHP imposes on a script. Edit the/etc/php5/apache2/php.ini file and increase the memory_limitvalue.

    After installing MySQL

    Set mysql bind address

    Before you can access the database from othercomputers in your network, you have to changeits bind address. Note that this can be a security problem, because your database can be

    accessed by other computers than your own. Skip this step if the applications which requiremysql are running on the same machine.

    type:

    $ sudo nano /etc/mysql/my.cnf

    and change the line:

    http://blag.borap.net/2010/05/04/re-enabling-php-in-user-directories-in-ubuntu-10-04/http://blag.borap.net/2010/05/04/re-enabling-php-in-user-directories-in-ubuntu-10-04/http://blag.borap.net/2010/05/04/re-enabling-php-in-user-directories-in-ubuntu-10-04/https://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttp://blag.borap.net/2010/05/04/re-enabling-php-in-user-directories-in-ubuntu-10-04/
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    19/26

    bind-address = localhost

    to your own internal ip address e.g. 192.168.1.20

    bind-address = 192.168.1.20

    If your ip address is dynamic you can also comment out the bind-address line and it will defaultto your current ip.

    If you try to connect without changing the bind-address you will recieve a "Can not connect tomysql error 10061".

    Set mysql root password

    Before accessing the database by console you need to type:

    $ mysql -u root

    At the mysql console type:

    $ mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('yourpassword');

    A successful mysql command will show:

    Query OK, 0 rows affected (0.00 sec)

    Mysql commands can span several lines. Do not forget to end your mysql command with asemicolon.

    Note:If you have already set a password for the mysql root, you will need to use:

    $ mysql -u root -p

    (Did you forget the mysql-root password? SeeMysqlPasswordReset.)

    Create a mysql database

    $ mysql> CREATE DATABASE database1;

    Create a mysql user

    For creating a new user with all privileges (use only for troubleshooting), at mysql prompt type:

    $ mysql> GRANT ALL PRIVILEGES ON *.* TO 'yourusername'@'localhost' IDENTIFIEDBY 'yourpassword' WITH GRANT OPTION;

    https://help.ubuntu.com/community/MysqlPasswordResethttps://help.ubuntu.com/community/MysqlPasswordResethttps://help.ubuntu.com/community/MysqlPasswordResethttps://help.ubuntu.com/community/MysqlPasswordReset
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    20/26

    For creating a new user with fewer privileges (should work for most web applications) which canonly use the database named "database1", at mysql prompt type:

    $ mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER,CREATE TEMPORARY TABLES, LOCK TABLES ON database1.* TO'yourusername'@'localhost' IDENTIFIED BY 'yourpassword';

    yourusernameandyourpasswordcan be anything you like. database1is the name of thedatabase the user gets access to. localhostis the location which gets access to your database. Youcan change it to '%' (or to hostnames or ip addresses) to allow connections from every location(or only from specific locations) to the database. Note, that this can be a security problem andshould only be used for testing purposes!

    To exit the mysql prompt type:

    $ mysql> \q

    Since the mysql root password is now set, if you need to use mysql again (as the mysql root),you will need to use:

    $ mysql -u root -p

    and then enter the password at the prompt.

    Backup-Settings

    Please, let's say something in which directories mysql stores the database information and how toconfigure a backup

    Alternatively

    There is more than just one way to set the mysql root password and create a database. Forexample mysqladmincan be used:

    $ mysqladmin -u root -p password yourpassword

    and

    $ mysqladmin -u root -p create database1

    mysqladminis a command-line tool provided by the default LAMP install.

    Phpmyadmin and mysql-workbench

    All mysql tasks including setting the root password and creating databases can be done via agraphical interface using phpmyadminor mysql-workbench.

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    21/26

    To install one or both of them, first enable the universe repository

    I am using Ubuntu server (command line) I am using a desktop

    Useany methodto install

    phpmyadmin

    Troubleshooting Phpmyadmin & mysql-workbench

    If you get blowfish_secret error:Choose and set a phrase for cryptography in the file/etc/phpmyadmin/blowfish_secret.inc.php and copy the line (not the php tags) into the file/etc/phpmyadmin/config.inc.php or you will receive an error.

    If you get a 404 error upon visitinghttp://localhost/phpmyadmin:You will need to configure

    apache2.conf to work with Phpmyadmin.

    $ gksudo gedit /etc/apache2/apache2.conf

    Include the following line at the bottom of the file, save and quit.

    $ Include /etc/phpmyadmin/apache.conf

    Alternative: install phpMyAdmin from source

    See thephpMyAdminpage for instructions on how to install phpmyadmin from source:

    Mysql-workbench

    Mysql-workbench runs locally, on the desktop. Useany methodto install

    mysql-workbench

    For more information

    2.9.3. Securing the Initial MySQL Accountsfrom theMySQL Reference Manualis worthreading.

    Edit Apache Configuration

    You may want your current user to be the PHP pages administrator. To do so, edit the Apacheconfiguration file :

    $ gksudo "gedit /etc/apache2/envvars"

    https://help.ubuntu.com/community/Repositories/CommandLinehttps://help.ubuntu.com/community/Repositories/CommandLinehttps://help.ubuntu.com/community/AddingRepositoriesHowtohttps://help.ubuntu.com/community/AddingRepositoriesHowtohttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttp://localhost/phpmyadminhttp://localhost/phpmyadminhttp://localhost/phpmyadminhttps://help.ubuntu.com/community/phpMyAdminhttps://help.ubuntu.com/community/phpMyAdminhttps://help.ubuntu.com/community/phpMyAdminhttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttp://dev.mysql.com/doc/mysql/en/default-privileges.htmlhttp://dev.mysql.com/doc/mysql/en/default-privileges.htmlhttp://dev.mysql.com/doc/mysql/en/index.htmlhttp://dev.mysql.com/doc/mysql/en/index.htmlhttp://dev.mysql.com/doc/mysql/en/index.htmlhttp://dev.mysql.com/doc/mysql/en/index.htmlhttp://dev.mysql.com/doc/mysql/en/default-privileges.htmlhttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/phpMyAdminhttp://localhost/phpmyadminhttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/AddingRepositoriesHowtohttps://help.ubuntu.com/community/Repositories/CommandLine
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    22/26

    Search both the strings starting by "APACHE_RUN_USER" and "APACHE_RUN_GROUP",and change the names to the current username and groupname you are using. Then you'll need torestart Apache. (look at the next chapter concerning apache commands)

    Configuration options relating specifically to user websites (accessed through

    localhost/~username) are in /etc/apache2/mods-available/userdir.conf and managed with thea2enmod and a2dismod commands.

    Installing suPHP

    suPHP is a tool for executing PHP scripts with the permissions of their owners. It consists of anApache module (mod_suphp) and a setuid root binary (suphp) that is called by the Apachemodule to change the uid of the process executing the PHP interpreter.

    Note: suPHP enforces, security and helps avoid file permission problems under developmentenvironments with several users editing the site files, but it also demands more memory and CPU

    usage, which can degrade your server performance under certain circumstances.

    To only install suPHP. useany methodto install the package

    libapache2-mod-suphp

    Enable this module by doing

    sudo a2enmod suphp

    then use a text editor such as "sudo nano" at the command line or "gksudo gedit" on the desktop

    to edit this file

    sudo nano /etc/apache2/mods-available/php5.conf

    or

    gksu "gedit /etc/apache2/mods-available/php5.conf"

    make a new empty line at the top of the content, then add

    make a new empty line at the bottom of the content, then add

    save changes

    https://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftwarehttps://help.ubuntu.com/community/InstallingSoftware
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    23/26

    For security reasons we need to specify to suPHP what are the document paths allowed toexecute scripts, use a text editor such as "sudo nano" at the command line or "gksudo gedit" onthe desktop to edit this file

    sudo nano /etc/suphp/suphp.conf

    or

    gksu "gedit /etc/suphp/suphp.conf

    find the value "docroot" and specify the document path of your site files, for example:

    docroot=/var/www/

    that value restrict script execution only to files inside "/var/www/"

    docroot=/var/www/:${HOME}/public_html

    that value restrict script execution only to files inside a custom home folder for each configureduser inside "/var/www/:${HOME}/public_html"

    for this tutorial we are going to use this value

    docroot=/home/user/public_html/

    which is the same Apache directory directive set before in this document

    save changes

    to restart Apache, type in your terminal

    sudo /etc/init.d/apache2 restart

    Now lets create a test script to see if suPHP is working correctly, in your terminal type

    echo "" | tee/home/user/public_html/whomi.php

    that command creates a quick php test file to display the current user executing the script

    open your browser and navigate to "localhost/whomi.php", most likely the browser will showyou a "500" server error, this is because suPHP does not allow too permissive file and folderpermissions and also does not allow mixed file and folder ownership, to correct this type in yourterminal

    sudo find /home/user/public_html/ -type f -exec chmod 644 {} \;sudo find /home/user/public_html/ -type d -exec chmod 755 {} \;sudo chown user:group -R /home/user/public_html/

  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    24/26

    those commands enforce a secure and correct file and folder permission and also set a correctuser and group ownership for all of them

    Now open your browser and navigate to "localhost/whomi.php", if everything went fine youshould see the name of the file owner executing the script and not "www-data" unless you

    specified so

    Run, Stop, Test, And Restart Apache

    Use the following command to run Apache :

    $ sudo /usr/sbin/apache2ctl start

    To stop it, use :

    $ sudo /usr/sbin/apache2ctl stop

    To test configuration changes, use :

    $ sudo /usr/sbin/apache2ctl configtest

    Finally, to restart it, run :

    $ sudo /usr/sbin/apache2ctl restart

    Alternatively, you can use a graphical interface by installingRapacheor the simplerlocalhost-indicator.

    Using Apache

    You can access apache by typing 127.0.0.1 orhttp://localhost(by default it will be listening onport 80) in your browser address bar. By default the directory for apache server pages is/var/www . It needs root access in order to put files in. A way to do it is just starting the filebrowser as root in a terminal:

    $ gksudo nautilus

    or

    if you want to make /var/www your own. (Use only for non-production web servers - this is notthe most secure way to do things.)

    $ sudo chown -R $USER:$USER /var/www

    Status

    https://launchpad.net/rapachehttps://launchpad.net/rapachehttps://launchpad.net/rapachehttps://launchpad.net/localhost-indicatorhttps://launchpad.net/localhost-indicatorhttps://launchpad.net/localhost-indicatorhttps://launchpad.net/localhost-indicatorhttp://localhost/http://localhost/http://localhost/http://localhost/https://launchpad.net/localhost-indicatorhttps://launchpad.net/localhost-indicatorhttps://launchpad.net/rapache
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    25/26

    To check the status of your PHP installation:

    $ gksudo "gedit /var/www/testphp.php"

    and insert the following line

    View this page on a web browser athttp://yourserveripaddress/testphp.phporhttp://localhost/testphp.php

    Securing Apache

    If you just want to run your Apache install as a development server and want to prevent it fromlistening for incoming connection attempts, this is easy to do.

    $ gksudo "gedit /etc/apache2/ports.conf"$ password:

    Change ports.conf so that it contains:

    Listen 127.0.0.1:80

    Save this file, and restart Apache (see above). Now Apache will serve only to your homedomain,http://127.0.0.1orhttp://localhost.

    Password-Protect a Directory

    There are 2 ways to password-protect a specific directory. The recommended way involves

    editing /etc/apache2/apache2.conf . (To do this, you need root access). The other way

    involves editing a .htaccessfile in the directory to be protected. (To do this, you need access tothat directory).

    Password-Protect a Directory With .htaccess

    SeeEnablingUseOfApacheHtaccessFiles

    Warning: On at least some versions of Ubuntu, .htaccessfiles will not work by default.

    SeeEnablingUseOfApacheHtaccessFilesfor help on enabling them.

    thumbnails

    If you direct your web browser to a directory (rather than a specific file), and there is no"index.html" file in that directory, Apache will generate an index file on-the-fly listing all thefiles and folders in that directory. Each folder has a little icon of a folder next to it.

    http://yourserveripaddress/testphp.phphttp://yourserveripaddress/testphp.phphttp://yourserveripaddress/testphp.phphttp://localhost/testphp.phphttp://localhost/testphp.phphttp://127.0.0.1/http://127.0.0.1/http://127.0.0.1/http://localhost/http://localhost/http://localhost/https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFileshttp://localhost/http://127.0.0.1/http://localhost/testphp.phphttp://yourserveripaddress/testphp.php
  • 7/25/2019 How to Install Wordpress on Ubuntu 14

    26/26

    To put a thumbnail of that specific image (rather than the generic "image icon") next to eachimage file (.jpg, .png, etc.):

    ... todo: add instructions on how to do thumbnails here, perhaps usingApache::AutoIndex 0.08

    orApache::Album 0.95...

    Known problems

    Skype incompatibility

    Skypeuses port 80 for incoming calls, and thus, may block Apache. The solution is to change theport in one of the applications. Usually, port 81 is free and works fine. To change the portnumber inSkypego to menu Tools > Options, then click on the Advanced tab, then in the box ofthe port for incoming calls write your preference.

    http://aspn.activestate.com/ASPN/CodeDoc/Apache-AutoIndex/AutoIndex.htmlhttp://aspn.activestate.com/ASPN/CodeDoc/Apache-AutoIndex/AutoIndex.htmlhttp://aspn.activestate.com/ASPN/CodeDoc/Apache-AutoIndex/AutoIndex.htmlhttp://aspn.activestate.com/ASPN/CodeDoc/Apache-Album/Album.htmlhttp://aspn.activestate.com/ASPN/CodeDoc/Apache-Album/Album.htmlhttp://aspn.activestate.com/ASPN/CodeDoc/Apache-Album/Album.htmlhttps://help.ubuntu.com/community/Skypehttps://help.ubuntu.com/community/Skypehttps://help.ubuntu.com/community/Skypehttps://help.ubuntu.com/community/Skypehttps://help.ubuntu.com/community/Skypehttps://help.ubuntu.com/community/Skypehttps://help.ubuntu.com/community/Skypehttp://aspn.activestate.com/ASPN/CodeDoc/Apache-Album/Album.htmlhttp://aspn.activestate.com/ASPN/CodeDoc/Apache-AutoIndex/AutoIndex.html