Ubuntu中配置nginx + php + mysql伺服器

來源:互聯網
上載者:User

1.安裝php5

 代碼如下 複製代碼

apt-get install php-pear php5-cli php5-common php5-cgi php5-mysql php5-gd php5-dev

2.安裝mysql5

 代碼如下 複製代碼
apt-get install mysql-server mysql-client libipc-sharedcache-perl

3.安裝nginx

 代碼如下 複製代碼
apt-get install nginx

配置nginx如下

 代碼如下 複製代碼
sudo vi /etc/nginx/sites-available/default

修改點如下

 代碼如下 複製代碼
#這行增加index.php為預設檔案
index index.php index.html index.htm;

啟用fastcgi處理php指令碼

 代碼如下 複製代碼

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
#       # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
#       # With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
#       # With php5-fpm:
#       fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}

4.建立fastcgi的控制指令碼

 代碼如下 複製代碼
sudo vi /etc/init.d/php-cgi

內容如下

 代碼如下 複製代碼
#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000
PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS=”- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND”
RETVAL=0
start() {
echo -n “Starting PHP FastCGI: ”
start-stop-daemon –quiet –start –background –chuid “$USER” –exec /usr/bin/env — $PHP_CGI_ARGS
RETVAL=$?
echo “$PHP_CGI_NAME.”
}
stop() {
echo -n “Stopping PHP FastCGI: ”
killall -q -w -u $USER $PHP_CGI
RETVAL=$?
echo “$PHP_CGI_NAME.”
}
case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo “Usage: php-fastcgi {start|stop|restart}”
exit 1
;;
esac
exit $RETVAL

給/etc/init.d/php-cgi加上執行許可權

 代碼如下 複製代碼
sudo chmod +x /etc/init.d/php-cgi

啟動php-cgi進程

 代碼如下 複製代碼
sudo /etc/init.d/php-cgi start

要讓php-cgi隨系統開機啟動,可以通過如下命令

 代碼如下 複製代碼

sudo update-rc.d php-cgi defaults 25

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.