Tech SNA
Latest Technology News, Mobile, Laptop, Gadgets & Much More.

How To Install & Setup Apache/ MySQL/ PHP on Ubuntu 18.04

0 113

In this tutorial, We’ll show you How To Install & Setup Apache/ MySQL/ PHP on Ubuntu 18.04. New PHP 7.4 comes with many new features and improvements and as a result of this many developers are using it for their projects. Installing  PHP with Apache on an Ubuntu 18.04 VPS is an easy task, just follow the steps below and you should have it done in a few minutes.

, we will learn How to Install PHP, MySQL and Apache Server in VPS Server (Like Digitalocean, Vultr, Cloudways, AWS, Google Cloud or any type of VPS Server).

Today, we will learn How To Install & Setup Apache/ MySQL/ PHP on Ubuntu 18.04 step by step.

It is not that hard if you know the right way of doing it. at the time when I was also a beginner, I spent a whole week trying to Install PHP, MySQL, and Apache Server in my Vultr Server. It caused so many errors and I had to do so many changes and tweaks to make it run successfully.

Don’t worry, I won’t let you suffer that much because there was no one to guide me at that time but for you, I am here now.

Okay, enough talking, let’s get started!

1. Install Apache

sudo apt update && sudo apt install apache2

2. Configure Firewall

sudo ufw allow OpenSSH
sudo ufw allow in "Apache Full"
sudo ufw enable
sudo ufw status

3. Test Apache

sudo service apache2 status

4. Install MySQL

sudo apt update && sudo apt install mysql-server
sudo service mysql status

5. MySQL Security

sudo mysql_secure_installation
-> ENTER | Y | Y | Y | Y
sudo mysqladmin -p -u root version

6. Install PHP

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt update && sudo apt install php libapache2-mod-php php-mysql
sudo apt-get install php7.2
sudo apt-get install php7.3
sudo apt -y install php7.4
php -v

7. Installing phpMyAdmin

sudo apt update && sudo apt install phpmyadmin
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin.conf
sudo service apache2 reload

8. Create MySQL User

sudo mysql
CREATE USER 'newusername'@'localhost' IDENTIFIED BY 'newuserpassword';
GRANT ALL PRIVILEGES ON * . * TO 'newusername'@'localhost';

9. Secure PhpMyAdmin

sudo nano /etc/apache2/conf-available/phpmyadmin.conf
Alias /enter your custom_url /usr/share/phpmyadmin
sudo service apache2 reload

10. Enable .htaacess

sudo apt-get update
sudo a2enmod rewrite
sudo nano /etc/apache2/sites-enabled/000-default.conf
<Directory "/var/www/html">
  AllowOverride All

11. Configure Apache File

sudo nano /etc/apache2/apache2.conf
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
 <Directory /var/www/html>
    Options -Indexes
ServerSignature Off
ServerTokens Prod

12. Installing All PHP Modules/ Extensions

PHP 7.2

sudo apt install php7.2-cli php7.2-fpm php7.2-json php7.2-pdo php7.2-mysql php7.2-zip php7.2-gd  php7.2-mbstring php7.2-curl php7.2-xml php7.2-bcmath php7.2-json php7.2-imagick

PHP 7.3

sudo apt install php7.3-cli php7.3-fpm php7.3-json php7.3-pdo php7.3-mysql php7.3-zip php7.3-gd  php7.3-mbstring php7.3-curl php7.3-xml php7.3-bcmath php7.3-json php7.3-imagick

PHP 7.4

sudo apt install php7.4-cli php7.4-fpm php7.4-json php7.4-pdo php7.4-mysql php7.4-zip php7.4-gd  php7.4-mbstring php7.4-curl php7.4-xml php7.4-bcmath php7.4-json php7.4-imagick

13. Install SSL Certificate

sudo apt-get update
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-apache
sudo apachectl stop
sudo letsencrypt --authenticator standalone --installer apache -d
sudo service apache2 start
service apache2 restart

14. Setup SSH Key

sudo apt-get update
mkdir .ssh
cd ~/.ssh
touch authorized_keys
sudo nano authorized_keys
sudo nano /etc/ssh/sshd_config
sudo systemctl restart sshd.service
service apache2 restart

We hope this post helped you to find out How To Install & Setup Apache/ MySQL/ PHP on Ubuntu 18.04.

We love to hear your comments on this article. Please feel free to leave any comments here.

If you liked this article, then please share to Social Media Site. You can also find us on Facebook, Twitter, and Instagram.

Thanks for reading this.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More