User Tools

Site Tools


wordpress:install_wordpress

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
wordpress:install_wordpress [2016/10/18 19:18] – created peterwordpress:install_wordpress [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 121: Line 121:
 ===== Copy Files to the Document Root ===== ===== Copy Files to the Document Root =====
  
 +Now that we have our application configured, we need to copy it into the WebServer's document root, where it can be served to visitors of our website.
  
-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 rsync command.  This preserves permissions and has good data integrity features.
  
-One of the easiest and most reliable way of transferring files from directory to directory is with the rsync command. This preserves permissions and has good data integrity features. +The location of the document root in the Ubuntu 14.04 is **/var/www/html/** We can transfer our WordPress files there by typing:
- +
-The location of the document root in the Ubuntu 14.04 LAMP guide is /var/www/html/. We can transfer our WordPress files there by typing:+
  
 +<code bash>
 sudo rsync -avP ~/wordpress/ /var/www/html/ sudo rsync -avP ~/wordpress/ /var/www/html/
 +</code>
  
 This will safely copy all of the contents from the directory you unpacked to the document root. This will safely copy all of the contents from the directory you unpacked to the document root.
Line 134: Line 135:
 We should now move into the document root to make some final permissions changes We should now move into the document root to make some final permissions changes
  
 +<code bash>
 cd /var/www/html cd /var/www/html
 +</code>
  
 You will need to change the ownership of our files for increased security. 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 plan on using to interact with your site. This can be your regular user if you wish, but some may suggest that you create an additional user for this process. It is up to you which you choose.+We want to give user ownership to the regular, non-root user (with sudo privileges) that you plan on using to interact with your site.  This can be your regular user if you wish, but some may suggest 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 the initial server setup guide, which we called demo. This is the account I am performing all of the actions of this guide as.+For this guide, we will use the same account that we set up during the initial server setup guide, which we called www-data 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 allow Apache to interact with the content as necessary.+The group ownership we will give to our web server process, which is **www-data** This will allow the WebServer to interact with the content as necessary.
  
 We can quickly assign these ownership values by typing: We can quickly assign these ownership values by typing:
  
-sudo chown -R demo:www-data *+<code bash> 
 +sudo chown -R www-data:www-data * 
 +</code>
  
 This will set up the ownership properties that we are looking for. 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 assigning correct ownership on our uploads directory. This will allow us to upload images and other content to our site. Currently, the permissions are too restrictive.+While we are dealing with ownership and permissions, we should also look into assigning correct ownership on our uploads directory.  This will allow us to upload images and other content to our site.  Currently, the permissions are too restrictive.
  
-First, let's manually create the uploads directory beneath the wp-content directory at our document root. This will be the parent directory of our content:+First, let's manually create the uploads directory beneath the **wp-content** directory at our document root.  This will be the parent directory of our content:
  
 +<code bash>
 mkdir /var/www/html/wp-content/uploads mkdir /var/www/html/wp-content/uploads
 +</code>
  
-We have a directory now to house uploaded files, however the permissions are still too restrictive. We need to allow the web server itself to write to this directory. We can do this by assigning group ownership of this directory to our web server, like this:+We have a directory now to house uploaded files, however the permissions are still too restrictive.  We need to allow the web server itself to write to this directory. We can do this by assigning group ownership of this directory to our web server, like this:
  
-sudo chown -R :www-data /var/www/html/wp-content/uploads+<code bash> 
 +sudo chown -R www-data:www-data /var/www/html/wp-content/uploads 
 +</code>
  
 This will allow the web server to create files and directories under this directory, which will permit us to upload content to the server. This will allow the web server to create files and directories under this directory, which will permit us to upload content to the server.
-Step Five — Complete Installation through the Web Interface+ 
 + 
 +===== Modify Nginx Server Blocks ===== 
 + 
 +If using Apache, just ignore this entire paragraph. 
 + 
 +We have our files and directories configured.  Now we need to modify our nginx configuration to serve the content correctly. 
 + 
 +We can use the default nginx server block as a base for our new server block.  Copy it over like this: 
 + 
 +<code bash> 
 +sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress 
 +</code> 
 + 
 +Open the new file we made so that we can make some changes: 
 + 
 +<code bash> 
 +sudo vi /etc/nginx/sites-available/wordpress 
 +</code> 
 + 
 +We will want to make the following changes: 
 + 
 +<file nginx /etc/nginx/sites-available/wordpress> 
 +server { 
 +        listen 80 default_server; 
 +        listen [::]:80 default_server ipv6only=on; 
 + 
 +        root /var/www/html; 
 +        index index.php index.html index.htm; 
 + 
 +        server_name your_domain.com; 
 + 
 +        location / { 
 +                # try_files $uri $uri/ =404; 
 +                try_files $uri $uri/ /index.php?q=$uri&$args; 
 +        } 
 + 
 +        error_page 404 /404.html; 
 + 
 +        error_page 500 502 503 504 /50x.html; 
 +        location = /50x.html { 
 +                root /usr/share/nginx/html; 
 +        } 
 + 
 +        location ~ \.php$ { 
 +                try_files $uri =404; 
 +                fastcgi_split_path_info ^(.+\.php)(/.+)$; 
 +                fastcgi_pass unix:/var/run/php5-fpm.sock; 
 +                fastcgi_index index.php; 
 +                include fastcgi_params; 
 +        } 
 +
 +</file> 
 + 
 +A summary of changes that you should be making are: 
 + 
 +  * Change the value of the **root** directive to point to our new document root at **/var/www/html**. 
 +  * Modify the **index** parameter to look for an **index.php** file before the other files. 
 +  * Change the value of the **server_name** directive to point to your server's domain name or IP address. 
 +  * Adjust the **try_files** within the **location /** block to send requests to PHP when they do not exactly match. 
 + 
 +Some of these might already be set from your LEMP installation.  When you are finished with these changes, save and close the file. 
 + 
 +We need to link our new file to the **sites-enabled** directory in order to activate it.  We can do that like this: 
 + 
 +<code bash> 
 +sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ 
 +</code> 
 + 
 + 
 +The file we just linked conflicts with our old default file, since it borrowed so much from it.  We need to disable the old file: 
 + 
 +<code bash> 
 +sudo rm /etc/nginx/sites-enabled/default 
 +</code> 
 + 
 +Now, restart the web server and PHP processor to enable our changes: 
 + 
 +<code bash> 
 +sudo service nginx restart 
 +sudo service php5-fpm restart 
 +</code> 
 + 
 + 
 +===== Complete Installation through the Web Interface =====
  
 Now that you have your files in place and your software is configured, you can complete the installation through the web interface. Now that you have your files in place and your software is configured, you can complete the installation through the web interface.
Line 167: Line 260:
 In your web browser, navigate to your server's domain name or public IP address: In your web browser, navigate to your server's domain name or public IP address:
  
 +<code>
 http://server_domain_name_or_IP http://server_domain_name_or_IP
 +</code>
  
 You will see the WordPress initial configuration page, where you will create an initial administrator account: You will see the WordPress initial configuration page, where you will create an initial administrator account:
 +
 +{{:wordpress:wordpress_initial_config.png|}}
 +
 +Fill out the information for the site and the administrative account you wish to make.  When you are 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 just created:
 +
 +{{:wordpress:wordpress_confirm_install.png|}}
 +
 +Hit the button at the bottom and then fill out your account information:
 +
 +{{:wordpress:wordpress_login.png|}}
 +
 +You will be presented with the WordPress interface:
 +
 +{{:wordpress:wordpress_admin_interface.png|}}
 +
 +
 +===== Configure Apache Pretty Permalinks for WordPress (Optional) =====
 +
 +If using NginX then either ignore this entire section or adjust accordingly.
 +
 +By default, WordPress creates URLs dynamically that look something like this:
 +
 +<code>
 +http://server_domain_name_or_IP/?p=1
 +</code>
 +
 +This isn't exactly the most useful interface for visitors or search engines, so most users want to modify this.  WordPress has the ability to create "pretty" permalinks which will clean up the URL into a more human-friendly format.
 +
 +There are a few things we need to do to get this to work with Apache on Ubuntu.
 +
 +
 +==== Modifying Apache to Allow URL Rewrites ====
 +
 +First, we need to modify the Apache virtual host file for WordPress to allow for .htaccess overrides.  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 another configuration file:
 +
 +<code bash>
 +sudo vi /etc/apache2/sites-available/000-default.conf
 +</code>
 +
 +Inside of this file, we want to set up a few things.  We should set the **ServerName** and create a directory section where we allow overrides.  This should look something like this:
 +
 +<file apache /etc/apache2/sites-available/000-default.conf>
 +<VirtualHost *:80>
 +    ServerAdmin webmaster@localhost
 +    DocumentRoot /var/www/html
 +    ServerName server_domain_name_or_IP
 +    <Directory /var/www/html/>
 +        AllowOverride All
 +    </Directory>
 +    . . .
 +</file>
 +
 +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 this by typing:
 +
 +<code bash>
 +sudo a2enmod rewrite
 +</code>
 +
 +After you have made these changes, restart Apache:
 +
 +<code bash>
 +sudo service apache2 restart
 +</code>
 +
 +
 +==== Create an .htaccess File ====
 +
 +Now that Apache is configured to allow rewrites through **.htaccess** files, we need to create an actual file.
 +
 +You need to place this file in your document root.  Type this to create an empty file:
 +
 +<code bash>
 +touch /var/www/html/.htaccess
 +</code>
 +
 +This will be created with your username and user group. We need the web server to be the group owner though, so we should adjust the ownership by typing:
 +
 +<code bash>
 +sudo chown :www-data /var/www/html/.htaccess
 +</code>
 +
 +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 this file, it can implement the rules automatically.  If it does not, you will have to manually edit this file 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 some say that it is an unnecessary security risk.
 +
 +If you want WordPress to automatically update this file with rewrite rules, you can ensure that it has the correct permissions to do so by typing:
 +
 +<code bash>
 +chmod 664 /var/www/html/.htaccess
 +</code>
 +
 +If you want to update this file manually for the sake of a small security gain, you can allow the web server only read privileges by typing:
 +
 +<code bash>
 +chmod 644 /var/www/html/.htaccess
 +</code>
 +
 +
 +==== Change the Permalink Settings in WordPress ====
 +
 +When you are finished doing the server-side changes, you can easily adjust the permalink settings through the WordPress administration interface.
 +
 +On the left-hand side, under the Settings menu, you can select Permalinks:
 +
 +{{:wordpress:wordpress_perma_settings.png|}}
 +
 +You can choose any of the preconfigured settings to organize URLs, or you can create your own.
 +
 +{{:wordpress:wordpress_perma_options.png|}}
 +
 +When you have made your selection, click "Save Changes" to generate the rewrite rules.
 +
 +If you allowed the web server write access to your .htaccess file, you should see a message like this:
 +
 +{{:wordpress:wordpress_perma_update.png|}}
 +
 +If you did not allow the web server write access to your .htaccess file, you will be provided with 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:
 +
 +<code bash>
 +vi /var/www/html/.htaccess
 +</code>
 +
 +This should give you the same functionality.
 +
 +
 +===== Conclusion =====
 +
 +You should now have a WordPress instance up and running.
 +
 +
 +===== References =====
 +
 +https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-on-ubuntu-14-04
 +
 +https://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu-14-04
 +
wordpress/install_wordpress.1476818299.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki