Manual Installation of Apache, MySQL, and PHP on Elastic VPS with Ubuntu 22.04 OS
In this guide, we’ll show you how to manually install Apache, MySQL, and PHP on your server. This setup, known as the AMP stack, is essential for running dynamic websites and web applications.
By following these steps, you’ll learn how to configure each component for optimal performance and security. Manual installation gives you more control and a deeper understanding of how these technologies work together. Let’s get started!
Step 1. Select the ‘New Environment’ on AccuWeb.Cloud dashboard
Step 2. Select PHP as the language and choose Ubuntu 22.04 elastic VPS. Click on install.
Manual installation of Apache
Step 1. Navigate to ‘Web SSH’ of your elastic VPS.
Step 2. Update the package list to get the latest information on available packages:
`sudo apt update`
Step 3. Install the Apache web server and automatically confirm the installation:
`sudo apt install apache2 -y`
Step 4. Enable Apache to start on boot:
`sudo systemctl enable apache2`
Step 5. Check the current status of the Apache service:
`sudo systemctl status apache2`
Step 6. Start the Apache web server:
`sudo systemctl start apache2`
Step 7. Verify that the Apache web server is running:
`sudo systemctl status apache2`
Manual Installation of MySQL
Step 1. Navigate to ‘Web SSH’ of your Elastic VPS.
Step 1. Installing MySQL
- First, install the MySQL server:
- sudo apt install mysql-server -y
Step 3. Then, start the MySQL service:
sudo systemctl start mysql.service
sudo systemctl status mysql.service
Step 4. Configuring MySQL
- To configure MySQL, log in to the MySQL shell:
- sudo mysql
Step 5. Change the root user password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Sep 6. Exit the MySQL shell:
- Exit
Sep 7. Secure the MySQL installation:
sudo mysql_secure_installation
Step 8. Log in to MySQL again:
mysql -u root -p
Step 9. Change the root user authentication method:
ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
Step 10. Creating a Dedicated MySQL User and Granting Privileges
- Log in to MySQL:
- sudo mysql
mysql -u root -p
CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';
Grant the necessary privileges to the new user:
GRANT CREATE, ALTER, DROP, INSERT, UPDATE, INDEX, DELETE, SELECT, REFERENCES, RELOAD on *.* TO 'sammy'@'localhost' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'sammy'@'localhost' WITH GRANT OPTION;
Step 1. To check your databases, use:
SHOW DATABASES;
Step 2. To see all the tables:
SHOW TABLES;
This guide outlines the steps to install and configure MySQL, create a dedicated user, and grant appropriate privileges.
Manual Installation of php
Step 1. Go to the ‘setting’ of your environment and choose the Firewall tab.
Step 2. Select the ‘inbound rules’ tab and click on ‘Add’ to add a new inbound rule.
Step 3. Enter the name ‘HTTPS’. For the port range, enter port 80.
Step 4. The new inbound rule is added to the firewall.
Step 5. Now, navigate to ‘Web SSH’ of your elastic VPS.
Step 6. Install PHP and necessary modules:
sudo apt install php libapache2-mod-php php-mysql -y
Step 6. Restart Apache service:
sudo systemctl restart apache2
Step 7. Create a PHP info file:
sudo vi /var/www/html/info.php
Step 8. Add the following content to the file:
<?php
phpinfo();
?>
Step 9. Press escape key. Now type ‘:x!’ and press enter to save the changes made in the file. Restart Apache service again:
sudo systemctl restart apache2
Step 10. Check PHP version:
php -v
Step 11. Check Apache service status:
systemctl status apache2
Step 12. Create a database connection file:
- vi /var/www/html/dbconnect.php
Step 13. After this, add the port in the firewall and make sure your SLB is enabled in your environment topology.
PHP Script
systemctl status apache2
<?php
// Database connection details
$servername = "localhost";
$username = "root"; // Replace with your MySQL username
$password = "your_root_password"; // Replace with your MySQL password
$dbname = "your_database_name"; // Replace with your database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
// Close connection
$conn->close();
?>
Press the escape key. Now type ‘:x!’ and press enter to save the changes made in the file.
Copy your public IP and paste it into a new tab and add ‘/dbconnect.php’ which is your file name. You can see the contents of dbconnect.php on the page.






















