Back to the List

How to Install LAMP (Linux, Apache, MySQL, PHP) on a VPS

To install LAMP (Linux, Apache, MySQL, PHP) on a VPS (Virtual Private Server), you can follow these general steps:

1. Connect to your VPS: Use SSH (Secure Shell) to connect to your VPS. You'll need the IP address or domain name of your VPS, as well as the SSH credentials (username and password or SSH key).

2. Update the system: Before installing any software, it's a good practice to update the system packages to their latest versions. Run the following commands:

sudo apt update

sudo apt upgrade


3. Install Apache: Apache is the web server software that will serve your web pages. Install Apache using the following command:


sudo apt install apache2


4. Configure Apache: After installing Apache, you may need to make some configurations. For example, if you want to serve your website from a specific directory, you can modify the Apache configuration file. The file is usually located at `/etc/apache2/apache2.conf`.

5. Install MySQL: MySQL is a popular relational database management system. Install MySQL using the following command:


sudo apt install mysql-server


During the installation, you'll be prompted to set a password for the MySQL root user. Make sure to choose a strong password and remember it.

6. Secure MySQL installation: Run the MySQL secure installation script to improve the security of your MySQL installation. Follow the prompts and answer the questions to secure your MySQL installation.


sudo mysql_secure_installation


7. Install PHP: PHP is a server-side scripting language used for dynamic web content. Install PHP and some commonly used extensions with the following command:


sudo apt install php libapache2-mod-php php-mysql


8. Configure PHP: You may want to adjust some PHP settings according to your needs. The PHP configuration file is usually located at `/etc/php/<version>/apache2/php.ini`. Make any necessary changes, such as increasing the file upload size or enabling certain extensions.

9. Test the LAMP stack: To test if everything is working correctly, create a PHP info file. Create a file named `info.php` in your web server's root directory with the following content:

<?php

phpinfo();

?>


Save the file and access it through your web browser by visiting `http://your_server_ip/info.php`. If PHP is working correctly, you should see a page with detailed PHP information.

That's it! You've successfully installed LAMP on your VPS. You can now start building and hosting your website using Apache, MySQL, and PHP. Remember to keep your server and software up to date with security patches to ensure a secure hosting environment.