Amazon AWS

Материал из RSU WiKi
Перейти к: навигация, поиск
Pen.pngЭта статья находится в процессе написания.
Если вы считаете, что её стоило бы доработать как можно быстрее, пожалуйста, скажите об этом.


Содержание

Регистрация и создание вирт. машин

Не забудьте в "Security Groups" открыть 80 порт

Установка хостинга Wordpress (Nginx++PHP-CGI+MySQL+APC)

Установка ПО

Подготовка

sudo -i
apt-get -y update && apt-get -y upgrade

MySQL

apt-get -y install mysql-server mysql-client

Nginx

apt-get -y install nginx
/etc/init.d/nginx start 

Firewall

ufw allow ssh
ufw allow http
ufw logging off
ufw enable 
ufw status

PHP

apt-get -y install php5-fpm php5-mysql php5-gd php5-curl php5-mcrypt php5-geoip php5-imagick

PHP-акселератор

apt-get -y php-apc

или

apt-get -y php5-xcache

Edit /etc/php5/fpm/php.ini and add these lines at the bottom:

[apc]
apc.write_lock = 1
apc.slam_defense = 0

Настройка NGINX

nginx hosts are configured much the same as apache’s, this is using configuration files. The defaults in Ubuntu are:

/etc/nginx/sites-available/
/etc/nginx/sites-enabled/ 

You should edit and create your configuration files in the ‘sites-available’ directory, and then symlink them in the ‘sites-enabled’ directory.

Lets take a look at the default configuration. Run this command to open it up:

nano /etc/nginx/sites-available/default 

There’s a couple of things we need to add/edit to make nginx work with PHP. Add ‘index.php’ to this line, like so:

index index.html index.htm index.php; 

And then uncomment the following so the lines below are active, like so:

location ~ .php$ {
  fastcgi_split_path_info ^(.+.php)(/.+)$;
  fastcgi_pass unix:/var/run/php5-fpm.sock;  
  fastcgi_index index.php; include fastcgi_params;
} 

We also need to change the PHP configuration to use the Unix Socket as specified in our default configuration.

nano /etc/php5/fpm/pool.d/www.conf 

And then find the line:

listen = 127.0.0.1:9000 

and replace it with:

listen = /var/run/php5-fpm.sock 

Now we’ve made these changes it’s time to restart php5-fpm and nginx:

/etc/init.d/php5-fpm restart && /etc/init.d/nginx restart 

At this point we can test if php is working by adding the following:

<?php phpinfo(); ?> 

Into a file using this command:

nano /usr/share/nginx/www/info.php 

Now you should be able to see the PHP info page by going to:

ec2-XX-XXX-XXX-XX.eu-west-1.compute.amazonaws.com/info.php 

We’re now confident that we’re got nginx working with PHP and we can see the results! WOO!

Step Five – Installing WordPress

This is where we will install WordPress.

Creating a host

We’ll assume that you don’t want to use the default nginx configuration, so we’ll create our own. I’ll use the example ‘www.example.com’, you just need to change this to match your domain. Lets create a configuration file with this command:

nano /etc/nginx/sites-available/www.example.com And then copy this configuration into it, after changing the domain:

server {
  listen 80;
  server_name www.example.com example.com;
  root /var/www/www.example.com/public_html;
  if ($http_host != "www.example.com") {
            rewrite ^ http://www.example.com$request_uri permanent;
  }
  index index.php index.html;
  location = /favicon.ico {
           log_not_found off;
           access_log off;
  }
  location = /robots.txt {
           allow all;
           log_not_found off;
           access_log off;
  }
  # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
  location ~ /\. {
           deny all;
           access_log off;
           log_not_found off;
  }
  location / {
           try_files $uri $uri/ /index.php?$args;
  }
  # Add trailing slash to */wp-admin requests.
  rewrite /wp-admin$ $scheme://$host$uri/ permanent;
  location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
           expires max;
           log_not_found off;
  }
  location ~ \.php$ {
           try_files $uri =404;
           include /etc/nginx/fastcgi_params;
           fastcgi_pass unix:/var/run/php5-fpm.sock;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}

Enabling the host

Now lets sym-link the site to enable it, and we’ll also remove the default configuration:

cd /etc/nginx/sites-enabled/ ln -s /etc/nginx/sites-available/www.example.com www.example.com rm default And reload nginx

/etc/init.d/nginx reload Note: There’s no need to restart nginx when adding another host.

Setting up the web directory

Now we need to set up the web directory as we specified in the host configuration file:

mkdir -p /var/www/www.example.com/public_html Setting up MySQL

We’ll now create and setup the database and create a WordPress username/password, in this example I will call the database ‘wordpress’ the username will be ‘wpuser’ and the password ‘wppassword’ – please replace these with your own values when configuring yours.

Creating the database:

mysqladmin -u root -p create wordpress Adding the User

Log onto the mysql command line with your password which you chose earlier and this command:

mysql -u root -p Run these lines to add your new wordpress user:

GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost' IDENTIFIED BY 'wp_password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost.localdomain' IDENTIFIED BY 'wp_password'; FLUSH PRIVILEGES; quit; Installing WordPress

We’ll finally install WordPress! YAY! First lets download it into a temporary folder, and then move it to the right place:

cd /tmp wget http://wordpress.org/latest.tar.gz tar xvfz latest.tar.gz cd wordpress/ mv * /var/www/www.example.com/public_html/ Now we’ll allow nginx able to write to the directory so WordPress can modify its configuration files:

chown -R www-data:www-data /var/www/www.example.com/public_html/ WordPress comes with a sample configuration file, we’ll use it, but we just need to move it into place with:

mv /var/www/www.example.com/public_html/wp-config-sample.php /var/www/www.example.com/public_html/wp-config.php Now let’s add our sql setting:

nano /var/www/www.example.com/public_html/wp-config.php Now add your credentials:

/** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wp_user'); /** MySQL database password */ define('DB_PASSWORD', 'wp_password'); Step Six – Launching WordPress – First Time

To run the first time setup on WordPress you should now visit:

http://www.example.com/wp-admin/install.php BOOM – you should see WordPress, enter the site name, username (don’t use admin) and password. You should now be able to log onto WordPress.

Finishing up

I would suggest that you install the W3 Total Cache WordPress plugin which will purge the Varnish cache when you publish a post. You should enable the following to get best results:

Page Cache: Enabled – Opcode: Alternative PHP Cache (APC) Object Cache: Enabled – Opcode: Alternative PHP Cache (APC) Browser Cache: Enabled Varnish: Enabled – Varnish Servers: localhost Conclusion

Hopefully this should get you going with your set up. There is lots left out of this guide in terms of configuring WordPress, and more advanced Varnish configurations with support for a wider array of setups however this is all out of the scope of this guide. Google is your friend for taking this set up further.

Keep in touch

If you find anything wrong, or are having trouble shoot me an email and i’ll try my best to keep this up to date with your comment and suggestions.

Примечания


См. также

Ссылки

Личные инструменты
Пространства имён

Варианты
Действия
Навигация
Инструменты