亚马逊amazon ec2 lamp配置教程
Why build your own when there are a lot of community options?
I don't know, go try them and come back if you need to build your own. This article will help you build a LAMP (Linux, Apache, MySQL, PHP) server from a default Amazon AMI cloud image.
This article assumes you can create an EC2 image and connect to it, and focuses on what to do next.
First off, update the server!. From the command line, run:
sudo yum update
and follow the prompts until the system is up to date.
The default AMI machine doesn't have Apache on it by default. The easiest way to install the latest available (to the Amazon image, anyway) version is to run the following commands:
sudo yum install httpd
sudo yum install mod_ssl
sudo yum install mysql
sudo yum install mysql-server
sudo yum install php
sudo yum install php-mysql
If you want to install specific versions, you may need to build from source. If you want to do this, see my how to compile Apache2, PHP5, and MySQL page.
Now you've installed them, but nothing is really ready to go yet. Let's start with MySQL:
sudo ./mysqld start
and follow the prompts from the script to create a password for the mysql user, remove the public test database, etc.
Next, let's fix the startup scripts, because right now only MySQL is running, Apache is stopped. If you reboot the machine, neither will start by default:
sudo rm K15httpd
sudo rm K36mysqld
By default, AMI images start at runlevel 3 (cf. /etc/inittab). Now that we've removed the roadblocks to getting the services started, let's link them up. From the same directory (/etc/rc.d/rc3.d), run:
sudo ln -s ../init.d/mysqld S30mysql
sudo ln -s ../init.d/httpd S85httpd
You can adjust the start priorities if you want, this is just a suggestion.
You will probably need to make a few changes to the Apache config file before your website is ready to start up, so:
sudo vi /etc/httpd/conf/httpd.conf
and make any changes you need. Always test your config file before trying to run Apache, it will save you downtime and heartache: just run
httpd -t and it will check your syntax.
I always move my web directories and logfiles, etc to a /www directory. If you do this, make sure you update logrotate appropriately. A busy server can run out of space if you don't watch your logfile growth.
sudo vi /etc/logrotate.d/httpd
Now, start up Apache and you're ready to go:
sudo /etc/rc.d/init.d/httpd start