文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>lamp相关设置与备忘

lamp相关设置与备忘

时间:2007-06-27  来源:oliliango

    同学的机器升级了,留下了一台p4+128M的机器正好可以作为服务器使用,在局域网里面假设一个网络服务器也是很就以来一直都有的想法。现在有了基本的机器组件了,室友又给上面加了60G的hdd,ok,可以开始了。论坛是必不可少的,可以公布一些公告,给大家一个灌水的地方。同学里面有个php达人的话就简单了很多,只需要搞定php环境,再有个基本的php论坛程序,就可以自定义加个性化了。在这样的需求下,lamp显然是最合适的选择了。在这里,我显然不想再说说什么是lamp了。
 
   系统就安装了fc6,其实本来是准备安装fc7的,但是种种原因没有成功,也不知道是怎么回事,怀疑是室友提供的hdd的问题。在fc6装好之后,随便搞搞ftp就通了,上面放些软件什么的也挺好。前段时间也没有看,以为“php达人”同学已经搞定了。昨天问问他才知道原来有奇怪的错误而导致一直卡在php和mysql的问题上。于是昨天晚上就登上去看看咯,结果在用phpmyadmin和mysql连接的时候出了问题,错误消息如下:

  #2002 - 服务器没有响应 (or the local MySQL server's socket is not correctly configured)

    真是奇怪的错误了,用mysql的控制台一直都是好好的,不知如何phpmyadmin就是不工作,网上对此的解释就多而且怪了,大多集中在selinux这个罪魁祸首上,不过在这台server上我早就把selinux干掉了啊。仔细端详他的错误提示,看来还是没有找到mysql的原因。原来,在phpmyadmin里面config.inc.php里面配置的host是localhost,而本机的机器名称被改掉了,难道是同学说的主机解析文件/etc/hosts里面设置的问题? 
    所以,上phpmyadmin里面改config.inc.php文件,把host域里面的localhost改成本机的ip。bingle。一切ok!
     顺便复习复习apache的虚拟目录设置和mysql的使用方式。不错。哈哈。
     把自己写的一些备忘开列如下:
    1.如要能够执行cgi脚本需要在httpd的conf中加入:
AddHandler cgi-script .cgi .pl
     以及在directory域中加入ExecCGI的Option

    2.apache的conf备忘:

DocumentRoot "/var/www/html" 设置主目录的路径
Servername 192.168.1.100  指定服务器的名称或者ip地址
DirectoryIndex  index.html index.htm index.php index.pl index.html.var
设定主页的文件名,而且在设置目录属性的时候加上:MultiViews 选项的话,只需要敲入index,apache自动会匹配相应的后缀名,找到为止
Option ExecCGI 设置目录的属性,All比较特殊,包含除了MultiViews之外的所有选项
AllowOverride None 设置为不使用目录下的.htaccess来设置子项目属性
Order allow,deny 注意,后面的deny会覆盖前面的allow
Allow from 192.168.1.3
Deny from all

    成对使用来定义一个虚拟目录,并建立用户认证:

Alias  /mysec "/usr/local/mysec"
 
<Directory "/usr/local/mysec">
AuthType Basic
AuthName "xxxxxx"
AuthUserFile /etc/httpd/mysecpwd  此处的mysecpwd文件在下文中说明用htpasswd建立
Require user xxxxxx dang
</Directory>

    设置密码及其文件:
htpasswd -c /etc/httpd/mysecpwd xxxxxx 这个命令可以用来创建一个文件,并设置用户“xxxxxx”的密码
htpasswd /etc/httpd/mysecpwd dang 则是设置用户“dang”的密码并将条目添加到/etc/httpd/mysecpwd文件中

    下面的配置是建立虚拟主机时使用的,而上文中所提到的嵌套关系可以在这里嵌套到VirtualHost这个里面去。如果一个主机使用了多个网卡,或者绑定了多个ip,就可以在这里使用基于不同的ip的虚拟主机。
<VirtualHost 192.168.1.1>
ServerName 192.168.1.1:80
ServerAdmin [email protected]
DocumentRoot "/var/www/web1"
DirectoryIndex index.html
ErrorLog logs/web1/error_log
CustomLog logs/web1/access_log combined
</VirtualHost>
 
<VirtualHost 192.168.1.2>
ServerName 192.168.1.2:80
ServerAdmin [email protected]
DocumentRoot "/var/www/web2"
DirectoryIndex index.html
ErrorLog logs/web2/error_log
CustomLog logs/web2/access_log combined
</VirtualHost>

       而如果是一个ip而采用不同的域名来实现多个虚拟主机,则可以采用如下的配置:
<VirtualHost www.abc.com>
ServerName www.abc.com:80
ServerAdmin [email protected]
DocumentRoot "/var/www/web1"
DirectoryIndex index.html
ErrorLog logs/web1/error_log
CustomLog logs/web1/access_log combined
</VirtualHost>
 
<VirtualHost www.xyz.com>
ServerName www.xyz.com:80
ServerAdmin [email protected]
DocumentRoot "/var/www/web2"
DirectoryIndex index.html
ErrorLog logs/web2/error_log
CustomLog logs/web2/access_log combined
</VirtualHost>

    3.cgi的配置和测试

    AddHandler cgi-script .cgi .pl 说明这些后缀名的都是cgi程序
    测试cgi环境:
测试perl环境:
test.pl
#!/usr/bin/perl
print "Content-type: text/html\n\n"; 这一句是不可少的
print "this is a test!";   注意这里的分号
 
设置/etc/httpd/conf.d/php.conf中的一行为:
AddType application/x-httpd-php .php .php3
 
测试php环境:
test.php:
<? phpinfo(); ?>

    4.mysql的命令备忘

mysql -h localhost -u root -p
 
setup passwd:
mysqladmin -u root password xxxxxxxx
 
modify passwd:
mysqladmin -u root password newpassword
 
show databases;
show tables;
 
use a database:
use mysql;
 
create a database:
create database xxxx;
 
drop a database:
drop database xxxx;
 
 
add a new user & setup it's privilege:
grant all on *.* to mysql@'%' identified by password('passxxx');
 
verify user informations:
select host,user,password,select_priv from mysql.user;

    5.phpmyadmin和discuz备忘
       phpMyAdmin的配置文件:config.inc.php中的典型片断如下:

$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'mysql';
$cfg['Servers'][$i]['password'] = 'mysqpassword';
$cfg['Servers'][$i]['onlydb'] = '';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = '';
$cfg['Servers'][$i]['controlpass'] = '';
/* Advanced phpMyAdmin features */

    use phpMyAdmin:
        install php-mysql
        install php-mbstring
        verify file:
        /etc/php.ini ,add a line:
extension=mbstring.so
 
    install discuz:
        unzip & run install.php from web-broswer
相关阅读 更多 +
排行榜 更多 +
冰封前线1941无限金币版

冰封前线1941无限金币版

策略塔防 下载
头文字d公路传说手机版

头文字d公路传说手机版

模拟经营 下载
火车站模拟器手机版

火车站模拟器手机版

模拟经营 下载