0

Install an Apache web server with PHP and MySQL in Amazon Linux

In this tutorial we will show you how to install an Apache web server with PHP and MySQL support on your Amazon Linux instance (sometimes called a LAMP web server or LAMP stack). You can use this server to host a static website or deploy a dynamic PHP application that reads and writes information to a database.

 

 

To install and start the LAMP web server with the Amazon Linux AMI (APACHE)

  • Connect to your instance.
  • To ensure that all of your software packages are up to date, perform a quick software update on your instance. This process may take a few minutes, but it is important to make sure that you have the latest security updates and bug fixes.The -y option installs the updates without asking for confirmation. If you would like to examine the updates before installing, you can omit this option.

  • Now that your instance is current, you can install the Apache web server, MySQL, and PHP software packages. Use the yum install command to install multiple software packages and all related dependencies at the same time.

  • Start the Apache web server.

  • Use the chkconfig command to configure the Apache web server to start at each system boot.

The chkconfig command does not provide any confirmation message when you successfully use it to enable a service.

You can verify that httpd is on by running the following command:

 

  • Test your web server. In a web browser, type the public DNS address (or the public IP address) of your instance. If there is no content in /var/www/html, you should see the Apache test page. You can get the public DNS for your instance using the Amazon EC2 console (check the Public DNS column; if this column is hidden, choose Show/Hide Columns (the gear-shaped icon) and choose Public DNS).

apache_test_page

 

To test your LAMP web server

If your server is installed and running, and your file permissions are set correctly, your ec2-user account should be able to create a PHP file in the /var/www/html directory that is available from the internet.

  • Create a PHP file in the Apache document root.

  • If you get a “Permission denied” error when trying to run this command, try logging out and logging back in again to pick up the proper group permissions that you configured in To set file permissions.
  • In a web browser, type the URL of the file that you just created. This URL is the public DNS address of your instance followed by a forward slash and the file name. For example

You should see the PHP information page:

phpinfo

If you do not see this page, verify that the /var/www/html/phpinfo.php file was created properly in the previous step. You can also verify that all of the required packages were installed with the following command. The package versions in the second column do not need to match this example output.

If any of the required packages are not listed in your output, install them using the sudo yum install package command.

 

 

To secure the database server

The default installation of the MySQL server has several features that are great for testing and development, but they should be disabled or removed for production servers. The mysql_secure_installation command walks you through the process of setting a root password and removing the insecure features from your installation. Even if you are not planning on using the MySQL server, we recommend performing this procedure.

  • Start the MySQL server.
  • Run mysql_secure_installation.

  1. When prompted, type a password for the root account.
    1. Type the current root password. By default, the root account does not have a password set. Press Enter.
    2. Type Y to set a password, and type a secure password twice. For more information about creating a secure password, see https://identitysafe.norton.com/password-generator/. Make sure to store this password in a safe place.

      Note

      Setting a root password for MySQL is only the most basic measure for securing your database. When you build or install a database-driven application, you typically create a database service user for that application and avoid using the root account for anything but database administration.

  2. Type Y to remove the anonymous user accounts.
  3. Type Y to disable the remote root login.
  4. Type Y to remove the test database.
  5. Type Y to reload the privilege tables and save your changes.
  • (Optional) If you do not plan to use the MySQL server right away, stop it. You can restart it when you need it again.

  • (Optional) If you want the MySQL server to start at every boot, type the following command.

You should now have a fully functional LAMP web server. If you add content to the Apache document root at /var/www/html, you should be able to view that content at the public DNS address for your instance.

 

 

Install phpMyAdmin

phpMyAdmin is a web-based database management tool that you can use to view and edit the MySQL databases on your EC2 instance. Follow the steps below to install and configure phpMyAdmin on your Amazon Linux instance.

Important

We do not recommend using phpMyAdmin to access a LAMP server unless you have enabled SSL/TLS in Apache; otherwise, your database administrator password and other data are transmitted insecurely across the internet. For security recommendations from the developers, see Securing your phpMyAdmin installation. For general information about securing a web server on an EC2 instance, see Tutorial: Configure Apache Web Server on Amazon Linux to use SSL/TLS.

Note

The Amazon Linux package management system does not currently support the automatic installation of phpMyAdmin in a PHP 7 environment. This tutorial describes how to install phpMyAdmin manually.

  • Log in to your EC2 instance using SSH.
  • Install the required dependencies.

  • Restart Apache.

  • Navigate to the Apache document root at /var/www/html.

  • Select a source package for the latest phpMyAdmin release from https://www.phpmyadmin.net/downloads. To download the file directly to your instance, copy the link and paste it into a wget command, as in this example:

  • Create a phpMyAdmin folder and extract the package into it using the following command.

  • Delete the phpMyAdmin-latest-all-languages.tar.gz tarball.

  • (Optional) If the MySQL server is not running, start it now.

  • In a web browser, type the URL of your phpMyAdmin installation. This URL is the public DNS address (or the public IP address) of your instance followed by a forward slash and the name of your installation directory. For example:

You should see the phpMyAdmin login page:

phpmyadmin

 

Prakash S

Prakash S

I would like to introduce myself as a Software professional opting for the career in software industry. I'm Prakash S, a MCA graduate and trained as industry level practice for Software technology. Basically I am a PHP Developer but now days exploring more in HTML5, CSS, AngularJS and jQuery libraries.