Sure, I can guide you through the step-by-step process of installing LAMP (Linux, Apache, MySQL, PHP) on an Oracle Cloud Ubuntu 22.04 server. Here are the steps:
Provision an Ubuntu 22.04 server instance on Oracle Cloud. Once you have the server instance up and running, you can SSH into it using a terminal application like PuTTY.
#Update the system packages by running the following command:
1 |
sudo apt-get update && sudo apt-get upgrade |
#Install Apache web server by running the following command:
1 |
sudo apt-get install apache2 |
#Open port 80 for incoming traffic by running the following command:
1 |
sudo ufw allow 80/tcp |
#Update firewall settings.
1 2 3 |
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT sudo netfilter-persistent save sudo service apache2 restart |
#Install MySQL server by running the following command:
1 |
sudo apt-get install mysql-server |
During the installation, you’ll be prompted to set the root password for MySQL. Choose a strong password and remember it.
#Once MySQL is installed, start the service and enable it to start at boot time by running the following commands:
1 2 |
sudo systemctl start mysql sudo systemctl enable mysql |
#This is an optional step and will allow the root MySQL user to login through phpMyAdmin.
1 |
sudo mysql |
#Change authentication method for the root account to mysql_native_password by executing the following query.
1 |
ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY 'password'; |
Replace password by the root password you entered while installing MySQL.
#To put the changes into effect, execute the following query :
1 |
FLUSH PRIVILEGES; |
Following this, we can now do a root login through phpMyAdmin. The username is root and password is the one that was setup earlier while installing MySQL.
#Return back to the command line.
1 |
exit |
#Secure your MySQL installation by running the following command:
1 |
sudo mysql_secure_installation |
- In the next screen we will be asked whether we need to setup VALIDATE PASSWORD plugin. We selected no.
- Set the password for the root MySql account.
- Remove anonymous users? We selected yes.
- Disallow root login remotely? We selected no.
- Remove test database and access to it? We chose yes.
- Reload privilege tables now? We again chose yes.
This will prompt you to configure some basic security settings for MySQL.
#Install PHP by running the following command:
1 |
sudo apt-get install php libapache2-mod-php php-mysql php-xmlrpc php-soap php-curl php-gd php-xml php-cli php-bcmath php-tokenizer php-pear php-curl php-memcached php-xdebug php-intl php-fpm php-pgsql php-imap php-json php-zip php-mbstring |
Restart the Apache web server to apply the changes by running the following command:
1 |
sudo systemctl restart apache2 |
Test your LAMP installation by creating a PHP file with the following code:
1 2 3 |
<?php phpinfo(); ?> |
Save the file as info.php
and copy it to the Apache web server’s root directory /var/www/html/
.
Open a web browser and navigate to http://your-server-ip-address/info.php
. You should see a page displaying PHP information. If you see the PHP information, your LAMP installation is working correctly.
That’s it! You have now successfully installed LAMP on your Oracle Cloud Ubuntu 22.04 server.
(Optional) If you want to install additional PHP modules, you can do so by running the following command:
1 |
sudo apt-get install php-{module-name} |
Replace {module-name} with the name of the module you want to install. For example, to install the gd module, run the following command:
1 |
sudo apt-get install php-gd |
To manage your MySQL databases and users, you can use the MySQL command line tool or a graphical user interface such as phpMyAdmin. To install phpMyAdmin, run the command:
1 |
sudo apt-get install phpmyadmin |
During the installation, you’ll be prompted to configure some basic settings for phpMyAdmin, such as the web server to use and the database administrator password. Once installed, you can access phpMyAdmin by navigating to http://your_server_ip/phpmyadmin in a web browser.
Finally, to keep your LAMP stack up-to-date and secure, you should regularly update your Ubuntu packages and LAMP components using the following commands
1 2 3 |
sudo apt-get update sudo apt-get upgrade sudo apt-get autoremove |
You should also configure a firewall to restrict incoming traffic to your server and set up backups to protect your data in case of a disaster.
That’s it! You now have a fully functional LAMP stack running on your Oracle Cloud Ubuntu server.
Note:
To be able to upload files using FileZilla we need to change the ownership and access modes of the server directory.
1 |
sudo apt install zip unzip |
any file unzip projectname.zip
1 |
unzip projectname.zip |
When php file not then follow this process
1 2 3 |
sudo nano /etc/apache2/apache2.conf sudo a2enmod rewrite sudo service apache2 restart |
1 2 |
sudo mkdir /var/www/mywebcode.com sudo nano /var/www/mywebcode.com/index.html |
1 2 3 4 5 6 7 8 |
<html> <head> <title>mywebcode.com</title> </head> <body> <h1>Welcome to www.mywebcode.com website</h1> </body> </html> |
1 2 3 |
sudo chown -R ubuntu /var/www/mywebcode.com sudo chmod -R 755 /var/www/mywebcode.com sudo chown -R www-data:www-data /var/www/mywebcode.com |
1 2 |
sudo chown www-data:www-data -R /var/www/mywebcode.com sudo nano /etc/apache2/sites-available/mywebcode.com.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<VirtualHost *:80> ServerAdmin webmaster@mywebcode.com ServerName mywebcode.com ServerAlias www.mywebcode.com DocumentRoot /var/www/mywebcode.com <Directory /var/www/mywebcode.com/> AllowOverride All Require all granted Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> |
1 |
sudo a2enmod rewrite |
.htaccess
1 2 3 4 5 6 7 8 9 10 11 |
<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on # Send request via index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> |
1 2 |
sudo a2ensite mywebcode.com.conf sudo service apache2 restart |
Add SSL Certificate in Oracle
1 2 3 4 |
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 443 -j ACCEPT sudo netfilter-persistent save sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT sudo netfilter-persistent save |
1 2 3 4 5 6 7 8 9 |
sudo service apache2 restart sudo iptables -save >/etc/iptables/rules.v4 sudo apt install certbot sudo mkdir /var/www/mywebcode.com/.well-known sudo chown -R ubuntu /var/www/mywebcode.com sudo charp www-data/var/www/mywebcode.com sudo chmod g+s /var/www/mywebcode.com sudo apt install certbot python3-certbot-apache sudo certbot --apache |