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.
- 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.
- 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.
- 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:
sqlsudo apt-get update
- Upgrade
Next, you should upgrade your packages to the latest versions. Run the following command:
csharpsudo apt-get upgrade
- Install Apache2
To install Apache2, run the following command:
csharpsudo apt-get install apache2
- Install PHP
To install PHP, run the following command:
vbnetsudo apt-get install php libapache2-mod-php
- Configure Apache to use PHP
To configure Apache to use PHP, run the following command:
bashsudo 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.
- Restart Apache
To restart Apache, run the following command:
sudo service apache2 restart
- 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:
csssudo nano /var/www/html/info.php
Add the following code to the file:
php<?php phpinfo(); ?>
Save the file and exit the editor.
- 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.
- 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:
bashsudo chmod -R 777 /var/www/html
- Install MySQL server
To install MySQL server, add the MySQL APT repository to your machine's package sources by running the following command:
pythonsudo 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:
pythonsudo dpkg -i mysql-apt-config_0.8.22-1_all.deb
Update your package sources by running the following command:
sqlsudo apt-get update
Install MySQL server by running the following command:
csharpsudo 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:
sqlsudo systemctl start mysql
Verify that the MySQL server is running by running the following command:
luasudo systemctl status mysql
- 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:
pythonsudo apt install apache2 php mysql-server php-mysql php-mbstring php-zip php-gd php-json php-curl
- 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:
pythonwget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
- Install Unzip
To unzip the downloaded file, first install the Unzip package:
csharpsudo apt-get install unzip
- Unzip the downloaded file
Unzip the downloaded file using the following command:
pythonunzip phpMyAdmin-5.1.1-all-languages.zip
- Move the extracted directory
Move the extracted directory to the Apache web root directory:
csssudo mv phpMyAdmin-5.1.1-all-languages /var/www/html/phpmyadmin
- Set ownership and permissions
Set the correct ownership and permissions for the phpMyAdmin directory:
bashsudo chown -R www-data:www-data /var/www/html/phpmyadmin
sudo chmod -R 755 /var/www/html/phpmyadmin
- Create an Apache configuration file
Create a new Apache configuration file for phpMyAdmin:
bashsudo nano /etc/apache2/conf-available/phpmyadmin.conf
Add the following lines to the configuration file:
cssAlias /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.
- Enable the new configuration file
Enable the newly created configuration file:
sudo a2enconf phpmyadmin.conf
- Restart Apache
Restart the Apache web server to apply the changes:
sudo systemctl restart apache2
- Install the "xml" extension for PHP
To install the latest version of the "xml" extension for PHP, update the package list:
sqlsudo apt update
Install the latest version of PHP and the required packages for the "xml" extension:
sudo apt install php php-xml
- 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:
perlphp -m | grep xml
- Restart Apache again
Restart the Apache web server to apply the changes:
sudo systemctl restart apache2
- 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
Post a Comment