Sabtu, 16 Mei 2020

How To Install Apache, MySQL & PHP on an Ubuntu 18.04 VPS or Dedicated Server

To run a website on your Ubuntu 18.04 VPS, you will need to install a group of open source software including Apache, PHP, and MySQL. These applications are very useful when it comes to running dynamic websites that rely on databases and server-side scripting languages.

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

PHP (Hypertext Preprocessor) is a general-purpose server-side scripting language designed for web developments since 1994.

MySQL is a relational database server designed by Oracle and is used by high-profile and large-scale websites including Google, Youtube, and Twitter. Its development began in 1994.

With a Linux distribution such as Ubuntu 18.04, it’s entirely possible to create fully functional LAMP (Linux Apache, MySQL, and PHP) server.

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

Special Note: regardless of the Linux distribution you chose for your website, if you use Linux - you should use the Best Linux Hosting Providers. HostAdvice helps you to choose from the top Linux hosting providers: read the expert and user reviews and reach your own conclusions.

Prerequisites

  • An Ubuntu 18.04 VPS plan.
  • A non-root user that can perform sudo tasks.

Step 1: Install Apache

Ubuntu 18.04 maintains a central repository where you can install most applications from using the apt command. To install Apache, run the command below:

  1. $ sudo apt-get install apache2

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:

Step 2: Install MySQL

Run the command below on the terminal window to install MySQL server on your Ubuntu 18.04 VPS.

  1. $ 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:

  1. $ sudo mysql_secure_installation

You will be taken through a series of questions. The prompts will allow us to set a password policy and root password. We will also be prompted to remove the anonymous user, test database and disable remote login as shown below.

  1. 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?
  2. Press y|Y for Yes, any other key for No: Y
  3. There are three levels of password validation policy:
  4. LOW Length >= 8
  5. MEDIUM Length >= 8, numeric, mixed case, and special characters
  6. STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
  7. Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
  8. Please set the password for root here.
  9. New password:
  10. Re-enter new password:
  11. Estimated strength of the password: 100
  12. Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
  13. 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.
  14. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
  15. Success.
  16. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.
  17. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
  18. Success.
  19. 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.
  20. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
  21. - Dropping test database...
  22. Success.
  23. - Removing privileges on test database...
  24. Success.
  25. Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
  26. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
  27. Success.
  28. All done!

Testing your MySQl server

You can now try login on your MySQL server by typing the command below:

  1. $ sudo mysql -u root -p

Please note, you will be prompted to enter the root password that you created earlier on this guide.

Then, you will get a mysql prompt as show above.

If you wish to create a database, you can run the command below. Remember to replace ‘databasename’ with the name of database that you want to create.

  1. $ Create database <databasename>

Step 3: Install PHP

Enter the command below to install PHP on your Ubuntu 18.04 server

  1. $ sudo apt-get install php libapache2-mod-php

Press when you are prompted to confirm the installation

Testing PHP

We can test our PHP installation by creating a file on the root folder of our website. To do this, type the command below:

  1. $ sudo nano /var/www/html/info.php

Then copy paste the text below and click CTR+X and Y to save the file.

  1. <?php
  2. phpinfo();
  3. ?>

Restart Apache

We need to restart Apache for the changes to take effect using the command below:

  1. $ sudo systemctl restart apache2

Next, visit the php info file we created above on your browser via your server’s public IP address. For example, if your IP address is 111.111.111.111 enter the below text on your browser

  1. 111.111.111.111/info.php

Output

You should see the PHP information file as shown below:

Conclusion

Those are the basic steps of installing Apache, MySQL, and PHP on your server. You can now go ahead and install a graphical user interface for your database (e.g. phpMyAdmin) to better manage your databases. With the LAMP stack, running your dynamic websites is a breeze.

Share

& Comment

0 komentar:

Posting Komentar

 

Copyright © 2015 Catatan Pribadi™ is a registered trademark.

Designed by Templateism | Templatelib. Hosted on Blogger Platform.