ubuntu下apache+passenger+php+mysql

一.安装apache2+php+mysql

sudo apt-get install mysql-server mysql-client
sudo apt-get install libmysql-ruby libmysqlclient15-dev

sudo apt-get install apache2
#/var/www
#/etc/apache2/apache2.conf

sudo apt-get install php5 libapache2-mod-php5

#重启apache
sudo /etc/init.d/apache2 restart

#vim info.php in /var/www
sudo chmod 777 /var/www/

sudo apt-get install php5-mysql php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

#重启apache
sudo /etc/init.d/apache2 restart

sudo apt-get install phpmyadmin
#自动安装在/usr/share/phpMyAdmin下,将phpMyAdmin拷贝到/var/www目录下面
sudo cp -R /usr/share/phpmyadmin /var/www/
#重启apache
sudo /etc/init.d/apache2 restart

二.安装passenger

https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
sudo apt-get install apt-transport-https ca-certificates
。。。。。。
#参考官网

三.配置apache支持passenger

#启用重写模块
sudo a2enmod rewrite

#/etc/apache2/sites-available/test.com
<VirtualHost *:80>
    ServerName test.com
    DocumentRoot /home/flowerwrong/dev/ruby/rails/thecampus/public
    <Directory /webapps/mycook/public>
        Allow from all
        Options -MultiViews
    </Directory>
</VirtualHost>

sudo a2ensite test.com

编辑/etc/apache2/mods_aviable/passenger.conf

修改正确的ruby路径

重启

#/etc/apache2/mods-available/passenger.conf

<IfModule mod_passenger.c>
  PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
  PassengerDefaultRuby /home/flowerwrong/.rvm/wrappers/default/ruby
</IfModule>

四.配置应用

RAILS_ENV=production rake db:create db:migrate
rake assets:precompile

五.github案例

https://gist.github.com/bradmontgomery/1587015

# Install rvm system-wide
bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
 
# Update the packages
apt-get update
apt-get upgrade
apt-get install build-essential
 
# get the packages required by ruby
rvm pkg install zlib
rvm pkg install openssl
 
# install the latest ruby (and make it the default)
rvm install 1.9.3
rvm 1.9.3 --default
 
# install the passenger gem
gem install passenger
 
# Try installing the apache module and watch it fail (no apache, yet)
passenger-install-apache2-module
 
# Install the following required packages (as per passenger's instructions)
apt-get install libcurl4-openssl-dev libssl-dev zlib1g-dev apache2-mpm-prefork apache2-prefork-dev libapr1-dev libaprutil1-dev
 
# Create /etc/apache2/mods-available/passenger.load and include:
cat >> /etc/apache2/mods-available/passenger.load <<END_CONF
   LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p0/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
END_CONF
 
# Then create /etc/apache2/mods-available/passenger.conf
cat >> /etc/apache2/mods-available/passenger.conf <<END_CONF
   PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p0/gems/passenger-3.0.11
   PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.3-p0/ruby
END_CONF
 
# Symlink passenger.conf and passenger.load to /etc/apache2/mods-enabled/
cd /etc/apache2/mods-enabled
ln -s ../mods-available/passenger.conf .
ln -s ../mods-available/passenger.load .
 
# Update your app's apache config in /etc/apache2/sites-available/appname with something similar to the following:
 
	<VirtualHost *:80>
		ServerAdmin webmaster@localhost
		DocumentRoot /home/user/appname/public
		<Directory /home/user/appname/public>
			AllowOverride all 
         		Options -MultiViews
		</Directory>
	</VirtualHost>
 
# Then symlink this file from /etc/apache2/sites-enabled and reload apache:
cd /etc/apache2/sites-enabled
ln -s ../sites-available/appname .
/etc/init.d/apache2 reload

相关推荐