Today, I will share with you how to install Magento 2 on a VPS.
Step 1. You need to have a VPS
If you don’t have a VPS, I recommend you can buy it on Contabo or Vultr
Contabo is cheaper, but you must pay at least per month.
Vultr is more expensive, but you can pay at least per hour.
Note:
- You should use NVMe for your storage(NVMe faster than SSD)
- You should use the location of the VPS near your customers(your website will load faster when customer open it).
- You must use AlmaLinux 9, if you want to use CWP.
Step 2. Install Control Web Panel
2.1 Update your system
run command lines:
dnf update -y
dnf install wget -y
2.2 Install required dependencies
dnf install -y perl-libwww-perl perl-LWP-Protocol-https perl-GDGraph
2.3 Download and install CWP
cd /usr/local/src
wget http://centos-webpanel.com/cwp-el9-latest
sh cwp-el9-latest
Wait for the installation to complete (this may take 15-30 minutes)
After installation completes, reboot your server by command line:
reboot
Step 3. Install Elastic search
3.1 Update Your System
sudo dnf update -y
3.2 Add ElasticSearch Repository
sudo tee /etc/yum.repos.d/elasticsearch.repo << EOF
[elasticsearch-8.x]
name=Elasticsearch repository for 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
3.3 Install ElasticSearch
sudo dnf install elasticsearch
3.4 Configure ElasticSearch
sudo vi /etc/elasticsearch/elasticsearch.yml
3.5 Start and Enable ElasticSearch Service
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
3.6 Testing ElasticSearch
curl -X GET "localhost:9200/"
It should shows like this

Step 4. Install Comoser
4.1 update the server
yum -y update
4.2 Switch into the /usr/local/src directory.
cd /usr/local/src
4.3 Install Composer by using cURL
curl -sS https://getcomposer.org/installer | php
mv -f composer.phar /usr/local/bin/composer
4.4 Check composer version
composer -V
Step 5. Install version PHP compatible with Magento 2.4.7
Step 6. Install Magento 2.4.7
6.1 Download Magento 2.4.7 at Github
Then upload it to your VPS. Or, you can use this command on your VPS to download it to on VPS:
wget https://github.com/magento/magento2/archive/refs/tags/2.4.7.zip
Use this command line:
ln -s /home/demo/public_htmls/magento247/pub /home/demo/public_html/magento247
With /home/demo/public_html/magento247 is folder website show up and /home/demo/public_htmls/magento247/ is root folder of your Magento.
6.2 Install all dependencies of Magento 2
run command line:
composer install
6.3 Install Magento 2 by command line:
php -dmemory_limit=4G bin/magento setup:install –base-url=https://demo.magepow.net/magento247/ \
–db-host=localhost –db-name=db_name \
–db-user=db_user –db-password=your_pass_word \
–admin-firstname=Magento –admin-lastname=User –admin-email=contact@magepow.net \
–admin-user=magepow –admin-password=admin123 –language=en_US \
–currency=USD –timezone=America/Chicago \
–use-rewrites=1 \
–search-engine=elasticsearch7 –elasticsearch-host=localhost \
–elasticsearch-port=9200
You can change this command line bellow:
https://demo.magepow.net/magento247/ – your domain
db_name – your database name
db_user – your database user
your_pass_word – your database password
contact@magepow.net – your email
magepow – the Username use to login(your should change it to your own)
admin123 – the Password use to login(your should change it to your own)
After run the above command line, you will get a screen like this

[SUCCESS]: Magento installation complete.
[SUCCESS]: Magento Admin URI: /admin_azh3x5o
Nothing to import.
Your Admin will be your domain/admin_azh3x5o
in my case: https://demo.magepow.net/magento247/admin_azh3x5o
You can run command line for upgrade, deploy, clean and flush cache:
php -d memory_limit=4048M bin/magento setup:upgrade && php -d memory_limit=4048M bin/magento setup:static-content:deploy -f && php -d memory_limit=4048M bin/magento c:c && php -d memory_limit=4048M bin/magento c:f
Step 7. Some popular issues
7.1 Permission wrong
You can fix it by follow command lines:
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
find ./var -type d -exec chmod 777 {} \;
find ./pub/media -type d -exec chmod 777 {} \;
find ./pub/static -type d -exec chmod 777 {} \;
chmod 777 ./app/etc
chmod 644 ./app/etc/*.xml
chmod u+x bin/Magento
7.2 .htaccess
In file .htaccess change:
Options +FollowSymLinks
to
Options +SymLinksIfOwnerMatch
Then, you can check the website.

If your website is having problems, please leave a comment below or contact us at Magepow Contact, the Magepow technician team will assist in solving your problem quickly. Thanks.
Hope this article will helpful for you!
Leave a Reply