How to Setup Apache Web Server + MySQL (LAMP Stack) on Linux in Azure/AWS/GCP

To setup and install Apache Web Server + MySQL with the LAMP Stack on any of the cloud platforms, the recommended way is to use the available image on the cloud marketplace. It comes pre-configured with the full LAMP Stack – Apache Web Server, MySQL Server, PHP,  PHPMyadmin and Let’s Encrypt. Check out the links below to deploy to your preferred cloud provider.

Apache Web Server + MySQL Server on Linux Cloud (LAMP Stack)

Table of Contents

Apache Web Server Features

  • Apache Modules – Mod_wsgi, Mod_Security
  • PHP Language
  • PHP Extensions – Apcu,Redis,Mongodb,Libsodium,Swoole
  • KodExplorer (Web based file manager)
  • Mysql Server
  • Mysql Shell
  • phpMyadmin
  • Mysql Client
  • LAMP stack
  • Handling of static files
  • Loadable dynamic modules
  • Auto-indexing
  • .htaccess
  • Compatible with IPv6
  • Supports HTTP/2
  • FTP connections
  • Gzip compression and decompression
  • Bandwidth throttling
  • Perl, PHP, Lua scripts
  • Load balancing
  • Session tracking
  • URL rewriting
  • Geolocation based on IP address

Getting Started with Apache Web Server on Linux

Once your Apache web server has been deployed, the following links explain how to connect to a Linux VM:

 

 

Once connected and logged in, the following section explains how to start using Apache, MySQL and phpmyadmin. 

Using Apache Web Server on Linux Ubuntu, CentOS and Debian

The default directories used by Apache are as follows:

 

Apache LocationPath
Install prefix/usr/local/apache
Web root location/data/www/default
Main configuration File/usr/local/apache/conf/httpd.conf
Default virtual host conf/usr/local/apache/conf/vhost/default.conf
Virtual host conf/usr/local/apache/conf/vhost/your_virtual_host.conf
Virtual host SSL location/usr/local/apache/conf/ssl/your_virtual_host
Virtual host location/data/www/your_virtual_host_names
Virtual host log location/data/wwwlog/your_virtual_host_names

Apache Documentation:

http://httpd.apache.org/docs/

Using MySQL Server

Once logged in via your ssh terminal, the first thing to do is to set a new password for the MySQL root user account by running the following commands. Replace the text ‘your_pass_here‘ with your new password.

				
					mysql --user=root --password
 
Enter password: mysql1234
 
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_pass_here';
 
FLUSH PRIVILEGES;
				
			

If you receive an error related to your SQL syntax, depending on the version of MariaDB installed, try the following command to change your mysql root user password:

				
					ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_pass';
				
			

Using phpMyadmin to manage MySQL databases

To login to phpmyadmin, browse to the following URL on your web browser (use http) :

 

http://youserverip/phpmyadmin

You can login using your root account or you can create a new user account by running the following commands from your ssh terminal:

Create new Root User

				
					sudo mysql

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'some_very_complex_password';

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

FLUSH PRIVILEGES;
				
			

Change Root User Password

If you want to change the password of your root user, simply run the following command:

				
					sudo passwd
				
			

Adding a New Website / Apache Virtual Host

The Apache server uses Lamp

 

CommandDescription
lamp addCreate a new Apache virtual host
lamp delDelete a Apache virtual host
lamp listList all of Apache virtual hosts
lamp versionPrint version and exit

To add a new website simply run the following command:

				
					sudo lamp add
				
			

This will then add a new directory for your website.

 

In the following screenshot I have 3 sites setup.

Apache Web Server Firewall Ports

Default MySQL port is: TCP 3306

Apache HTTP : TCP 80

Apache TLS: TCP 443

 

The links below explain how to modify / create firewall rules depending on which cloud platform you are using.

 

To setup AWS firewall rules refer to – AWS Security Groups

To setup Azure firewall rules refer to – Azure Network Security Groups

To setup Google GCP firewall rules refer to – Creating GCP Firewalls

Apache Server Support / Documentation

If you experience any issues on getting this Apache web server setup on any of the cloud platforms, please contact us and we will assist

 

For documentation, please refer to the following links:

 

Using MySQL:

https://dev.mysql.com/doc/mysql-getting-started/en/

 

Using phpMyadmin:

https://docs.phpmyadmin.net/en/latest/

 

Using Apache:

http://httpd.apache.org/docs/

Avatar for Andrew Fitzgerald
Andrew Fitzgerald

Cloud Solution Architect. Helping customers transform their business to the cloud. 20 years experience working in complex infrastructure environments and a Microsoft Certified Solutions Expert on everything Cloud.

5 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x