Hosting A PHP Web Application On AWS: Difference between revisions
No edit summary |
No edit summary |
||
| Line 101: | Line 101: | ||
First initialize the eb environment with | First initialize the eb environment with | ||
<syntaxhighlight> | <syntaxhighlight lang="sh"> | ||
$ eb init | $ eb init | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 116: | Line 116: | ||
Zip the project with | Zip the project with | ||
<syntaxhighlight> | <syntaxhighlight lang="sh"> | ||
$ zip ../app-source.zip -r * .[^.]* | $ zip ../app-source.zip -r * .[^.]* | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| Line 122: | Line 122: | ||
Then from the directory where `.elasticbeanstalk/` is located, deploy with: | Then from the directory where `.elasticbeanstalk/` is located, deploy with: | ||
<syntaxhighlight> | <syntaxhighlight lang="sh"> | ||
$ eb deploy | $ eb deploy | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 20:55, 20 July 2018
Editing Hosting A PHP Web Application On AWS
Overview[edit]
Process (rough notes)[edit]
From the AWS Management Console home page > Build a solution group, click on Build a web app, which is a path to creating a new Elastic Beanstalk instance.
-- OR --
AWS Management Console > Services > Compute > Elastic Beanstalk.
Create New Application at the upper right.
Once the application is created, navigate to its management page, Actions dropdown (upper right) > Create environment
Create a web server environment[edit]
Select environment tier: Web server environment. Then click Select
- Environment name: appropriate token for the environment
- Domain: leave blank
- Platform: PHP, Python, Docker, etc.
- Applciation code: Upload your code
- In the next dialog there is an option to use a Public S3 URL, which might be simpler to maintain with Git, etc.? No, this process only accepts zip files, so using an S3 bucket would mean that there is a zip archive located at the URL. Also, Git is an option, but only after using Git to archive a repo.
- Version label: Include some indication of version in the token, e.g. version number or date.
- Click Create Environment to create and launch the new environment. This will create a new EC2 instance.
More configuration options[edit]
Click "Configure more options button to define additional properties for the web server.
For example, to create a database, or to define security properties for the EC2 instance linked to the web server.
Security[edit]
This panel controls key pairs for SSH access.
Virtual machine permissions > EC2 key pair > choose an existing key pair. (This is created via AWS Management Console > EC2 > Network & Security > Key Pairs)
When connecting to the EC2 instance via ssh, it's necessary that an inbound rule exists for ssh for the EC2 instance's security group. Under instance details, click on the security group > Inbound tab > Edit button. There should be a rule for SSH for the IP address of the machine that is used to ssh to the EC2 instance.
Instances (EC2)[edit]
Control over instance type and security types.
Once the environment is launched a url will be available that can be used to view the web site.
Database[edit]
Either select an existing snapshot, or create a new database.
For example, MariaDB is not available from the list of database types when creating a new database. In order to link the EBS to a MariaDB database, first create the MariaDB instance in the AWS RDS Management Console. Then create a snapshot of the database. Then select that snapshot when selecting a database for the EBS.
Security group rules must be configured to allow the EB instance to make connections to the RDS database.
- AWS Management Console > RDS > Instances > my instance > click for details
- Scroll down to the Connect pane to view a list of Security groups
- An inbound rule needs to exist for the VPC that was created for the EB instance.
- Scroll farther down on the RDS instance details page for the Details pane > Security and network > VPC > click on the VPC name to view its details, e.g. its IPv4 CIDR.
- Click on a CIDR/IP - Inbound security group to edit its settings.
- Security Groups listings page > Click on the row for the RDS's security group > Inbound tab > Edit button
- Type: e.g. MYSQL/Aurora, or appropriate database type
- Protocol: TCP
- Port range: 3306
- Source: VPC IPv4 CIDR value
Subdomains[edit]
Create subdomains as separate environments under the common EB application.
Configuration[edit]
From the EB on the the EB instance to view its properties.
Notifications - Enter an email address to receive notifications.
Updating app code[edit]
Source files are located at /var/app/current/
AWS Management Console[edit]
Zip the entire contents of the project (not including the parent folder).
- EBS Management Console > application > application versions
- Upload button
- Version label: name consistent with previous uploads
- Upload application: choose the zip file
- After upload completes select the application version > Deploy button.
- Select the environment that the code should be deployed to.
EB CLI[edit]
Installing eb cli on Mac OS[edit]
Use pip and not homebrew.
Updating app source without Git[edit]
First initialize the eb environment with
$ eb init
This will prompt for properties of the EB application and environment, and then store the configuration in ./.elasticbeanstalk/config.yml
Edit the config file with the path of the zip file to use for updating the app:
deploy: path/to/app-source.zip
Zip the project with
$ zip ../app-source.zip -r * .[^.]*
Then from the directory where .elasticbeanstalk/ is located, deploy with:
$ eb deploy
PHPStorm[edit]
It's possible to create a remote host for the EBS, but it is read-only.
- Type: SFTP
- SFTP hose: AWS EC2 Management console > EC2 instnace > IPv4 Public IP
- Root path: /var/app/current/
- User name: ec2-user
- Auth type: Key pair
- Private key file: path to .pem file
Importing data[edit]
Any MariaDB (or MySQL) client can be used to connect to the MariaDB database if it is publicly accessible, e.g. MySQLWorkbench. [1]
Retrieve the Endpoint from the AWS Management Console after loading the details of the MariaDB RDS instance. This is the host for the purposes of connecting to the database.
- Connect to the database with MySQLWorkbench.
- Management > Data Import/Restore
- Import from Self-Contained File > Select a dump of the source database
- 'Default Target Schema > Select database
- Dump Structure and Data
- Start Import button
Viewing server logs[edit]
TK
Pricing[edit]
See AWS Web Hosting Fundamentals
Notes[edit]
- ↑ Connecting to a DB Instance - AWS documentation