Setup a Lnmp on Ubuntu 12.04
Setup a Lnmp on Ubuntu 12.04
吴下阿吉 发表于4年前
Setup a Lnmp on Ubuntu 12.04
  • 发表于 4年前
  • 阅读 135
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

1.0 Nginx

1.1 Download

download address

1.2 Get dependencies

uzip:

unzip to a location

1.3 Install

<!-- lang: shell -->
cd ~/Downloads
tar xvf nginx-1.4.3.tar.gz ~/src/nginx-1.4.3
cd ~/src/nginx-1.4.3
./configure --prefix=~/app/nginx-1.4.3 ----with-pcre=~/src/pcre-8.33 --with-zlib=~/src/zlib-1.2.8 --with-openssl=~/src/openssl-1.0.1e
make
sudo make install

1.4 Setup as a service

<!-- lang: shell -->
sudo gedit /etc/init.d/nginx
#! /bin/sh
# the right or left side of the equal sign doesn't have blank space. 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DESC="Nginx daemon"
NAME=nginx

NGINX_HOME=~/app/nginx-1.4.3
DAEMON=$NGINX_HOME/sbin/$NAME
CONFIGFILE=$NGINX_HOME/conf/$NAME.conf
PIDFILE=$NGINX_HOME/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
    $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
    kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}

do_reload() {
    kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}

case "$1" in
    start)
        echo -n "Starting $DESC: $NAME"
        do_start
            echo "."
        ;;
    stop)
        echo -n "Stopping $DESC: $NAME"
            do_stop
                echo "."
         ;;
    reload|graceful)
         echo -n "Reloading $DESC configuration..."
             do_reload
                echo "."
          ;;
    restart)
          echo -n "Restarting $DESC: $NAME"
              do_stop
              do_start
                   echo "."
           ;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
    exit 3
     ;;
esac
sudo update-rc.d nginx defaults

1.5 Test

<!-- lang: shell -->
sudo service nginx start
# http://localhost

2.0 MySQL

2.1 Download

download address

2.2 Install

<!-- lang: shell -->
tar -xvf ~/Download/mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz ~/app/mysql-5.6.14
sudo groupadd mysql
sudo useradd -r -g mysql mysql
cd ~/app/mysql-5.6.14
sudo chown -R mysql
sudo chgrp -R mysql
sudo ./scripts/mysql_install_db --user=mysql
sudo chown -R root .
sudo chown -R mysql data
sudo ./bin/mysql_safe --user=mysql &

2.3 Setup as a service

<!-- lang: shell -->
sudo cp ./support-files/mysql.server /etc/init.d/mysql
sudo cp support-files/mysql-default.cnf /etc/my.cnf
sduo update-rc.d mysql defaults

2.4 Configuration

<!-- lang: shell -->
sublime ~/.profile
# mysql
export PATH="$PATH:$HOME/app/mysql-5.6.14/bin"

sudo ./bin/mysqladmin -u root password 'xxx'

2.5 Test

<!-- lang: shell -->
sudo service mysql start
mysql -u root -p

3.0 PHP

3.1 Download

download address

3.2 Before install

<!-- lang: shell -->
sudo apt-get install libxml2 libxml2-dev

3.3 Install

<!-- lang: shell -->
cd ~/Downloads
tar xvf php-5.5.5.tar.gz ~/src/php-5.5.5
cd ~/src/php-5.5.5
./configure --prefix=~/app/php55 --enable-fpm --with-mysql=~/app/mysql-5.6.14 --with-pdo-mysql=~/app/mysql-5.6.14
make
sudo make install

3.4 Config PHP-FPM

<!-- lang: shell -->
cd ~/app/php55/etc
cp ./php-fpm.conf.default ./php-fpm.conf
sudo gedit ./php-fpm.conf
# remove ; on line 25    
# set user = xxx group = xxx on line 148

3.5 Run PHP-FPM

<!-- lang: shell -->
cd ~/app/php55/sbin
sudo ./php-fpm
netstat -anp | grep 9000  # check output like: tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN

3.6 Setup as a service

<!-- lang: shell -->
cd ~/src/php-5.5.5
sudo cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
sudo update-rc.d php-fpm defaults

3.7 Config Nginx for PHP

<!-- lang: shell -->
sudo gedit ~/app/nginx-1.4.3/conf/nginx.conf
# append following content in first 'server{}'
location ~ \.php$ {
    root          html;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include       fastcgi_params;
}
# save

3.8 Write and run PHP script

<!-- lang: shell -->
# confirm nginx and php-fpm are running.    
cd ~/app/nginx-1.4.3/html
gedit phpinfo.php
# <?php phpinfo(); ?>
# save
# http://localhost/phpinfo.php
共有 人打赏支持
粉丝 34
博文 33
码字总数 9287
×
吴下阿吉
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: