命令行安装与配置Ubuntu+Nginx+Mysql+Php+Zend+eaccelerator的教程
1、安装ubuntu server 10.04或10.10,其中安装语言选的en,时区shanghai,服务只安装ssh,其他全部用默认就行。
代码: 因为以下过程得输入大量命令和代码,在客户机上直接粘贴即可(在windows下的putty中单击右键即可把剪贴板中的内容粘贴到终端)。
2、添加源:
lucid(10.04)的源添加如下:
复制代码代码如下:
deb http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ lucid main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ lucid-security main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ lucid-updates main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ lucid-backports main restricted universe multiverse deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main deb http://ppa.launchpad.net/brianmercer/php/ubuntu lucid main
maverick(10.10)的源:
复制代码代码如下:
deb http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ maverick main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse deb-src http://archive.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse deb http://ppa.launchpad.net/nginx/stable/ubuntu maverick main
最后一行为nginx的ppa源,需要添加key,在终端运行:
3、更新
4、安装网站系统
复制代码代码如下:
sudo apt-get install nginx php5-common php5-dev php5-cgi php5-fpm php-apc php5-mysql php5-curl php5-gd php5-idn php-pear php5-mcrypt php5-memcache php5-ming php5-recode php5-tidy php5-xmlrpc php5-xsl mysql-server
上面为必选安装,以下php组件为可选安装,一般网站程序可能用不着:
复制代码代码如下:
sudo apt-get install php5-imagick php5-imap php5-recode php5-snmp php5-sqlite php5-xmlrpc php5-suhosin php5-odbc php5-ladp
5、修改nginx配置文件
把其中的:
复制代码代码如下:
location / {
root /var/www; index index.html index.htm; }
改为:
复制代码代码如下:
location / {
root /var/www/nginx-default; index index.php index.html index.htm; }
其中的:
复制代码代码如下:
#location ~ \.php$ {
# fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # include fastcgi_params; #}
改为:
复制代码代码如下:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; include fastcgi_params; }
6、更改网站目录权属: 注:其中的ubuntu为系统登录用户名。
7、安装ZendGuardLoader及eaccelerator:
复制代码代码如下:
sudo mkdir /usr/zend
mkdir /tmp/eaccelerator chmod 0777 /tmp/eaccelerator wget http://phpcj.googlecode.com/files/ZendGuardLoader.so sudo mv ZendGuardLoader.so /usr/zend/ZendGuardLoader.so wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2 tar xvjf eaccelerator-0.9.6.1.tar.bz2 cd eaccelerator-0.9.6.1 cp control.php /var/www/nginx-default/control.php //复制控制程序到网站目录,通过http://网站名/control.php访问,默认帐号为admin,密码为eAccelertor,可编辑此文件修改。 phpize sudo ./configure --enable-eaccelerator=shared sudo make sudo make install sudo vi /etc/php5/fpm/php.ini
在配置文件最后加上:
复制代码代码如下:
zend_extension=/usr/zend/ZendGuardLoader.so
zend_loader.enable=1 zend_loader.disable_licensing=0 zend_loader.obfuscation_level_support=3 zend_loader.license_path= zend_extension="/usr/lib/php5/20090626+lfs/eaccelerator.so" eaccelerator.shm_size="16" eaccelerator.cache_dir="/tmp/eaccelerator" eaccelerator.enable="1" eaccelerator.optimizer="1" eaccelerator.check_mtime="1" eaccelerator.debug="0" eaccelerator.filter="" eaccelerator.shm_max="0" eaccelerator.shm_ttl="0" eaccelerator.shm_prune_period="0" eaccelerator.shm_only="0" eaccelerator.compress="1" eaccelerator.compress_level="9" eaccelerator.allowed_admin_path="/var/www/nginx-default/control.php"
8、(可选步骤)安装phpmyadmin:
复制代码代码如下:
wget http://downloads.sourceforge.net/project/phpmyadmin/phpMyAdmin/3.3.9/phpMyAdmin-3.3.9-all-languages.tar.bz2
tar xvjf phpMyAdmin-3.3.9-all-languages.tar.bz2 mv phpMyAdmin-3.3.9-all-languages /var/www/nginx-default/phpmyadmin cd /var/www/nginx-default/phpmyadmin cp config.sample.inc.php config.inc.php vi config.inc.php
将其中的:
下面的:
复制代码代码如下:
// $cfg['Servers'][$i]['controluser'] = 'pma';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass'; // $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin'; // $cfg['Servers'][$i]['bookmarktable'] = 'pma_bookmark'; // $cfg['Servers'][$i]['relation'] = 'pma_relation'; // $cfg['Servers'][$i]['table_info'] = 'pma_table_info'; // $cfg['Servers'][$i]['table_coords'] = 'pma_table_coords'; // $cfg['Servers'][$i]['pdf_pages'] = 'pma_pdf_pages'; // $cfg['Servers'][$i]['column_info'] = 'pma_column_info'; // $cfg['Servers'][$i]['history'] = 'pma_history'; // $cfg['Servers'][$i]['tracking'] = 'pma_tracking'; // $cfg['Servers'][$i]['designer_coords'] = 'pma_designer_coords'; // $cfg['Servers'][$i]['auth_swekey_config'] = '/etc/swekey-pma.conf';
将//全部删除,然后将其中的:
复制代码代码如下:
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pmapass'; pma和pmapass修改为你的mysql用户名和密码,最后登录phpmyadmin,将phpmyadmin/scripts目录中的creat_tables.sql文件导入mysql。
9、重启系统、上传文件,网站建立成功。
附:系统及部分软件管理操作
复制代码代码如下:
sudo reboot now //重启系统
sudo halt //关闭系统
2、nginx配置修改及生效:
复制代码代码如下:
sudo vi /etc/nginx/nginx.conf //修改配置
sudo vi /etc/nginx/sites-enabled/default //修改配置 sudo service nginx restart //重启nginx
3、php配置修改及生效:
复制代码代码如下:
sudo vi /etc/php5/fpm/php.ini //修改配置
sudo service php5-fpm restart //重启fastcgi进程
3、网站目录:
4、eaccelerator管理:
5、修复nginx+php出现的重大漏洞、修改上传文件大小(可以看你自己的情况)
复制代码代码如下:
sudo vi /etc/php5/fpm/php.ini
cgi.fix_pathinfo = 0 //修复漏洞 upload_max_filesize = 2M改为5M //修改上传文件大小
6、设定防火墙
复制代码代码如下:
sudo ufw enable
sudo ufw default deny sudo ufw allow 80 sudo ufw allow 22
7、启动php5-fpm时,出现:
8、Discuz后台启动 URL静态化,会提示 404 Not Found的解决办法:
以下内容来自:http://www.vpsee.com/2011/04/some-nginx-rewrite-examples-for-subdirectories/,未测试。
复制代码代码如下:
rewrite ^/bbs/archiver/((fid|tid)-[\w\-]+\.html)$ /bbs/archiver/index.php?$1 last;
rewrite ^/bbs/forum-([0-9]+)-([0-9]+)\.html$ /bbs/forumdisplay.php?fid=$1&page=$2 last; rewrite ^/bbs/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /bbs/viewthread.php?tid=$1&extra=page%3D$3&page=$2 last; rewrite ^/bbs/space-(username|uid)-(.+)\.html$ /bbs/space.php?$1=$2 last; rewrite ^/bbs/tag-(.+)\.html$ /bbs/tag.php?name=$1 last;
Discuz! X1.5 安装在子目录 /bbs 下:
复制代码代码如下:
rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
(责任编辑:IT)rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last; rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last; rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last; rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last; rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last; rewrite ^([^\.]*)/([a-z]+)-(.+)\.html$ $1/$2.php?rewrite=$3 last; if (!-e $request_filename) { return 404; } |