A LAMP stack is a development framework based on four open-source software components: Linux, Apache, MySQL, and PHP. They are often deployed together to allow a server to host dynamic websites and PHP-based apps. Here are the step-by-step instructions for setting up a LAMP stack on Ubuntu.
Note: These instructions assume you have a fresh installation of Ubuntu. Make sure your system is up-to-date by running:
```bash sudo apt update sudo apt upgrade ```
```bash sudo apt install apache2 ```
```bash sudo systemctl enable apache2 sudo systemctl start apache2 ```
```bash sudo apt install mysql-server ```
```bash sudo mysql_secure_installation ```
```bash sudo apt install php libapache2-mod-php php-mysql ```
```bash sudo nano /var/www/html/phpinfo.php ```
Add the following content and save the file:
```php <?php phpinfo(); ```
```bash sudo systemctl restart apache2 ```
You can create a simple PHP script to test the connection to MySQL:
```bash sudo nano /var/www/html/test-mysql.php ```
Add the following PHP code and save the file:
```php <?php $connection = mysqli_connect("localhost", "root", "your_mysql_password"); if (!$connection) { die("Database connection failed: " . mysqli_connect_error());} echo "Connected to MySQL successfully!"; mysqli_close($connection); ?> ```
Replace `”your_mysql_password”` with the root password you set during the MySQL installation.
You’ve now successfully installed a LAMP stack on your Ubuntu system. You can start building and hosting web applications on your server.
Have additional questions? Search below: