To deploy an app on shared hosting, such as GoDaddy, and later on AWS, you can follow these general steps. I'll also provide some guidance on how to troubleshoot the 500 error you're encountering.
Deploying on Shared Hosting (GoDaddy)
-
Prepare Your Application:
- Ensure your application is ready for deployment. This includes setting up environment variables, configuring your database, and ensuring all dependencies are installed.
-
Upload Your Files:
- Use an FTP client (like FileZilla) to upload your application files to your GoDaddy hosting account. Typically, you will upload your files to the
public_htmldirectory.
- Use an FTP client (like FileZilla) to upload your application files to your GoDaddy hosting account. Typically, you will upload your files to the
-
Configure Your Environment:
- Create a
.envfile in the root of your application and configure it with your production settings (database credentials, app URL, etc.).
- Create a
-
Set Up Your Database:
- Use GoDaddy's cPanel to create a new database and user. Update your
.envfile with these credentials. - Run your database migrations using a tool like phpMyAdmin or through SSH if available.
- Use GoDaddy's cPanel to create a new database and user. Update your
-
Set File Permissions:
- Ensure that the storage and cache directories are writable. You can set permissions using your FTP client or through the cPanel file manager.
-
Update Your Web Server Configuration:
- Ensure your
.htaccessfile is correctly configured to handle URL rewriting if you're using a framework like Laravel.
- Ensure your
Troubleshooting 500 Errors
-
Check Error Logs:
- On GoDaddy, you can find error logs in the cPanel under the "Metrics" section, look for "Errors" or "Raw Access Logs".
- Alternatively, you can create a custom
error_logfile in your application directory by adding the following line to your.htaccessfile:php_value error_log /path/to/your/application/error_log
-
Enable Debugging:
- Temporarily enable debugging in your
.envfile by settingAPP_DEBUG=true. This will display detailed error messages in your browser. Remember to set it back tofalseafter troubleshooting.
- Temporarily enable debugging in your
Example .htaccess for Laravel
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Deploying on AWS
-
Set Up an EC2 Instance:
- Launch an EC2 instance with your preferred operating system (Ubuntu, Amazon Linux, etc.).
-
Install Required Software:
- SSH into your instance and install necessary software (Apache/Nginx, PHP, MySQL, etc.).
-
Upload Your Application:
- Use SCP or SFTP to upload your application files to the EC2 instance.
-
Configure Your Environment:
- Set up your environment variables and database configuration.
-
Set Up Your Web Server:
- Configure Apache or Nginx to serve your application. Ensure your virtual host configuration points to the correct directory.
-
Set Up a Database:
- You can use RDS for a managed database service or install MySQL directly on your EC2 instance.
Example Nginx Configuration for Laravel
server {
listen 80;
server_name your_domain.com;
root /path/to/your/application/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Conclusion
By following these steps, you should be able to deploy your application on both shared hosting and AWS. Make sure to check the error logs to troubleshoot the 500 error you're encountering. If you need more detailed guidance, there are many tutorials available on Laracasts and YouTube that cover deployment in depth.