How to install apache and mysql and php on an ubuntu server

How to install apache and mysql and php on an ubuntu server

Apache is fast, secure and consistently a high-quality web server software which is the most popular since 1996.

In this article, we are going to show you how to install Apache, MySQL, and PHP on your Ubuntu 18.04 server.

Explaining with steps:-

Step 1:  Update your system

sudo apt-get update

Step 2: Install Apache
Press ‘Y’ when you are prompted to confirm the Apache installation.
Once the installation is complete, enter your VPS machine public IP address on your browser. You should see the default Apache web page as shown below:
sudo apt-get install apache2

Step 3: Install Mysql

sudo apt-get install mysql-server

Press ‘Y’ when you get a confirmation message.

Secure your mysql server

MySQl server ships with default settings which are not secure. We need to configure it to make our server less vulnerable to attacks. Luckily there is a single configuration command that will make things easier for us. Just run the command below:

sudo mysql_secure_installation

VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

Please set the password for root here.
New password:
Re-enter new password:
Estimated strength of the password: 100

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.

Normally, root should only be allowed to connect from ‘localhost’. This ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL comes with a database named ‘test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y

– Dropping test database…
Success.
– Removing privileges on test database…
Success.

Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

Success.
All done!

Testing your MySQl server

sudo mysql -u root -p

Install PHP

sudo apt-get install php libapache2-mod-php

Press Y when you are prompted to confirm the installation

Restart Apache

sudo systemctl restart apache2

If you are using this for your laravel project then you have to install the bellow library.

sudo apt-get -y install unzip zip nginx php7.2 php7.2-mysql php7.2-fpm php7.2-mbstring php7.2-xml php7.2-curl

Setup Vhost With out SSL:

<VirtualHost *:80>
    ServerName xxxxxxxxx.com
    DocumentRoot "/var/www/html/<project directory>/"
  <Directory "/var/www/html/<project directory>">
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

Setup Vhost With SSL:

<VirtualHost *:80>
	ServerName  xxxxxxxxx.com
	DocumentRoot /var/www/html/<project directory>/
	RewriteEngine On
	RewriteCond %{HTTPS} off
	RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<VirtualHost *:443>
    ServerName xxxxxxxxxx.com
    DocumentRoot /var/www/html/<project directory>/
    <Directory "/var/www/html/<project directory>/">
       Options FollowSymLinks
       AllowOverride All
    </Directory>
      SSLEngine on
      SSLCertificateFile /etc/ssl/<project directory>/xxxxx.crt
      SSLCertificateKeyFile /etc/ssl/<project directory>/xxxx.key
      SSLCertificateChainFile  /etc/ssl/<project directory>/xxxxxxx.ca-bundle
      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Enable and Disable Vhost Config

sudo a2dissite 000-default.conf
sudo a2ensite demo.conf

Lets Get Started your project with professional way

Get in touch and let us know
how we can Help


Contact Us