Step by step Magento 2 Installation on Oracle Cloud Infrastructure Using Ubuntu 18.04
Adnan Ahmed Siddiqui
Digitalisation Expert | Project Manager | AI Enthusiast
Today, we are going to install Magento2 on the Oracle cloud platform. You can use these steps to install magento2 in any other cloud platform using Ubuntu 18.04.
Step 1: Setup Compute Instance
Setup a compute instance on the oracle cloud, here we are going to use Canonical Ubuntu 18.04 with at least 1 CPU and 4 GB memory.
Remember Don’t forget to assign public IP and place your instance in Public Subnet.
After creating an instance, you will get a public IP for your virtual server. Copy and store it safely. We will need this to connect to the server via SSH.
Step 2: Connect it via SSH
Connect to your instance via SSH and perform commands below, if you don't know how to connect via SSH follow this Guide
Your SSH command should looks like this:?
ssh –i <private_key_file> <username>@<public-ip-address>
<private_key_file> is the full path and name of the file that contains the private key associated with the instance you want to access.
<username> is the default username for the instance. For Oracle Linux and CentOS images, the default username is opc. For Ubuntu images, the default username is ubuntu.
<public-ip-address> is your instance IP address that you retrieved from the Console.
Step 3: Installing Apache2 Server on Ubuntu 18.04
sudo apt update && sudo apt install apache2
sudo systemctl restart apache2
Step 4: Configure Firewall
The Ubuntu firewall is disabled by default. However, you still need to update your iptables configuration to allow HTTP traffic. Update iptables with the following commands.
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT
sudo netfilter-persistent save
The commands add a rule to allow HTTP traffic and saves the changes to the iptables configuration files.
?You can now test your server.
You can test your server from the command line with curl localhost. Or, you can connect your browser to your public IP address assigned to your instance: https://<x.x.x.x>. The page looks similar to:
If you get any error you may also try to run below commands
sudo ufw allow OpenSSH
sudo ufw allow in “Apache Full”
sudo ufw enable
Step 5: Installing Repositories
This command is necessary to get the required repository for future Magento 2 Installation and other PHP compatible repositories.
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
Next Step is to modify the “000-default.conf” available in apache2 directory by using the below command.
sudo nano /etc/apache2/sites-available/000-default.conf
Add below content after <VirtualHost *:80> and before ending of </VirtualHost> in the opened file.
DocumentRoot /var/www/html/magento2/
<Directory /var/www/html/magento2/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Now edit the apache2 conf file using below command
sudo nano /etc/apache2/apache2.conf
Enter the obtained IP address from your compute instance.
ServerName your_server_IP_address
Now test the configuration
sudo apachectl configtest
sudo a2enmod rewrite
sudo systemctl restart apache2
Step 6: Magento 2 Installation – Installing PHP 7.3
We have to run the following command to install required PHP extensions which are mandatory for Magento 2 installation. So that we combined all PHP extension installation commands in one sentence by minimising further lines of commands.
sudo apt-get install php7.3 libapache2-mod-php7.3 php7.3-mysql php7.3-soap php7.3-bcmath php7.3-xml php7.3-mbstring php7.3-gd php7.3-common php7.3-cli php7.3-curl php7.3-intl php7.3-xmlrpc php7.3-json php-imagick php7.3-zip zip unzip -y
Now edit apache conf
sudo nano /etc/apache2/mods-enabled/dir.conf
Enter the “index.php” in the editor file. As shown below.
<IfModule mod_dir.c
????????DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>>
Restart or Reload Apache2 Server using following command.
sudo systemctl restart apache2
Step 7: Install MySQL
sudo apt update && sudo apt install mysql-server
Check the running status of installed MySQL by following command
sudo service mysql status
Installing MySQL Security
sudo mysql_secure_installation
Hit Enter, it asks you for strong password input, then press “2” for strong password and press “y” wherever is needed till last.
If you want to check the version of installed MySQL then run the following command.
sudo mysqladmin -p -u root version
NOTE: if you are using managed MySQL Database in OCI please follow these steps here to bind your SQL conf to your DB server, You need to add Ingress rules to your VPC subnets see here.
Step 8: Installing phpMyAdmin
sudo apt-get install phpmyadmin php7.2-mbstring php7.2-gettext -y
Restart or Reload Apache2 Server by following this command
sudo systemctl restart apache2
Step 9: Creating SQL Database, database user and password
sudo mysql
CREATE DATABASE dbname;
Replace “dbname” with your desired database name
Setup a database user with a strong password. Replace “newuser” with your desired database-username and “password” with a desired strong-password.
CREATE USER 'newuser'@localhost IDENTIFIED BY 'password'
Grant all Privileges
GRANT ALL ON dbname.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;
Restart the Server
sudo systemctl restart apache2
Step10: Create a Magento user
Creating a new user is mandatory for security reasons. It helps your server be protected from hacking and brute force attacks, modification to your root directory and core Magento files. So that by creating a new user with your desired name and giving the required superuser permission is an important task. Follow the following commands. This also avoids further Magento 2 Installation errors.
领英推荐
sudo adduser adnan
Giving superuser permission to created new user
sudo usermod -g www-data adnan
Changing ownership and writing permission to a created user.
sudo chown adnan:www-data /var/www/html/
Open file
sudo nano /etc/sudoers
Then add the user below admin user like below syntax.
adnan ALL=(ALL) ALL
Step 11: Magento 2 Installation – Installing Composer
The Magento community recommends Magento 2 Installation for required extensions only by this composer method. This is very easy and simple. Just copy and paste it.
sudo curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Then Switch to the installation directory of Magento 2 i.e. be in a main public_html directory of your server where you want to install Magento setup files.
cd /var/www/html
Switch to the Created new user
su adnan
Remove the existing “index.html” file available in that directory. Without this Magento 2 setup may run into an error.
sudo rm index.html
Magento 2 Installation – Downloading Magento
You must have registered to the Magento portal and get the public key and secret key in your profile section. This alphanumeric key is used as a username and password for Magento 2 Installation. Just copy and paste it.
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition
You can install specific magento2 version by adding version in command as below in this command we are installing version 2.4.0
composer create-project --repository-url=https://repo.magento.com/ magento/project-enterprise-edition=2.4.0
Provide the Public & Private keys as Username and Password for further installation and press “y” for next step.
Wait for 5 to 15 min to get the installation of all setup files from the official Magento site.
Step 12: Modifying and Enabling some necessary permissions
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} + && find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} + && chown -R :www-data . && chmod u+x bin/magento
Don’t miss any word, copy the entire line of command, we combined 3 lines of command in one line. This saves our further steps.
Step 13: Modify the php.ini file of php7.3
sudo nano /etc/php/7.3/apache2/php.ini
Modify or Replace the below contents of value with given below value respectively.
memory_limit = 2G
upload_max_filesize = 300M
max_file_uploads = 50
zlib.output_compression = On
opcache.save_comments=1
Restart or Reload the Server
sudo systemctl restart apache2
Step 14: Installing from Browser
Enter your domain name. After that you will get the installation page of Magento 2 with the latest version. Follow the instructions as shown on the page. Before final installation it will ask you about your database name, database username and password, as you created, after the installation of phpmyadmin.
Enter your required time zone, currency setup and language you desired for. Then Enter the admin user name, transactional email ID and admin password.
After Successful installation, it will redirect you to a new page where you should choose your desired admin URL. It should look like this?
https://your_domain_name/admin_6sjsh.
If you want to change the admin URL, you should choose a non-guessable and anonymous alphanumeric admin URL to protect from Hacking and Brute Force attacks.
Then Click Finish Install. Wait for 2-3 min to install the final setup. After Successful installation copy, all displayed data of that page in txt format or wherever you want for further need. This is your final Magento 2 Installation setup.
NOTE: If you are using magento2 version 2.3.7 or above it does not comes with browser setup you have to install it using CLI follow the below command?
Go to magento2 installation directory and run the following command
bin/magento setup:install --base-url=https://YOUR_SERVER_IP/ \
-db-host=localhost --db-name=YOUR_DB_NAME --db-user=USERNAME --db-password=PASSWORD \
--admin-firstname=ADMIN_FIRSTNAME --admin-lastname=LASTNAME --admin-email=EMAIL \
--admin-user=USERNAME --admin-password=PASSWORD --language=en_US \
--currency=USD --timezone=America/Chicago --use-rewrites=1
You can change the timezone later in settings from admin panel
Messages like the following display if the installation is successful:Post installation file permissions check.
For security, remove write permissions from these directories: '/var/www/html/magento2/app/etc'
[Progress: 274 / 274
[SUCCESS]: Magento installation complete.
[SUCCESS]: Admin Panel URI: /admin_puu71q]
After this, get back to the SSH terminal window and run the following command in your magento installation directory for installing and enabling the cron job.
bin/magento cron:install
If you are using magento2.4.x version you will get two-factor authentication prompt at admin panel you can disable it to login first and then re-enable it if needed
bin/magento module:disable Magento_TwoFactorAuth
Step 15: Installing Sample Data
For installing Sample Data, run the following commands, as it is in your magento2 installation directory
bin/magento deploy:mode:set developer
sudo rm -rf generated/metadata/* generated/code/*
bin/magento sampledata:deploy
Then, it will ask username and password, enter previously entered Username and Password when you were installing Magento2 Setup.
bin/magento setup:upgrade
All Setup and Sample Data Installation is Done. Congratulations, You have successfully installed your first Online Store with Magento 2.X.X.
BONUS STEP
If you are going to setup SFTP connection for your magento directory to install extensions follow this guide. Permissions on /var/www/html for uploading website files via SFTP
FTP connection Enable? write permission in www directory:?
sudo chmod -R 775 /var/www
sudo chown www-data:www-data /var/www/html/magento2
sudo chmod -R 775 /var/www
sudo usermod -a -G www-data [username]