This assumes that
root
First things first, update the package repos and upgrade stuff
1sudo apt update
2sudo apt upgrade -y
Install server requirements (Apache, PHP and dependencies)
1sudo apt install -y apache2 php php-curl php-gd php-zip certbot unzip
certbot
is for SSL, and unzip
is to extract opencart files, both we’ll use later
Restart Apache after installing dependencies (otherwise they don’t show up on the Opencart install page)
1sudo apt install mysql-server mysql-client
Now secure the MySQL installation by setting a root
user password and other stuff
1mysql_secure_installation # interactive
1sudo apt install phpmyadmin # interactive
PHPmyAdmin no longer let’s you login with the root MySQL user. So you’ll have to create a database and a user to use with Opencart from the command line. Once it’s created you can use that to login to PHPmyAdmin.
Replace DBNAME, USERNAME, PASSWORD in the commands below
1mysql --user=root
2mysql> CREATE DATABASE DBNAME ;
3mysql> CREATE USER 'USERNAME'@'localhost' IDENTIFIED BY 'PASSWORD' ;
4mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'localhost' ; -- grant access to ALL MySQL databases
5mysql> GRANT ALL PRIVILEGES ON DBNAME.* TO 'USERNAME'@'localhost' ; -- grant access to Opencart database
1curl -s https://raw.githubusercontent.com/aamnah/bash-scripts/master/setup/virtualhost.sh | bash -s mydomain.com
1# add `root` to `www-data`
2adduser root www-data
3
4# Change group ownership for `/var/www` to `www-data`
5sudo chgrp -R www-data /var/www/*
6
7# Give write permission to the group
8sudo chmod -R g+w /var/www/*
9
10# chmod g+s forces new files and dirs to pick up the group owner (www-data),
11# making sure that permissions change propagates
12# (`-s` means set user or group ID on execution)
13find /var/www -type d -print0 | sudo xargs -0 chmod g+s
1# move to project directory
2cd /var/www/domain.com/public_html
3
4# delete default index.html created by virtualhost script
5rm index.html
6
7# download OpenCart release
8# https://github.com/opencart/opencart/releases
9wget https://github.com/opencart/opencart/releases/download/3.0.3.2/opencart-3.0.3.2.zip
10
11# unzip the files
12unzip opencart-3.0.3.2.zip
13
14# move stuff from the `upload/` folder to project root
15mv upload/* .
16mv upload/.htaccess.txt
17
18# Rename config files
19cp config-dist.php config.php
20cp admin/config-dist.php admin/config.php
21
22# Make sure the file permissions are right
23chmod 755 config.php admin/config.php
24chown -R www-data:www-data /var/www/
25
26# Rename .htaccess file
27mv .htaccess.txt .htaccess
28
29# Enable Rewrite module (needed for clean URLs, will give errors otherwise)
30a2enmod rewrite
31
32# Restart Apache
33service apache2 restart
Now go to your domain or IP in the browser and complete the installation. Afterwards, cleanup
1# delete install/ and empty upload/ dir
2rm -rf install/ upload/
1# set permissions for files
2
3# To change all the directories to 755 (-rwxr-xr-x)
4echo -e "Setting permissions for all directories to 755.."
5find . -type d -exec chmod 755 {} \;
6
7# To change all the files to 644 (-rw-r--r--):
8echo -e "Setting permissions for all files to 644.."
9find . -type f -exec chmod 644 {} \;
10
11# set 444 for admin files
12echo -e "Setting secure 444 permissions for admin files.."
13chmod 444 config.php
14chmod 444 admin/config.php
15chmod 444 index.php
16chmod 444 admin/index.php
17chmod 444 system/startup.php
18
19# set 777 for cache
20echo -e "Setting 777 permissions for cache folders.."
21chmod 777 image/cache/
22chmod 777 system/storage/cache/