進度條

在AWS上安裝Ruby On Rails(三) - Apache & passenger設定

更新日期:

1. t2.micro 只有1GB 的RAM,在編譯passenger的時候會不夠記憶體

   所我們要生出虛擬記憶體

$ sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=2048    // 2GB

$ sudo chmod 0600 /var/swap.1

$ sudo /sbin/mkswap /var/swap.1

$ sudo /sbin/swapon /var/swap.1

 

這樣就可以加入swap成功

如果想要開機後直接包含swap

修改 /etc/fstab

$ sudo vim /etc/fstab

加入

/var/swap.1 swap swap defaults 0 0

即可

 

 

2. 下載passenger

$ gem install passenger --no-document

 

3. 安裝Apache

$ sudo yum install libcurl-devel httpd-devel apr-devel apr-util-devel -y

 

4. 執行passenger的apache module installation

$ passenger-install-apache2-module

 

5. 修改 /etc/httpd/conf/httpd.conf

$ sudo vim /etc/httpd/conf/httpd.conf

加入下面字串,由passenger提供

LoadModule passenger_module /home/ec2-user/.rvm/gems/ruby-2.4.1/gems/passenger-5.2.3/buildout/apache2/mod_passenger.so

<IfModule mod_passenger.c>

  PassengerRoot /home/ec2-user/.rvm/gems/ruby-2.4.1/gems/passenger-5.2.3

  PassengerDefaultRuby /home/ec2-user/.rvm/gems/ruby-2.4.1/wrappers/ruby

</IfModule>

 

6. 加入VirtualHost

$ sudo vim /etc/httpd/conf.d/dev.conf

<VirtualHost *:80>

    # Change these 3 lines to suit your project

    RailsEnv development

    ServerName yourProject.domain.name

 

    DocumentRoot /var/www/YourProject/public

    <Directory /var/www/YourProject/public>

        # all requsts are allowe, no deny

        # example: http://httpd.apache.org/docs/2.4/upgrading.html

 

      Allow from all

      Options -MultiViews

    </Directory>

</VirtualHost>

 

7. 使用者權限

$ sudo usermod -a -G apache ec2-user

 

8. 登出後再登入

$ goups

 

9. 設定/var/www權限

$ sudo chown -R ec2-user:apache /var/www

$ sudo chmod 2775 /var/www

$ find /var/www -type d -exec sudo chmod 2775

$ find /var/www -type f -exec sudo chmod 0664

 

12. 放入專案於/var/www/YourProject

 

11. 設定好,開啟Apache

$ sudo service httpd start

或是重開

$ sudo service httpd restart