Thursday, March 3, 2022

Themosis Framework - Laravel based wordpress setup on localhost

1) Download existing code and database and put code into htdocs and import sql file or if it is new setup, follow this url.

https://framework.themosis.com/docs/2.0/installation/

2) If wp_options has different domain on production, Use same domain in virtualhost for local setup. 

3) Point the domain upto htdocs (folder inside project root dir) and open it in browser.

4) If you get error

Unable to define the environment. / Unable to locate your environment configuration file. / Missing environment variables. / Error establishing a database connection
Solution :
Add your server's hostname in xyz.com/config/environment.php as a production value. In my case it is localserver.
<?php
return array(

    'local'         => ['xyz.local', 'xyz2.local'],
    'staging'       => 'dev.xyz.co.uk',
    'production'    => ['ip-172-16-150-95.eu-west-1.compute.internal', 'ip-172-31-13-11.eu-west-1.compute.internal', 'localserver']
);

5) Now if you get db connection error 'Error establishing a database connection'
Put correct database credentials and correct urls in xyz.com/.env.production.php
<?php
return [
    'DB_NAME'                       => 'xyz',
    'DB_USER'                       => 'admin',
    'DB_PASSWORD'                   => 'password',
    'DB_HOST'                       => 'localhost',
    'WP_HOME'                       => 'http://xyz.com',
    'WP_SITEURL'                    => 'http://
xyz.com/cms',
    'DEV_EMAIL'                     => 'developer@xyz.co.uk',
    'DEV_NAME'                      => '
developer',
]

6) If errors are resolved but it opens blank page in place of site, change owner of complete project to apache or www-data depends on it is centos or ubuntu.
sudo chown -R apache:apache xyz.com
It is not able to create files in xyz.com/storage/views, that's why you are getting blank page once necessary files are created, site can be opened.

7) After doing all above things but still you get 'Error establishing a database connection'. Check if you have created wp-config.php inside cms folder.
This creation is the reason of database connection error. There should be only one wp-config.php and it is in xyz.com/htdocs/wp-config.php
wp-admin Details :

http://xyz.co.in/cms/wp-login.php
Username - admin
Password - xxxxxxxxxxxxx
8) Fix issue 'Error establishing a database connection' in existing setup.
cd xyz.com          
nano config/environment.php
Remove same domain from staging and production.
nano .env.production.php
Make credentials and DB Variable correct.
rm htdocs/cms/wp-config.php
nano config/environment.php  
chown -R apache:apache storage/views/

Configure SNS service on AWS

To send sms in india, sns service should be configured in Singapore. Mumbai is not providing facility right now. 

To send sms in US, service should be configured in US region.

1) Open SNS in AWS Management Console.  

Create Topic (Topic name + Display name > create topic)

2) Create Subscription (ARN : Created Topic Name + Protocol : Email > Create subscription)

3) Create user in IAM and attach policy SNS full access.

4) Now try sending sms using python script 

pip3 install boto3

nano sms.py

    import boto3
    # Create an SNS client
    access_key = 'ACLAXXXXXXXXXXXXXZBA'
    secret = 'Zwxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    region = "ap-southeast-1"
    number = '+9199xxxxxxxx'
    sender_id = 'senderidname'
    sms_message = 'Your code: 123456'
    sns = boto3.client('sns', aws_access_key_id=access_key, aws_secret_access_key=secret, region_name=region)
    sns.publish(PhoneNumber=number, Message=sms_message, MessageAttributes={'AWS.SNS.SMS.SenderID': {'DataType': 'String', 'StringValue':     sender_id}, 'AWS.SNS.SMS.SMSType': {'DataType': 'String', 'StringValue': 'Transactional'}})
python sms.py 

5) If you do not receive sms then check error in cloudwatch but before it you need to enable the logs.
Click on Text Messaging (SMS) option > Text messaging preferences > Edit
Delivery status logging - optional > Create new service role

It will take you on IAM page and it will create roles for
SNS Success feedback and SNS Failure feedback > Allow

Once roles are created

Delivery status logging - optional > Use existing service role > add ARN of failure feedback
arn:aws:iam::360209543005:role/SNSFailureFeedback > save changes

Now errors will be reported in cloudwatch log group
check the error > cloudwatch > Log groups

 "delivery":
        "phoneCarrier": "Vodaphone - Kerela",
        "mnc": 90,
        "numberOfMessageParts": 1,
        "destination": "+9199xxxxxxxx",
        "priceInUSD": 0.00223,
        "smsType": "Promotional",
        "mcc": 404,
        "providerResponse": "Phone carrier has blocked this message",
        "dwellTimeMs": 172,
        "dwellTimeMsUntilDeviceAck": 669
    },
    "status": "FAILURE"
Phone carrier has blocked the sms that's why it is not delivered because you were sending promotional sms type.
You should have sent Transaction sms type.
Either select default sms type transactional
Click on Text Messaging (SMS) option > Text messaging preferences > Edit > Default message type > transactional
OR send message type in the code, just like above example did. Now message will be delivered.

Send message by sender ID
i) US does not support sender ID
ii) To send message in India by sender id
Generate request in support for sender ID.
https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-sms-awssupport-sender-id.html