PHP on Amazon AWS, Install PHP on AWS and Run Crontab on AWS

22,280 views
21,993 views

Published on

This Article Describe Install PHP on Amazon AWS with Amazon EC2 and setup Crontab on AWS.

Published in: Technology
5 Comments
7 Likes
Statistics
Notes
  • Really love your guide, the screenshots made it really easy to understand each steps. However, it will still be too complicated for someone who does not have sysadmin experience or don't know how to use CLI. For them, I would recommend this guide: http://www.cloudways.com/blog/host-php-on-aws-cloud/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @chintankotadia7 i think because you have n't write anything on the file... make sure.
    1. after command crontab -e
    2. press the INSERT key to write on the file. (Now write the command). (first line)
    3. Press enter for blank line. (this should be second line)
    4. Use ESC key for close the editing.
    5. then type :x for save changes (this will installed a new crontab)

    if nothing is changed, then message appear 'no changes made', else message is 'installing new crontab'
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Thanks for the response.

    Currently, it says that 'no changes made to crontab'. Can you please let me know what am I doing wrong here?
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • @chintankotadia7

    :x command is used for close the operation with save changes.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • i setup crontab step by step but i dont know what is the x command??
    plz reply.
    thanks.........
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
22,280
On SlideShare
0
From Embeds
0
Number of Embeds
152
Actions
Shares
0
Downloads
412
Comments
5
Likes
7
Embeds 0
No embeds

No notes for slide

PHP on Amazon AWS, Install PHP on AWS and Run Crontab on AWS

  1. 1. Installing PHP on Amazon EC2 (Using Amazon Linux AMI) Kamal Sharma
  2. 2. Requirements Amazon Web Services Account WinSCP (for transfer files) PuTTY (SSH client) Create and Launch Amazon Linux AMI Create Security Group Log in to Amazon Management Console with your username and password. Switch to EC2 Tab. On the Network & Security tab click on Security Groups to view and create Security Groups. Security Group frame is active, where all Security Group is listed. Click Create Security Group button to create new group. Popup window will open, fill the required fields.
  3. 3. New Group created with name MyTestGroup. Assign ports to security group using inbound tab. select option from Create a new rule drop down. 22 (SSH) – Port 22 is used for connecting SSH server. 80 (HTTP) – Default port of Web server. Apply Rule Changes Create Key Pairs On the Key Pairs Panel, click on Create Key Pair button. Fill desired Key Pair Name.
  4. 4. Key Pair is created successfully and able to download on your local disk. Convert Key Pair to PuTTY Format PuTTY can’t read (.PEM) files that provide by Amazon. It understands its own (.PPK) format. We can translate the (.PEM) file format to (.PPK) file format using PuTTYgen. Open PuTTYgen; most probably locate in (c:/program files/putty/puttygen.exe) Find the (.PEM) file using Load button.
  5. 5. Key Passphrase like a password, you can leave this field blank otherwise it authenticate when you connecting to instance. Save private key on your disk. Create Instance On Amazon EC2 Console Dashboard, Launch the instance using Launch Instance button. Choose an Amazon Machine Image (AMI) from one of the tabbed lists below by clicking its Select button.
  6. 6. Pick a meaningful name for your Instance, select Edit details to choose your Security Group Instance is launched and Public DNS is available. Pick a meaningful name for your Instance, select Key Pair and choose Amazon Linux AMI Security Group and Instance Type, click Edit details. is available. Amazon Linux AMI. Click Continue.
  7. 7. Controlling Instance via PuTTY In Auth section, browse your private key file for authentication. Use Public DNS as Host Name. Connection Type to SSH And Port 22
  8. 8. After connecting to server, on terminal login as ec2-user Change the user (ec2-user) to root with the following command. sudo -i If you try to open Public DNS URL, browser throws error Unable to connect because server is not installed on AMI. First need to install Apache server with following command. yum install httpd Type and Enter y to confirm installation.
  9. 9. After Apache is successfully installed, start the Apache with following command. service httpd start Test the URL (Public DNS), Apache is installed and running successfully.
  10. 10. Installing PHP Install PHP using following command. yum install php If you need to install separate package such as MySQL, IMAP etc. Name Package MySQL php-mysql GD php-gd XML php-xml IMAP php-imap yum install php php-mysql php-gd php-xml php-imap
  11. 11. After install PHP, need to restart Apache to take effect, use the following command to restart Apache. service httpd restart Transferring Files For transferring files need SCP client such as WinSCP. Open WinSCP, use Public DNS as Host name User name as ec2-user Browse your Private Key file. And Choose File protocol - SCP After successful login move to root directory (Server Path). /var/www/html
  12. 12. Use drag and drop for transfer files (client to server) error message such as Permission denied directory. So need to change the Permission for ec2 chgrp (Change Group Permission) chmod (Change File Permission) After edit the permission, files successfully transferred. (client to server), when you trying to transfer file, WinSCP generate an Permission denied because ec2-user don’t have permission to copy files Permission for ec2-user. The following command need to change chgrp (Change Group Permission) – chgrp -R “user” “directory” chmod (Change File Permission) – chmod permission “directory” edit the permission, files successfully transferred. hen you trying to transfer file, WinSCP generate an permission to copy files in root . The following command need to change the permissions. R “user” “directory” chmod permission “directory”
  13. 13. Test the URL, PHP is successfully installed. Second method, transfer files without changing the group permission for ec2 ec2-user directory path in (httpd.conf) Enable SEO Friendly URLs Support (.htaccess) By default, Amazon not provides this option with (httpd.conf) configuration. Testing the clean URL with browser, it First needs to edit the (httpd.conf) file command. installed. without changing the group permission for ec2-user; change the (httpd.conf) file. URLs Support (.htaccess) this option with Apache installation; need to interfere with browser, it generates an error because Apache not able to handle (.htaccess) file. (httpd.conf) file in etc/httpd/conf for editable by ec2-user with the following change the server path to interfere with Apache not able to handle (.htaccess) file. with the following
  14. 14. Chgrp –R “ec2-user” “/etc/httpd/conf/httpd.conf” Chmod 0774 “/etc/httpd/conf/httpd.conf” Open the directory (/etc/httpd/conf) using WinSCP and edit the (httpd.conf) file. You need to change the AllowOverride None To AllowOverride all Restart the Apache with service httpd restart Apache commands
  15. 15. Start - service httpd restart Stop – service httpd stop Restart – service httpd restart Test and SEO friendly URL is working. Running CronJobs Cron is a time-based job scheduler in Unix Cron Job commands: crontab -l – Listing the running cron. crontab -r – Removing the running cron. crontab -e – creating and editing the cron. Checking the any Cron Job is running for the user crontab -l Sample Cron Job for every one minute. Min Hour Day of Month Month of Year * * * * * * * * * php /var/www/html/mycronfile.php Create Cron Job using following command service httpd restart service httpd restart is working. based job scheduler in Unix-like computer operating systems. Listing the running cron. Removing the running cron. creating and editing the cron. Checking the any Cron Job is running for the user with the following command. for every one minute. Month of Year Day of Week Commands * php filePath * * * * * php /var/www/html/mycronfile.php Create Cron Job using following command
  16. 16. crontab -e After CronTab editor open, press the insert key to write on the file. Press enter for blank line. Use ESC key to close the editing Type : x command and press enter to close and save changes. Cron Job is installed.

×