Skip to content

Instantly share code, notes, and snippets.

@xiarahman
Created December 25, 2024 10:57
Show Gist options
  • Save xiarahman/206357272b187e3d290bb90ee6127aea to your computer and use it in GitHub Desktop.
Save xiarahman/206357272b187e3d290bb90ee6127aea to your computer and use it in GitHub Desktop.
Install Magento on Ubuntu 24
Installing Magento 2.4 on Ubuntu 24 involves several steps, including installing necessary software prerequisites and configuring your environment. Here's a step-by-step guide:
---
### **Step 1: Update Your System**
1. Open the terminal and update the system packages:
```bash
sudo apt update && sudo apt upgrade -y
```
---
### **Step 2: Install Required Software**
1. **Install Apache2**:
```bash
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
```
2. **Install MySQL**:
```bash
sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysql
```
Secure MySQL installation:
```bash
sudo mysql_secure_installation
```
3. **Install PHP and Required Extensions**:
Magento 2.4 requires PHP 8.1 or 8.2. Install PHP 8.1:
```bash
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php8.1 libapache2-mod-php8.1 -y
```
Install necessary PHP extensions:
```bash
sudo apt install php8.1-bcmath php8.1-intl php8.1-mbstring php8.1-soap php8.1-xsl php8.1-curl php8.1-mysql php8.1-zip php8.1-opcache php8.1-gd php8.1-cli php8.1-common php8.1-fpm php8.1-json php8.1-readline -y
```
4. **Install Composer**:
Magento requires Composer for dependency management.
```bash
sudo apt install curl unzip -y
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
composer --version
```
5. **Install Elasticsearch**:
Magento 2.4 requires Elasticsearch. Install the latest compatible version:
```bash
sudo apt update
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.2-amd64.deb
sudo dpkg -i elasticsearch-8.10.2-amd64.deb
sudo systemctl enable elasticsearch.service
sudo systemctl start elasticsearch.service
```
---
### **Step 3: Configure Apache**
1. Enable Apache modules:
```bash
sudo a2enmod rewrite
sudo a2enmod ssl
sudo systemctl restart apache2
```
2. Create a virtual host configuration file for Magento:
```bash
sudo nano /etc/apache2/sites-available/magento.conf
```
Add the following configuration:
```apache
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/magento_error.log
CustomLog ${APACHE_LOG_DIR}/magento_access.log combined
</VirtualHost>
```
Enable the site:
```bash
sudo a2ensite magento.conf
sudo systemctl reload apache2
```
---
### **Step 4: Configure MySQL Database**
1. Log in to MySQL:
```bash
sudo mysql -u root -p
```
2. Create a database and user for Magento:
```sql
CREATE DATABASE magento;
CREATE USER 'magento_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON magento.* TO 'magento_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
```
---
### **Step 5: Install Magento**
1. Navigate to the web root:
```bash
cd /var/www/html
```
2. Download Magento using Composer:
```bash
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento
```
Enter Magento authentication keys from your Magento Marketplace account when prompted.
3. Set permissions:
```bash
sudo chown -R www-data:www-data /var/www/html/magento
sudo chmod -R 775 /var/www/html/magento
```
---
### **Step 6: Finalize Installation**
1. Install Magento using the CLI:
```bash
php /var/www/html/magento/bin/magento setup:install \
--base-url=http://yourdomain.com \
--db-host=localhost \
--db-name=magento \
--db-user=magento_user \
--db-password=secure_password \
--admin-firstname=Admin \
--admin-lastname=User \
[email protected] \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/New_York \
--cleanup-database \
--sales-order-increment-prefix="ORD$" \
--use-rewrites=1
```
---
### **Step 7: Access Magento**
1. Open your web browser and visit `http://yourdomain.com` to see the Magento storefront.
2. Visit `http://yourdomain.com/admin` to access the admin panel.
---
@xiarahman
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment