php-awsHow can I configure a PHP application to run on an EC2 instance using Nginx?
-
Install Nginx and PHP on the EC2 instance:
sudo apt-get update sudo apt-get install nginx sudo apt-get install php
-
Create a configuration file for Nginx:
sudo nano /etc/nginx/sites-available/example.com
server_name
- The domain name of the application.root
- The document root for the application.index
- The default page to be served when a directory is requested.location
- The directive to pass requests to the PHP interpreter.
server { server_name example.com; root /var/www/example.com/public_html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; } }
-
Enable the new configuration and restart Nginx:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ sudo systemctl restart nginx
-
Create a PHP file to test the configuration:
sudo nano /var/www/example.com/public_html/index.php
<?php phpinfo(); ?>
-
Visit the domain in a web browser to test the configuration:
http://example.com
Output:
PHP Version 7.2.24-0ubuntu0.18.04.4
Helpful links
More of Php Aws
- How can I use PHP to connect to an Amazon Aurora database?
- How do I use PHP to create a ZIP file on AWS?
- How can I use AWS and Zksync together with PHP?
- How can I use Yum to install PHP on an Amazon EC2 instance?
- How can I use an AWS SQS Worker with PHP?
- How can I use AWS WAF to secure my PHP application?
- How can I use AWS PHP SDK without credentials?
- How do I generate an AWS Signature Version 4 with PHP?
- How do I determine the version of PHP I am running on AWS?
- How can I use the AWS S3 S3Client library with PHP?
See more codes...