Setting up Magento 1 with Ansible involves creating a playbook that automates the installation process. This includes configuring the server, installing necessary dependencies, setting up the database, and installing Magento 1. Here’s a structured Ansible playbook to help you install Magento 1 on an Ubuntu server.
Prerequisites:
Directory Structure:
mkdir -p magento1-setup/{tasks,templates,vars}
cd magento1-setup
Create Files:
main.yml: The main playbook.tasks/: Folder for individual tasks.vars/main.yml: Variables for the playbook, such as database name and passwords.vars/main.ymlIn this file, set variables such as MySQL root password, Magento database, and admin credentials.
# vars/main.yml
mysql_root_password: "secure_root_password"
magento_db_name: "magento1"
magento_db_user: "magento_user"
magento_db_password: "secure_password"
magento_admin_user: "admin"
magento_admin_password: "admin123"
magento_admin_email: "admin@example.com"
magento_base_url: "http://yourdomain.com"
If you need to configure files like php.ini or the Apache virtual host file, you can create them in the templates/ directory.
main.yml)The following is a complete playbook for setting up Magento 1.
# main.yml
---
- hosts: magento_servers
become: true
vars_files:
- vars/main.yml
tasks:
- name: Update and upgrade apt packages
apt:
update_cache: yes
upgrade: dist
- name: Install required packages
apt:
name:
- apache2
- mysql-server
- php5.6
- php5.6-mysql
- php5.6-curl
- php5.6-xml
- php5.6-mbstring
- php5.6-intl
- php5.6-gd
- php5.6-zip
- unzip
- curl
state: present
- name: Enable Apache modules
command: a2enmod rewrite
notify: restart apache
- name: Start and enable Apache
service:
name: apache2
state: started
enabled: true
- name: Start and enable MySQL
service:
name: mysql
state: started
enabled: true
- name: Set MySQL root password
mysql_user:
login_user: root
name: root
password: "{{ mysql_root_password }}"
host_all: true
- name: Create Magento database
mysql_db:
name: "{{ magento_db_name }}"
state: present
- name: Create Magento database user
mysql_user:
name: "{{ magento_db_user }}"
password: "{{ magento_db_password }}"
priv: "{{ magento_db_name }}.*:ALL"
state: present
- name: Download Magento 1
get_url:
url: "https://example.com/magento1.zip" # Replace with the actual Magento 1 download URL
dest: /tmp/magento1.zip
- name: Extract Magento
unarchive:
src: /tmp/magento1.zip
dest: /var/www/html/
remote_src: yes
- name: Set permissions for Magento directory
file:
path: /var/www/html/magento1
owner: www-data
group: www-data
recurse: yes
- name: Configure Apache virtual host for Magento
template:
src: templates/magento1-vhost.conf.j2
dest: /etc/apache2/sites-available/magento1.conf
notify: restart apache
- name: Enable Magento site
command: a2ensite magento1.conf
notify: restart apache
- name: Disable default site
command: a2dissite 000-default.conf
notify: restart apache
- name: Set PHP memory limit and max execution time
lineinfile:
path: /etc/php/5.6/apache2/php.ini
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
state: present
loop:
- { regexp: '^memory_limit', line: 'memory_limit = 512M' }
- { regexp: '^max_execution_time', line: 'max_execution_time = 18000' }
notify: restart apache
- name: Run Magento setup script
shell: |
php /var/www/html/magento1/install.php \
--license_agreement_accepted yes \
--locale en_US \
--timezone America/Chicago \
--default_currency USD \
--db_host localhost \
--db_name "{{ magento_db_name }}" \
--db_user "{{ magento_db_user }}" \
--db_pass "{{ magento_db_password }}" \
--url "{{ magento_base_url }}" \
--skip_url_validation yes \
--use_rewrites yes \
--use_secure no \
--secure_base_url "{{ magento_base_url }}" \
--use_secure_admin no \
--admin_lastname Admin \
--admin_firstname Admin \
--admin_email "{{ magento_admin_email }}" \
--admin_username "{{ magento_admin_user }}" \
--admin_password "{{ magento_admin_password }}"
handlers:
- name: restart apache
service:
name: apache2
state: restarted
Create a file templates/magento1-vhost.conf.j2 with the following content:
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/magento1
ServerName {{ magento_base_url }}
<Directory /var/www/html/magento1>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/magento1_error.log
CustomLog ${APACHE_LOG_DIR}/magento1_access.log combined
</VirtualHost>
Save your work and run the playbook:
ansible-playbook -i hosts main.yml
Check the Magento Installation:
vars/main.yml (e.g., http://yourdomain.com).This playbook will automatically set up Magento 1 with Apache, MySQL, and PHP 5.6 on an Ubuntu server. Make sure to update the playbook with the actual download URL for Magento 1, as Magento 1 is no longer officially available from Adobe.