AWS Lightsail - Using the aws-php-sdk to create instances
Introduction
1. Setting up a VirtualHost in OpenLiteSpeed.
2. Accessing the VirtualHost directory using Samba.
3. Creating a new project in the directory with PHPStorm.
4. Downloading and installing the AWS PHP SDK using Composer.
5. Creating the Lightsail Client.
Requirements
The following is a list of items needed to create instances successfully using the aws-php-sdk:
1) An easy to use IDE such as PHP Storm
2) The latest version of PHP. Available at php.net
3) The latest version of the AWS PHP SDK (Can be installed using composer)
4) A Linux server with the LAMP or LOMP stack installed and configured or a web control panel
5) A basic understanding of how to write PHP code.
Overview
The following is an overview of the steps covered in this tutorial:
1) Setup a virtualhost in OpenLiteSpeed
2) Access the virtualhost directory using Samba
3) Create a new project in PHPStorm
4) Download and install the aws-php-sdk
5) Create an AWS Lightsail PHP Client
Step 1: Setup a virtualhost in OpenLiteSpeed
cd /usr/local/lsws mkdir aws.local cd aws.local mkdir public_htmlOpen a new browser window and navigate to https://your-server-ip:7080. Enter your OpenLiteSpeed credentials on the login page to access the OLS webadmin dashboard. Click “Virtual Hosts” and click the “Add” button. Configure the following settings:
Virtual Host Name = aws.local Virtual Host Root = $SERVER_ROOT/aws.local Config File = $SERVER_ROOT/conf/vhosts/$aws.local/vhconf.conf Enable Scripts/ExtApps = Yes Restrained = No Max Keep-Alive Request = 1000Click on the “Save” button. An error message may be displayed informing you that the vhconf.conf file does not exist. Click on the “CLICK TO CREATE” link to create the file and click on the “Save” button to create the virtualhost. Click the “General” tab and configure the following settings:
Document Root = $VH_ROOT/public_html Domain Name = aws.local Domain Aliases = www.aws.local Enable GZIP Compression = Yes Enable Brotli Compression = YesClick on the “Save” button to save the settings. Scroll down and click the “Edit” button on “Index Files”. Configure the following settings:
Index Files = index.html, index.php Auto Index = NoClick the “Save” button and click on the “Rewrite” tab. Click “Edit” on “Rewrite Control” and set “Enable Rewrite” to “Yes”. Set “Auto Load from .htaccess” to “Yes” and click the “Save” button. Click the “Listeners” option on the webadmin menu list on the left and click “Edit” on the default listener. On “Virtual Host Mappings” click the “Add” button and configure the following settings:
Virtual Host = aws.local Domains = *Click the Save button and click the restart litespeed icon on the top right corner of the webadmin to restart the web server and apply changes. Open the hosts configuration file for your computer. If you are using a mac, the file is located in the /etc/ directory. If you are using a Windows device, the file should be found in the “c://windows/system32/drivers/etc/” directory. Add the following line in the hosts file:
192.168.88.100 aws.localReplace the above IP with the actual IP address of your web server.
Step 2: Access the virtualhost directory using Samba
sudo apt install sambaOnce Samba is installed, run the followinf command to open the smb.conf file:
sudo nano /etc/samba/smb.confAdd the bottom of the smb.conf file, add the following configuration:
[sambashare] comment = smb server path = /usr/local/lsws/ read only = no browsable = yesPress “CTRL + O” and press “CTRL + X” to save the changes made to the file. Run the following command to create a samba user:
sudo smbpasswd -a usernameReplace username with an actual username and set a good password. Run the following commands to restart samba so that the changes take effect:
sudo service smbd restart sudo ufw allow sambaOpen your Windows device and open the file explorer. Left click on “This PC” and click “Map network drive”. Select a drive name and enter “\\server-ip-address\sambashare” on the folder path. Click “Finish” and enter the samba credentials that you set. If you are using a mac, you can connect to the samba share in Finder. Click Menu and click “Go”. Click “Connect to Server” then enter “smb://server-ip-address”. Connect and enter your samba credentials when prompted. Once you connected successfully you should see the samba network folder in Finder or Windows file manager.
Step 3: Create a new project in PHPStorm
Open PHPStorm and click “Create New Project”. Click the browse button and open the Samba network share. Select the “aws.local” director and select the “public_html” directory. Click the “Open” button and PHPStorm will automatically use the selected directory to setup a PHP project.
In PHPStorm, right click on the “public_html” directory and click “Create New PHP File”.