How to install apache2, mysql, php on VPS ubuntu server

Maybe you know that if you want to deploy a website on vps server, you need to prepare a environment: mysql, php and apache2 or nginx. Today, we will install mysql, php and apache2 on ubuntu vps server.

How to connect to your server via ssh

You can use terminal on Ubuntu OS, terminal on Mac OS or Git Bash, puty on Windows OS. We can use the ssh command line format
ssh ssh-user@host-ip -p ssh-port
Example: I have ssh-user phudu25, host-ip 192.168.31.124, ssh-port 22 then I run the ssh command line
ssh phudu25@192.168.31.124 -p 22

Connect to your server via ssh

Tips: If you use the ssh private key ( how to generate ssh key ), you can use the command line format
ssh -i private-key-file ssh-user@host-ip -p ssh-port
Example: I have the ssh private key named louiscoding the I run the ssh command line
ssh -i louiscoding phudu25@192.168.31.124 -p 22
If you have the problem with permission to read the ssh private key file, you can run with sudo
sudo ssh -i louiscoding phudu25@192.168.31.124 -p 22

How to install apache2 on ubuntu server

Run the command line sudo apt-get update and sudo apt-get install apache2

install apache2 on ubuntu

Now you can see the apache2 ubuntu default page by visit the host ip on your browser

apche2 ubuntu default page

Tips: Please read that page, you will know about apache2 configuration overview, apache2 conmand line: a2enmod, a2dismod, a2ensite, a2dissite, and a2enconf, a2disconf. The default page is in the folder /var/www/html, apache2 is in the folder /etc/apache2. It will be your knowledge to learn how to deploy a website on ubuntu vps server.

How to install php on ubuntu server

Run the command line sudo apt-get install php Then it will download the lastest version for you, it is 7.2.1.5 right now. You can choose “Y” to install

install php on ubuntu

If you want to install the php5.6, you can use these command line:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php5.6

You can create a file test.php in the root folder of the website /var/www/html to ensure that it is installed correctly. The command line to create file sudo nano /var/www/html/test.php

welcome to louiscoding blog

Now, you can check the test.php page on your browser with url http://192.168.31.124/test.php

welcome to louiscoding blog

How to install mysql server on ubuntu server

Run the command line sudo apt-get install mysql-server

install mysql server on ubuntu

Run command line sudo mysql -u root -p and mysql command line show databases; to ensure that mysql server is installed correctly

check mysql server installed correctly

Hope it will be useful with you. Please feel free to let me know if you have any question.

How to install apache2, mysql, php on VPS ubuntu server
5 (100%) 1 vote

Leave a Reply

Your email address will not be published. Required fields are marked *