Thursday, October 17, 2013

Install Apache 2.4, PHP 5.4 & APC on Amazon Linux EC2 - Coding Steps

Install Apache 2.4, PHP 5.4 & APC on Amazon Linux EC2 - Coding Steps

The following guide is a step by step tutorial on installing and configuring Apache 2.4, and PHP 5.4 (with APC) on an Amazon EC2 instance running Amazon Linux AMI. The procedure has been tested on Amazon Linux AMI, but should also apply in general to Fedora/Red Hat/CentOS distributions. Also, should you be interested in manually installing PHP APC straight from the PHP PECL library, please check this guide. A guide on installing the complete LAMP stack with MySQL is provided here.

1. Install Linux updates, set time zones, followed by GCC and Make

sudo yum -y update
sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \
     /etc/localtime
sudo yum install -y gcc make gcc-c++

2. Install Apache 2.4 httpd, PHP 5.4 and PHP extensions

sudo yum install -y httpd24 php54
sudo yum install -y php54-devel php54-mysql php54-pdo php54-mbstring
sudo yum install -y php-pear 
sudo pear install Log
sudo yum install -y pcre-devel
sudo service httpd start

3. Install PHP APC module

sudo yum install -y php54-pecl-apc

4. Auto Start Apache in EC2 Amazon Linux

sudo /sbin/chkconfig --levels 235 httpd on
sudo service httpd restart

If this tutorial was helpful to you, then please do not forget to leave a comment, or two. :)


Install Apache, PHP, APC, & MySQL on Amazon EC2 with Amazon Linux AMI

    The following guide is a step by step guide on installing and configuring Apache, PHP (with APC) & MySQL (LAMP Stack) on an Amazon EC2 instance running Amazon Linux AMI. The procedure has been tested on Amazon Linux AMI, but should also apply in general to Fedora/Red Hat/CentOS distributions. Also, should you be interested in manually installing PHP APC straight from the PHP PECL library, please check this guide.

    1. Install Linux updates, set time zones, followed by GCC and Make

    sudo yum -y update
    sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \
          /etc/localtime
    sudo yum install -y gcc make

    2. Install PHP and PHP extensions

    sudo yum install -y php
    sudo yum install -y php-devel php-mysql php-pdo
    sudo yum install -y php-pear php-mbstring
    sudo pear install Log
    sudo yum install -y pcre-devel

    3. Install Apache httpd

    sudo yum -y install httpd
    sudo service httpd start

    4. Install MySQL

    sudo yum -y install mysql-server mysql
    sudo service mysqld start
     ps:read the output from MySQL, do the secure install and set password

    5. Install PHP APC module

    sudo yum -y install httpd-devel
    sudo pecl install apc-beta
    echo "extension=apc.so" | sudo tee /etc/php.d/apc.ini
    Or Simply:
    sudo yum install -y php-pecl-apc

    6. MySQL Configuration

    sudo vi /etc/my.cnf
    [mysqld]
    ...
    skip-external-locking
    long_query_time=1
    slow_query_log
    slow_query_log_file=/var/log/log-slow-queries.log
    log-bin=mysql-bin
    server-id= 1
    ...
    [mysqld_safe]
    ...
    myisam_recover_options
    ...
    [mysqld]
    ...
    key_buffer_size = 128M
    max_allowed_packet = 3M
    table_open_cache = 64
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    myisam_sort_buffer_size = 16M
    thread_cache_size = 8
    query_cache_size= 32M
    thread_concurrency = 8
    innodb_buffer_pool_size = 128M
    innodb_log_file_size = 32M
    innodb_additional_mem_pool_size = 8M
    innodb_log_buffer_size = 4M
    ...
    Log Slow Queries:
    sudo touch /var/log/log-slow-queries.log
    sudo chown mysql.mysql /var/log/log-slow-queries.log
    sudo /sbin/chkconfig --levels 235 mysqld on
    sudo service mysqld start

    7. PHP Configuration Changes in php.ini

    sudo nano /etc/php.ini
    expose_php = Off
    memory_limit = 128M
    date.timezone = America/Indianapolis
    Note: Location of error file
    /var/log/httpd/error.log

    8. Auto Start Apache in EC2 Amazon Linux

    sudo /sbin/chkconfig --levels 235 httpd on
    sudo service httpd start
    If this tutorial was helpful to you, then please do not forget to leave a comment, or two. :)

    How to install PHPMyAdmin on Linux EC2 instance?


    Do the following:
    1. Navigate to the apache folder
      cd /var/www/html
      
    2. Ensure ownership of the folder (assuming signed in with ec2-user)
      sudo chown ec2-user .
      
    3. Download phpMyAdmin
      wget http://www.sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.0.3/phpMyAdmin-4.0.3-all-languages.tar.bz2
      
    4. Unzip
      tar -jxf phpMyAdmin-4.0.3-all-languages.tar.bz2 -C /var/www/html
      
    5. Rename the folder
      mv phpMyAdmin-4.0.3-all-languages phpmyadmin
      
    6. Remove the zip file
      rm -rf phpMyAdmin-4.0.3-all-languages.tar.bz2
      
    That's the basics. You can find more info in the link provided above.

    You can find the latest version of phpMyAdmin here:http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/
    ps: to login phpMyAdmin, use your MySQL root username and password

    2 comments:

    educational blogs said...

    nice blog thanks for sharing this valuable information

    AWS in-house Corporate training in Nigeria

    pakkahouse said...

    pakkahouse

    PAKKAHOUSE IS AN INDIAN REALESTATE AND ECOMMERCE WEBSITE, THIS SITE ALSO CATERS FOR MANY
    BROKERAGE STOCK SITES AND ALSO EDU AND GOVERNMENT ADVERTISEMENT,
    FOR MORE INFORMATION AND UPDATE ABOUT NEWS PLEASE CLICK AND VISIT THE SITE FOR DAILY UPDATES.IT IS AN