How to Install LAMP Stack on Google Cloud Platform [Ubuntu, Apache2, MySQL Server, PHP, PHP XML, phpmyadmin]

How to Install LAMP Stack on Google Cloud Platform

If you're looking to run a web server or host a website, you'll need to install a LAMP stack on your server. A LAMP stack consists of four components: Linux, Apache, MySQL, and PHP. In this tutorial, we'll walk you through the steps to install a LAMP stack on a Google Cloud Platform instance.

  1. Create a new instance in Google Cloud Platform

To get started, create a new instance in Google Cloud Platform. During the creation process, set up the boot disk to OS Ubuntu and SSD 20GB. You can set up a fixed IP in networking and also remember to allow HTTP traffic and HTTPS traffic in the Firewall section. Once you've set everything up, press the create button.

  1. Open SSH

After the instance is created, open SSH by clicking on the SSH button on the right-hand side of the screen. This will open a terminal window in your web browser.

  1. Update

The first thing you should do after logging into your instance is to update the package list. Run the following command in your terminal window:

sql
sudo apt-get update
  1. Upgrade

Next, you should upgrade your packages to the latest versions. Run the following command:

csharp
sudo apt-get upgrade
  1. Install Apache2

To install Apache2, run the following command:

csharp
sudo apt-get install apache2
  1. Install PHP

To install PHP, run the following command:

vbnet
sudo apt-get install php libapache2-mod-php
  1. Configure Apache to use PHP

To configure Apache to use PHP, run the following command:

bash
sudo nano /etc/apache2/mods-enabled/dir.conf

This will open the Apache configuration file in the Nano text editor. You need to move the PHP handler to the first line after the DirectoryIndex. Modify the file to look like this:

php
<IfModule mod_dir.c>
    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

Save the file and exit the editor.

  1. Restart Apache

To restart Apache, run the following command:

sudo service apache2 restart
  1. Create a PHP info file

To confirm that LAMP is installed and working correctly, you can create a PHP info file by running the following command:

css
sudo nano /var/www/html/info.php

Add the following code to the file:

php
<?php phpinfo(); ?>

Save the file and exit the editor.

  1. Test PHP

Open a web browser and navigate to http://[your_instance_ip]/info.php. You should see a page with information about your PHP installation.

  1. Set permissions for FTP

To allow FTP access to your web server, you need to set the permissions of the web directory to allow the FTP user to write to it. To do this, run the following command:

bash
sudo chmod -R 777 /var/www/html
  1. Install MySQL server

To install MySQL server, add the MySQL APT repository to your machine's package sources by running the following command:

python
sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb

Install the MySQL APT configuration file by running the following command:

python
sudo dpkg -i mysql-apt-config_0.8.22-1_all.deb

Update your package sources by running the following command:

sql
sudo apt-get update

Install MySQL server by running the following command:

csharp
sudo apt-get install mysql-server

During the installation process, you'll be prompted to set a root password for the MySQL server. Be sure to choose a strong password and keep it safe.

Once the installation is complete, start the MySQL server by running the following command:

sql
sudo systemctl start mysql

Verify that the MySQL server is running by running the following command:

lua
sudo systemctl status mysql
  1. Install phpMyAdmin

phpMyAdmin is a web-based application for managing MySQL databases. To install it, first install the required dependencies by running the following command:

python
sudo apt install apache2 php mysql-server php-mysql php-mbstring php-zip php-gd php-json php-curl
  1. Download phpMyAdmin

Download the latest version of phpMyAdmin from the official website using wget. You can check the latest version on the phpMyAdmin download page:

python
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
  1. Install Unzip

To unzip the downloaded file, first install the Unzip package:

csharp
sudo apt-get install unzip
  1. Unzip the downloaded file

Unzip the downloaded file using the following command:

python
unzip phpMyAdmin-5.1.1-all-languages.zip
  1. Move the extracted directory

Move the extracted directory to the Apache web root directory:

css
sudo mv phpMyAdmin-5.1.1-all-languages /var/www/html/phpmyadmin
  1. Set ownership and permissions

Set the correct ownership and permissions for the phpMyAdmin directory:

bash
sudo chown -R www-data:www-data /var/www/html/phpmyadmin
sudo chmod -R 755 /var/www/html/phpmyadmin
  1. Create an Apache configuration file

Create a new Apache configuration file for phpMyAdmin:

bash
sudo nano /etc/apache2/conf-available/phpmyadmin.conf

Add the following lines to the configuration file:

css
Alias /phpmyadmin /var/www/html/phpmyadmin
<Directory /var/www/html/phpmyadmin>
Options Indexes FollowSymLinks MultiViews
AllowOverride
all
Require
all granted
</Directory>

Save and close the configuration file.

  1. Enable the new configuration file

Enable the newly created configuration file:

sudo a2enconf phpmyadmin.conf
  1. Restart Apache

Restart the Apache web server to apply the changes:

sudo systemctl restart apache2
  1. Install the "xml" extension for PHP

To install the latest version of the "xml" extension for PHP, update the package list:

sql
sudo apt update

Install the latest version of PHP and the required packages for the "xml" extension:

sudo apt install php php-xml
  1. Verify the "xml" extension

Verify that the "xml" extension is enabled by running the following command. If the command returns "xml", it means that the "xml" extension is enabled:

perl
php -m | grep xml
  1. Restart Apache again

Restart the Apache web server to apply the changes:

sudo systemctl restart apache2
  1. Access phpMyAdmin

Now you should be able to access the latest version of phpMyAdmin by visiting your GCP instance's IP address followed by /phpmyadmin in a web browser (e.g. http://your-instance-ip-address/phpmyadmin). Log in with the MySQL root user and the password you set during the installation process.

That's it! You now have a fully functional LAMP stack installed on your Google Cloud Platform instance. You


[start] [Below is the original Notes from YAP WEI JUN as a references : ]

1. Create a new Instance in Google Cloud Platform. Setup Boot Disk to OS Ubuntu, SSD 20GB. You can setup a fixed IP in networking, and also remember to Allow HTTP traffic, Allow HTTPS traffic in Firewall section. then press create button. 2. After complate, open SSH. 3. update sudo apt-get update 4. upgrade sudo apt-get upgrade 5. install apache2 sudo apt-get install apache2 6. install php sudo apt-get install php libapache2-mod-php 7. configure Apache to use PHP by running the command: sudo nano /etc/apache2/mods-enabled/dir.conf 8. move the PHP handler to the first line after the DirectoryIndex, <IfModule mod_dir.c> DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm </IfModule> 9. Restart Apache by running the command: sudo service apache2 restart 10. To confirm that LAMP is installed and working correctly, you can create a PHP info file by running the command: sudo nano /var/www/html/info.php 11. Add the following code to the file: <?php phpinfo(); ?> 12. Save the file and exit the editor. 13. Open a web browser and navigate to http://[your_instance_ip]/info.php 14. (for ftp purpose) you can set : sudo chmod -R 777 /var/www/html 15. TO install MySQL Server, Add the MySQL APT repository to your machine's package sources by running the following command: sudo wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb 16. Install the MySQL APT configuration file by running the following command: sudo dpkg -i mysql-apt-config_0.8.22-1_all.deb 17. Update your package sources by running the following command: sudo apt-get update 18. Install MySQL server by running the following command(Select Mysql 5.7 ): sudo apt-get install mysql-server 19. During the installation process, you'll be prompted to set a root password for the MySQL server. Be sure to choose a strong password and keep it safe. 20. Once the installation is complete, start the MySQL server by running the following command: sudo systemctl start mysql 21. Verify that the MySQL server is running by running the following command: sudo systemctl status mysql 22. Install the required dependencies for phpMyAdmin: sudo apt install apache2 php mysql-server php-mysql php-mbstring php-zip php-gd php-json php-curl 23. Download the latest version of phpMyAdmin from the official website using wget. You can check the latest version on the phpMyAdmin download page (https://www.phpmyadmin.net/downloads/): wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip 24. Install Unzip sudo apt-get install unzip 25. Unzip the downloaded file using the unzip command: unzip phpMyAdmin-5.1.1-all-languages.zip 26. Move the extracted directory to the Apache web root directory: sudo mv phpMyAdmin-5.1.1-all-languages /var/www/html/phpmyadmin 27. Set the correct ownership and permissions for the phpMyAdmin directory: sudo chown -R www-data:www-data /var/www/html/phpmyadmin sudo chmod -R 755 /var/www/html/phpmyadmin 28. Create a new Apache configuration file for phpMyAdmin: sudo nano /etc/apache2/conf-available/phpmyadmin.conf 29. Add the following lines to the configuration file: Alias /phpmyadmin /var/www/html/phpmyadmin <Directory /var/www/html/phpmyadmin> Options Indexes FollowSymLinks MultiViews AllowOverride all Require all granted </Directory> 30. Save and close the configuration file. 31. Enable the newly created configuration file: sudo a2enconf phpmyadmin.conf 32. Restart the Apache web server to apply the changes: sudo systemctl restart apache2 33. install the latest version of the "xml" extension for PHP 34. Update the package list: sudo apt update 35. Install the latest version of PHP and the required packages for the "xml" extension: sudo apt install php php-xml 36. Verify that the "xml" extension is enabled by running the following command, If the command returns "xml", it means that the "xml" extension is enabled.: php -m | grep xml 37. Restart the Apache web server to apply the changes: sudo systemctl restart apache2 38. Now you should be able to access the latest version of phpMyAdmin by visiting your GCP instance's IP address followed by /phpmyadmin in a web browser (e.g. http://your-instance-ip-address/phpmyadmin). Log in with the MySQL root user and the password you set during the installation process.


[end] [Below is the original Notes from YAP WEI JUN as a references : ]






Comments

Popular posts from this blog