WordPress is available as a packaged application for Ubuntu. However it requires a bit of post installation configuration. The installation will install the apache2 multi-user server if no server is installed. I modified the installation to run over top of an existing site. The default installation creates directories under /var/www
, which I move to /srv
.
Initial setup
Install the wordpress
package using your preferred package manager. If you want email notifications to work you will also need to install php-mail
. Both packages can be installed with the command sudo aptitude install wordpress php-mail
.
Change directories to sudo bash /usr/share/doc/wordpress/examples
and run sudo bash setup-mysql wordpress www.example.com
to create the database and initial configuration. This will create the database and configure a virtual host with a document root for the site under /var/www
. This site is not configured for WordPress permalinks. Move /var/www/wp-uploads
and /var/www/www.example.com
to /srv
. Update /etc/wordpress/config-www.example.com.php
to reflect the moved directories. Create the file /etc/apache2/sites-available/example
with the following content.
## Virtual host VirtualDocumentRoot <VirtualHost *:80> ServerName www.example.com UseCanonicalName Off VirtualDocumentRoot /srv/www.example.com Options All ServerAdmin admin@www.example.com # Store uploads in /srv/wp-uploads/$0 RewriteEngine On RewriteRule ^/wp-uploads/(.*)$ /srv/wp-uploads/%{HTTP_HOST}/$1 </VirtualHost>
Create a symbolic link in /etc/apache2/sites-enabled
to this file and restart apache. Additional information and alternative configurations are documented in /usr/share/doc/wordpreess/examples/apache.conf
.
You can now login to the new WordPress installation and configure it.
Enabling permalinks
Ensure /etc/wordpress/htaccess
contains the following configuration.
# For rewrite rules needed for making WordPress URL friendly # See Options -> Permalinks for details and please use the defaults, # especially in mind when hosting several blogs on one machine! <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Link /etc/wordpress/htaccess
as .htaccess
in the document root of the site. Use a command like:
ln -s /etc/wordpress/htaccess /srv/www.example.com/.htaccess
Overlaying an Existing Site
This assumes that the index file in the root of the site is not index.php
. This approach can also be used if you wish to serve content from the site outside the control of WordPress
Remove the symbolic link /srv/www.examples.com
. Copy the existing site to /srv/www.examples.com
, or change the document root for the site to the existing site. Create symbolic links to the WordPress code inside the document root. Use a command like:
ln -s /usr/share/wordpress/* /etc/www.example.com
To ensure WordPress is the default application for the site add the following lines to /etc/wordpress/htaccess
.
<IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule>
The existing site content will be available by URL. Unavailable content will show the 404 page of your WordPress site.
Final Setup
Your WordPress site is now up and running. Follow the WordPress documentation to customize your site and add content. You may also want to files like favicon.ico
and robots.txt
to the document root.