You can deploy a repeatable LAMP stack on an Ubuntu VPS with one Ansible playbook: refresh APT metadata, install Apache, a MySQL-compatible server and PHP packages, then start and enable the services. The example below targets Ubuntu 24.04 and keeps the host address, SSH account, key and privilege settings in inventory variables so it works across VPS providers.
Antihost offers Linux VPS plans with full root access, unlimited traffic on a 1 Gbps port and a 14-day free trial.
The playbook is intentionally conservative. It uses Ubuntu’s distribution packages, makes service startup idempotent, verifies Apache and PHP locally, and leaves application-specific firewall rules, TLS, backups and database hardening as separate decisions.
As an Amazon Associate I earn from qualifying purchases.
What this deployment creates
LAMP is an acronym for Linux, Apache, MySQL-compatible database software and PHP. In this guide, Linux is Ubuntu 24.04 on a virtual private server. Apache serves HTTP, PHP executes dynamic application code, and the database stores application data.
Ansible runs from a control machine (your workstation, a CI runner or an administration server) and connects to the VPS over SSH. The managed host needs Python for Ansible modules; the ansible.builtin.apt module specifically requires python3-apt. Standard Ubuntu cloud images normally include it, but confirm that requirement when using a minimal image.
#1 Best Overall
- [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
- [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
- [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
- [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
- [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.
Decide the stack shape before writing tasks
| Decision | Choice in this example | When to choose another option |
|---|---|---|
| Ubuntu release | Ubuntu 24.04 LTS | Use the package names and PHP version supplied by the release installed on your VPS; do not copy names from a different release without checking APT. |
| Web server | Apache 2, package apache2 |
Use another web server only if the application’s deployment model requires it. |
| Database | Ubuntu’s mysql-server package |
Use mariadb-server when the application explicitly supports MariaDB and you have checked compatibility. |
| PHP integration | Apache PHP module, installed with libapache2-mod-php |
Use PHP-FPM when you need process-pool isolation, independent PHP workers or a proxy-based Apache configuration. The FPM package and Apache proxy configuration must match the PHP version in your Ubuntu release. |
| Package source | Ubuntu’s configured repositories | Add an additional repository only when the application needs a version unavailable in Ubuntu. The current Ansible documentation deprecates ansible.builtin.apt_repository in favor of ansible.builtin.deb822_repository. |
| Host layout | One VPS for Apache, PHP and the database | Split the web and database tiers when availability, load, isolation or independent scaling justifies the operational overhead. |
A single VPS is easy to operate and inexpensive to start, but it is one failure domain. Treat the database as a separate service boundary even when both services share the machine.
Prerequisites
- An Ubuntu 24.04 VPS with a routable address and an administrative SSH account.
- An SSH private key on the Ansible control machine. Prefer key authentication over a password.
- Ansible installed on the control machine and the ability to run
ansibleandansible-playbook. - Permission to use
sudoon the VPS. The playbook uses privilege escalation for package and service changes. - A DNS name, if you intend to serve a public site. DNS and TLS are separate from installing LAMP.
Providers use different default usernames, key paths and sudo policies. Keep those values in inventory rather than hard-coding them into tasks. Replace the example address and username with values supplied by your VPS provider.
Free tools Windows power users keep installed
One-click scans. No signup required.
Create an Ansible project and inventory
Create a directory on the control machine and an inventory file. The ansible_host value is the VPS address; ansible_user and ansible_ssh_private_key_file identify the SSH login.
mkdir -p lamp-ansible
cd lamp-ansible
cat > inventory.ini <<'EOF'
[lamp]
web ansible_host=203.0.113.10 ansible_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_ed25519
EOF
Do not use the documentation address above on a real deployment; substitute your VPS address. If the provider requires a nonstandard SSH port, add ansible_port=2222 to that host line. If the SSH account cannot sudo without a password, configure the appropriate become method and prompt for the password rather than storing it in the repository.
Test connectivity before changing anything:
ansible -i inventory.ini lamp -m ansible.builtin.ping
A successful result contains "ping": "pong". An unreachable result is an SSH, network, username, key or firewall problem; fix that first.
Rank #2
- 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
- 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
- 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
- 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
- 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
Write the idempotent LAMP playbook
Save the following as site.yml. The package list is explicit so a review of the playbook shows exactly what is installed. php-mysql supplies the PHP database driver used by many applications, while php-cli is useful for maintenance commands and deployment checks.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →---
- name: Install and run LAMP on Ubuntu
hosts: lamp
become: true
gather_facts: true
vars:
lamp_packages:
- apache2
- mysql-server
- php
- libapache2-mod-php
- php-mysql
- php-cli
tasks:
- name: Refresh the APT package index
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
- name: Install Apache, MySQL and PHP
ansible.builtin.apt:
name: "{{ lamp_packages }}"
state: present
- name: Ensure Apache is running and enabled at boot
ansible.builtin.service:
name: apache2
state: started
enabled: true
- name: Ensure MySQL is running and enabled at boot
ansible.builtin.service:
name: mysql
state: started
enabled: true
- name: Publish a temporary PHP verification page
ansible.builtin.copy:
dest: /var/www/html/ansible-lamp-check.php
owner: root
group: root
mode: '0644'
content: <?php echo "LAMP OK\n"; ?>
- name: Check that Apache serves the PHP page
ansible.builtin.uri:
url: http://127.0.0.1/ansible-lamp-check.php
return_content: true
status_code: 200
register: lamp_http_check
changed_when: false
failed_when: "'LAMP OK' not in lamp_http_check.content"
The apt task with update_cache: true refreshes the local package index before installation. The one-hour cache_valid_time prevents an unnecessary refresh on every run while still allowing regular updates. If the managed host lacks python3-apt, bootstrap that dependency using your provider’s image tooling or a one-time SSH command before running this playbook; the APT module cannot load without it.
state: present installs missing packages and does nothing when the requested versions are already installed. Likewise, state: started starts a stopped service but does not restart an already running one, and enabled: true configures startup after reboot. Avoid state: restarted in a normal convergence task: it always restarts the service, even when no configuration changed.
Run the playbook safely
- Review the inventory and confirm that the host is the intended VPS.
- Run a syntax check:
ansible-playbook -i inventory.ini site.yml --syntax-check. - Preview changes with check mode:
ansible-playbook -i inventory.ini site.yml --check. Package and service behavior in check mode can be less exact than a real run, so treat it as a preview rather than proof. - Apply the configuration:
ansible-playbook -i inventory.ini site.yml. - Run the same command again. A converged host should report no package or service changes; the verification task remains a read-only check.
The temporary check file proves that Apache answered locally and that PHP was interpreted rather than returned as source text. Remove it after verification or replace it with your application’s document root:
ansible -i inventory.ini lamp -b -m ansible.builtin.file
-a "path=/var/www/html/ansible-lamp-check.php state=absent"
Do not leave diagnostic pages that disclose environment information on a production site.
Recommended Free Tools
Rank #3
- [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
- [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
- [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
- [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
- [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by
Keep credentials and application configuration out of the playbook
The installation playbook does not create an application database user or password because those values differ by application and are secrets. Store credentials in Ansible Vault or an external secret manager, not in plaintext inventory, Git history or command-line arguments.
A minimal Vault workflow is:
ansible-vault create group_vars/lamp/vault.yml
ansible-playbook -i inventory.ini site.yml --ask-vault-pass
Inside the encrypted file, use names such as app_db_name, app_db_user and app_db_password. A separate database-configuration role can consume those variables and create the least-privileged account required by the application. Keep administrative database credentials separate from the account used by the web application.
Database hardening, removal of anonymous accounts, restriction of remote database access, backup schedules and restore tests should be explicit tasks with application-specific acceptance criteria. Installing the server package alone does not establish a backup or a recovery plan.
Configure the network, TLS and site after the base stack
At minimum, expose SSH and HTTP during initial setup. Once DNS points to the VPS and TLS is configured, serve the application over HTTPS and redirect HTTP. Restrict SSH to trusted source addresses where practical, use key authentication, and avoid exposing the database port to the public internet unless a documented architecture requires it.
Firewall policy belongs in its own role so a change can be reviewed independently of package installation. The same separation helps with TLS certificates, Apache virtual hosts, PHP settings, log rotation and application deployment. A working LAMP base is not a finished production security configuration.
Rank #4
- Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
- Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
- All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
- Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
- Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
Choose between common LAMP variants
| Variant | Advantages | Costs and checks |
|---|---|---|
| Apache module PHP | Few moving parts and a straightforward Ubuntu package installation; suitable for many traditional PHP applications. | PHP workers share Apache’s process model. Confirm that the application and its expected PHP settings are compatible. |
| Apache with PHP-FPM | Separate PHP worker pool, tunable process limits and clearer isolation between Apache and PHP. | Requires the FPM package, a matching Apache proxy configuration and pool sizing. Versioned package names vary by Ubuntu release. |
| Ubuntu database package | Integrates with Ubuntu updates and avoids maintaining another repository. | The exact MySQL-compatible implementation and version follow the Ubuntu release repositories. Check application compatibility before deployment. |
| Additional package repository | Can provide a required PHP or database version. | Adds signing keys, update responsibility and a larger change surface. Use ansible.builtin.deb822_repository for new repository definitions; apt_repository is deprecated in current Ansible documentation. |
| Single VPS | Simple networking, one inventory target and low operational overhead. | Web and database availability are coupled, and resource contention can affect both tiers. |
| Separate web and database hosts | Independent scaling, stronger isolation and the option to maintain the database privately. | Requires private networking, access controls, backups and more involved Ansible inventory and monitoring. |
Verify each layer when something fails
SSH or privilege escalation fails
Run the ping module, check the inventory hostname and address, and verify the SSH key permissions. If ping works but package tasks fail, test sudo for the Ansible user and confirm that the account is allowed to become root.
APT cannot update or install
Inspect the managed host’s repository configuration and outbound DNS and HTTPS access. An expired package index, a disabled Ubuntu repository or a held package can prevent installation. Confirm that python3-apt is installed before retrying the APT module.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesApache does not start
Check the service and configuration directly on the VPS with systemctl status apache2 and apachectl configtest. A port already occupied by another web server, an invalid virtual-host file or a permission error is more useful to fix than repeatedly restarting the service.
The PHP check returns source code or downloads
Apache is serving the file but PHP is not connected to it. Confirm that libapache2-mod-php installed successfully, inspect enabled Apache modules, and restart Apache only after a configuration change. If you selected PHP-FPM instead, verify the FPM socket and proxy configuration for the installed PHP version.
The database service is inactive
Inspect systemctl status mysql and the journal for the first startup error. Typical causes include an interrupted package configuration, insufficient disk space or a conflicting data directory. Correct the underlying error, then let Ansible enforce state: started again.
Best Value
The second Ansible run reports changes every time
Look for tasks that use timestamps, generated content or unconditional shell commands. Replace shell-based installation with package modules, use stable file modes and ownership, and reserve handlers or explicit restarts for changes that genuinely require them.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Operate the stack after installation
Keep the playbook in version control and pin changes through review. Run package updates deliberately, test the application after PHP or database upgrades, monitor disk space and service health, and make backups before schema or configuration changes. Test a restore on a separate location; a backup that has never been restored is only an assumption.
When the VPS reboots, the enabled: true settings cause Apache and MySQL to start through Ubuntu’s service manager. Ansible remains useful after boot: rerunning the playbook repairs drift, confirms required packages and services, and provides a repeatable record of the intended state.
Frequently Asked Questions
Can I use MariaDB instead of MySQL?
Yes, when the application supports MariaDB. Replace mysql-server with the Ubuntu release’s mariadb-server package and change the service name to the one provided by that package, then verify application compatibility and test the database migration path.
Why does the playbook refresh APT before installing packages?
The refresh downloads current package indexes from the configured Ubuntu repositories. Without an up-to-date index, a new VPS can report that packages are unavailable or install stale metadata.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallWhat makes the playbook idempotent?
Package tasks use state: present, service tasks use state: started with enabled: true, and the verification request is marked unchanged. Re-running the playbook therefore converges the host instead of reinstalling or restarting everything.
Should the database be on the same VPS as Apache?
A single VPS is appropriate for a simple deployment when its failure and resource limits are acceptable. Move the database to a separate private host when you need independent scaling, stronger isolation or higher availability, and then add the networking, credentials, backups and monitoring that design requires.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




