MOVED TO Repo for more easy management https://github.com/knm1993/Wordpress-with-api-basic-auth/tree/master
- create a wordpress server
- enable api
- api with authentication
- written by the
goodestBEST siuga
- Download Wordpress
- Unzip the wordpress zip then place into a server folder. (example: /home/ubuntu/var/www)
- Start a database of MYSQL with name "wordpress"
- Go to <http://example.com/wordpress/readme> following the instrustion
- The pre-config database should be working in the config setup.
- Login the panel
- Go to plugin
- Install "WordPress REST API Authentication" from the plugin market
- Enable the "WordPress REST API Authentication"
- Go to "WordPress REST API Authentication" setting from sidebar
- On "Configure API Authentication" tab, select Basic Auth as Authentication Method and Username : Password as Basic Auth Authentication Key
- Save configuration
- Complete!
Kernel
sudo nano /var/www/html/.htaccess
.htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Kernal
sudo service apache2 restart
Kernal
sudo nano /etc/apache2/apache.conf
apache.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
CHANGE None TO All in apache.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Kernal
sudo a2enmod rewrite
Kernal
sudo service apache2 restart
Endpoint:
(http://example.com/wordpress/wp-json/wp/v2/posts)
Method:
POST
Authorization:
Basic Auth - Username:Password
Header:
{
"Content-Type":"application/json"
}
Body:
{
"date":"2019-11-29 16:00:00",
"date_gmt":"2019-11-29 16:00:00",
"status":"publish",
"title":"PageTesto",
"content":"Standart Content"
}
Response:
{
"id": 5,
"date": "2019-11-29T16:00:00",
"date_gmt": "2019-11-29T08:00:00",
"guid": {
"rendered": "http://localhost/wordpress/?p=5",
"raw": "http://localhost/wordpress/?p=5"
},
"modified": "2019-11-29T16:00:00",
"modified_gmt": "2019-11-29T08:00:00",
"password": "",
"slug": "pagetesto",
"status": "future",
"type": "post",
"link": "http://localhost/wordpress/?p=5",
"title": {
"raw": "PageTesto",
"rendered": "PageTesto"
},
"content": {
"raw": "Standart Content",
"rendered": "<p>Standart Content</p>\n",
"protected": false,
"block_version": 0
},
"excerpt": {
"raw": "",
"rendered": "<p>Standart Content</p>\n",
"protected": false
},
"author": 1,
"featured_media": 0,
"comment_status": "open",
"ping_status": "open",
"sticky": false,
"template": "",
"format": "standard",
"meta": [],
"categories": [1],
"tags": [],
"permalink_template": "http://localhost/wordpress/2019/11/29/%postname%/",
"generated_slug": "pagetesto",
"_links": {
"self": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"collection": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts"
}
],
"about": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/types/post"
}
],
"author": [
{
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/users/1"
}
],
"replies": [
{
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/comments?post=5"
}
],
"version-history": [
{
"count": 0,
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5/revisions"
}
],
"wp:attachment": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/media?parent=5"
}
],
"wp:term": [
{
"taxonomy": "category",
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/categories?post=5"
},
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/tags?post=5"
}
],
"wp:action-publish": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-unfiltered-html": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-sticky": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-assign-author": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-create-categories": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-assign-categories": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-create-tags": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-assign-tags": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}
Endpoint:
(http://example.com/wordpress/wp-json/wp/v2/posts)
Method:
GET
Authorization:
Not Required
Header:
Not Required
Body:
Not Required
Response:
{
"id": 5,
"date": "2019-11-29T16:00:00",
"date_gmt": "2019-11-29T08:00:00",
"guid": {
"rendered": "http://localhost/wordpress/?p=5",
"raw": "http://localhost/wordpress/?p=5"
},
"modified": "2019-11-29T16:00:00",
"modified_gmt": "2019-11-29T08:00:00",
"password": "",
"slug": "pagetesto",
"status": "future",
"type": "post",
"link": "http://localhost/wordpress/?p=5",
"title": {
"raw": "PageTesto",
"rendered": "PageTesto"
},
"content": {
"raw": "Standart Content",
"rendered": "<p>Standart Content</p>\n",
"protected": false,
"block_version": 0
},
"excerpt": {
"raw": "",
"rendered": "<p>Standart Content</p>\n",
"protected": false
},
"author": 1,
"featured_media": 0,
"comment_status": "open",
"ping_status": "open",
"sticky": false,
"template": "",
"format": "standard",
"meta": [],
"categories": [1],
"tags": [],
"permalink_template": "http://localhost/wordpress/2019/11/29/%postname%/",
"generated_slug": "pagetesto",
"_links": {
"self": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"collection": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts"
}
],
"about": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/types/post"
}
],
"author": [
{
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/users/1"
}
],
"replies": [
{
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/comments?post=5"
}
],
"version-history": [
{
"count": 0,
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5/revisions"
}
],
"wp:attachment": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/media?parent=5"
}
],
"wp:term": [
{
"taxonomy": "category",
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/categories?post=5"
},
{
"taxonomy": "post_tag",
"embeddable": true,
"href": "http://localhost/wordpress/wp-json/wp/v2/tags?post=5"
}
],
"wp:action-publish": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-unfiltered-html": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-sticky": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-assign-author": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-create-categories": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-assign-categories": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-create-tags": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"wp:action-assign-tags": [
{
"href": "http://localhost/wordpress/wp-json/wp/v2/posts/5"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
}