Self-Hosting
Self-hosting lua.sh allows you to have full control over your URL shortening service, ensuring scalability, reliability, and performance. Below is a generic guideline to set up lua.sh while respecting the recommended minimum infrastructure.
Recommended Minimum Infrastructure
To achieve optimal performance and scalability, we recommend the following server configuration:
- Load Balancer: Distributes traffic between application servers for better reliability and redundancy.
- 2 PHP Machines: Handles the application logic and serves requests.
- Redis Machine or Cluster: Manages caching and queues to ensure smooth operations.
- MySQL Database Machine or Cluster: Stores and manages your data efficiently.
The minimum recommended configuration is 1 core and 1GB RAM for each machine. However, you may need to adjust based on your traffic and performance requirements.
Schema Overview
User
|
v
Load Balancer
|
+-------------------------------+
| |
v v
PHP Server 1 PHP Server 2
| |
+-------------+ +-------------+
| | | |
v v v v
Redis MySQL Redis MySQL
Load Balancer
- Purpose: Directs incoming traffic to your PHP machines, balancing the load and improving reliability.
- Requirements: Configured with health checks to monitor the availability of application servers.
- Optional Enhancements:
- Sticky sessions, if needed.
- SSL termination for secure communication.
PHP Machines
- Purpose: Runs the application code, processes user requests, and interfaces with Redis and the database.
- Configuration:
- Deploy lua.sh and ensure the environment variables (
.env
) are consistent across all PHP machines. - Use file synchronization or a shared file system for consistency in file uploads and other shared resources.
- Configure queue workers using a process manager like Supervisor or Systemd.
- Deploy lua.sh and ensure the environment variables (
- Scaling: Add more PHP machines to handle increased traffic.
Redis Machine
- Purpose: Provides fast caching and queue management for optimal performance.
- Configuration:
- Set a secure password and restrict access to trusted application servers.
- Update your
.env
file on PHP machines with the Redis server details.
- Scaling: As traffic grows, consider scaling vertically (larger machine) or horizontally (clustering).
Database Machine
- Purpose: Stores application data securely and reliably.
- Configuration:
- Use a relational database (e.g., MySQL or MariaDB).
- Ensure database backups are set up and tested regularly.
- Optimize your database for high performance (e.g., indexing, query optimization).
- Scaling:
- For read-heavy workloads, set up replication with a primary database and read replicas.
- For write-heavy workloads, consider sharding or a larger instance.
General Deployment Tips
- Environment Variables:
- Ensure all machines share consistent
.env
files, particularly for database and Redis configurations. - Configure the
APP_URL
to point to your load balancer or main domain.
- Monitoring and Logging:
- Enable logging on all machines to track errors and performance.
- Set up monitoring tools to observe resource usage (CPU, memory, disk, etc.) and application metrics.
- Security:
- Use firewalls to restrict access between servers.
- Enable HTTPS for all external traffic.
- Regularly update your application and server software.
- Backups:
- Regularly back up your database.
- If applicable, back up Redis data and application files (e.g., uploads).
- Scaling:
- As traffic increases, you can scale each component independently:
- Add more PHP machines.
- Scale Redis and database machines vertically or horizontally.