Pages

Set Up WordPress with Optimal .htaccess Settings

Thứ Sáu, 15 tháng 9, 2017

If you are a WordPress user then you probably have met the .htaccess file. The .htaccess file allows you to make configuration changes on a per-directory basis and it is very useful in case you want to enable/disable additional functionality and features for your site. In this tutorial, we are going to show you how to set up a basic WordPress site with optimal .htaccess settings on a VPS running Ubuntu 16.04 as an operating system.

Update the packages on Ubuntu

It is very important to keep all your software up to date, so once you connect to your Linux VPS via SSH update the software to the latest version by using the following commands:
sudo apt-get update
sudo apt-get upgrade

Install WordPress on Ubuntu

First of all, create a directory for the WordPress files and download the latest version of WordPress:
sudo mkdir /var/www/html/wordpress
cd /var/www/html/wordpress
sudo wget https://wordpress.org/latest.zip
Extract the archive and set the proper ownership:
sudo unzip latest.zip
sudo mv wordpress/* .
sudo rm -rf latest.zip wordpress
sudo mv wp-config-sample.php wp-config.php
sudo chown -R www-data: /var/www/html/wordpress
Next step is to create a MySQL database and user for the new WordPress site. Log in to the MySQL database server:
mysql -u root -p
Run the following commands:
mysql> CREATE DATABASE wordpressdb;
mysql> GRANT ALL PRIVILEGES on wordpressdb.* to 'wordpressuser'@'localhost' identified by 'PaSsW0rD';
mysql> FLUSH PRIVILEGES;
mysql> EXIT
Now, edit the wp-config.php file and change the database settings:
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');

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

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

/** MySQL hostname */
define('DB_HOST', 'localhost');
Create virtual host for the new WordPress site:
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
Paste the following lines:
<VirtualHost *:80>
 ServerAdmin admin@yourdomain.com
 DocumentRoot /var/www/html/wordpress
 ServerName yourdomain.com
 ServerAlias www.yourdomain.com

 <Directory /var/www/html/wordpress/>
  Require all granted
 </Directory>
 
 ErrorLog /var/log/apache2/yourdomain.com-error_log
 CustomLog /var/log/apache2/yourdomain.com-access_log common
</VirtualHost>
Enable the new virtual host and reload Apache for the changes to take effect:
sudo a2ensite yourdomain.com.conf
sudo systemctl reload apache2
Now you should be able to access the WordPress site via web browser by using your domain name.

Subscribe your email address now to get the latest articles from us

Không có nhận xét nào:

Đăng nhận xét

 
Copyright © 2015. VPS Review.
Design by Herdiansyah Hamzah. Published by Themes Paper. Powered by Blogger.
Creative Commons License