To run a trang web on your Ubuntu 18.04 VPS, you will need lớn install a group of open source software including Apađậy, PHP., & MySQL. These applications are very useful when it comes lớn running dynamic websites that rely on databases và server-side scripting languages.

Bạn đang xem: How to install php on linux, apache, mysql, php (lamp) stack on ubuntu 16

Apabịt is fast, secure and consistently a high-unique web hệ thống software which is the most popular since 1996.

PHPhường (Hypertext Preprocessor) is a general-purpose server-side scripting language designed for website developments since 1994.

MySquốc lộ is a relational database hệ thống designed by Oracle and is used by high-protệp tin và large-scale websites including Google, Youtube, và Twitter. Its development began in 1994.

With a Linux distribution such as Ubuntu 18.04, it’s entirely possible khổng lồ create fully functional LAMPhường (Linux Apabít, MySquốc lộ, & PHP) VPS.

In this guide, we are going lớn show you how to install Apache, MySquốc lộ, và PHP on your Ubuntu 18.04 server.

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


An Ubuntu 18.04 VPS plan.A non-root user that can persize suvì tasks.

Step 1: Install Apache

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

$ sudo apt-get install apache2Press ‘Y’ when you are prompted lớn confirm the Apabít installation.

Xem thêm: Installation - First Steps With Elasticsearch, Docker And Php

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 commvà below on the terminal window to install MySQL server on your Ubuntu 18.04 VPS.

$ subởi apt-get install mysql-serverPress ‘Y’ when you get a confirmation message.

Secure your MySQL server

MySQl hệ thống ships with default settings which are not secure. We need khổng lồ configure it khổng lồ make our server less vulnerable to lớn attacks. Luckily there is a single configuration commvà that will make things easier for us. Just run the command below:

$ suvì mysql_secure_installationYou will be taken through a series of questions. The prompts will allow us lớn mix a password policy & root password. We will also be prompted lớn remove sầu the anonymous user, thử nghiệm database và disable remote login as shown below.

VALIDATE PASSWORD PLUGIN can be used to lớn kiểm tra passwords & improve sầu security. It checks the strength of password & allows the users to lớn 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: YThere are three levels of password validation policy:LOWLength >= 8MEDIUM Length >= 8, numeric, mixed case, & special charactersSTRONG Length >= 8, numeric, mixed case, special characters and dictionary filePlease enter 0 = LOW, 1 = MEDIUM & 2 = STRONG: 2Please set the password for root here.New password:Re-enter new password:Estimated strength of the password: 100Do you wish khổng lồ continue with the password provided?(Press y|Y for Yes, any other key for No) : YBy mặc định, a MySquốc lộ installation has an anonymous user, allowing anyone to log inkhổng lồ MySquốc lộ without having khổng lồ have sầu a user tài khoản created for them. This is intended only for testing, và lớn make the installation go a bit smoother. You should remove sầu them before moving inkhổng lồ a production environment. Remove sầu anonymous users? (Press y|Y for Yes, any other key for No) : YSuccess. Normally, root should only be allowed lớn 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) : YSuccess. By default, MySQL comes with a database named "test" that anyone can access. This is also intended only for testing, và should be removed before moving into lớn a production environment.Remove chạy thử database và access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping demo database...Success. - Removing privileges on demo 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) : YSuccess.All done!

Testing your MySQl server

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

$ subởi mysql -u root -pPlease note, you will be prompted to lớn enter the root password that you created earlier on this guide.


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

If you wish to create a database, you can run the command below. Rethành viên lớn replace ‘databasename’ with the name of database that you want to create.

$ Create database

Step 3: Install PHP

Enter the commvà below to install PHP. on your Ubuntu 18.04 server

$ suvị apt-get install php libapache2-mod-phpPress Y when you are prompted khổng lồ confirm the installation

Testing PHP

We can chạy thử our PHP.. installation by creating a file on the root thư mục of our trang web. To bởi vì this, type the comm& below:

$ subởi nano /var/www/html/info.phpThen copy paste the text below & cliông xã CTR+X and Y khổng lồ save the file.

Restart Apache

We need to lớn restart Apabịt for the changes lớn take effect using the commvà below:

$ suvì chưng systemctl restart apache2Next, visit the php info tệp tin we created above on your browser via your server’s public IPhường address. For example, if your IP. address is enter the below text on your browser


You should see the PHP information file as shown below:



Those are the basic steps of installing Apabịt, MySquốc lộ, và PHP. on your VPS. You can now go ahead & install a graphical user interface for your database (e.g. phpMyAdmin) to lớn better manage your databases. With the LAMP stack, running your dynamic websites is a breeze.