linux+php+mysql配置

来源:互联网 发布:手机wifi网络测试软件 编辑:程序博客网 时间:2024/05/21 08:35

linux+php+mysql配置  

2013-07-3122:46:06|  分类: 默认分类|举报|字号 订阅

LAMPLinux, Apache, MySQL, PHP的缩写.这篇教程将教你如何在一台Fedora 12服务器上安装Apache2web服务器+PHP(mod_php) +MySQL .

我已经测试无误,你可以放心使用。

1. 前言


在这篇教程中,我使用的主机名为server1.example.comip地址是192.168.0.100。这些设置可能与你想要的有所不同,所以你必须在适当的地方修改一下。

2 安装MySQL5


用下列命令安装MySQL

yum install mysqlmysql-server


然后我们为MySQL创建系统启动链接(这样的话,MySQL就会随着系统启动而启动),并启动MySQL服务器:

chkconfig --levels235 mysqld on
 /etc/init.d/mysqld start


运行

mysqladmin -u rootpassword yourrootsqlpassword
 mysqladmin -h server1.example.com -uroot password yourrootsqlpassword


来为root用户设置一个密码(否则任何人都可以访问你的MySQL数据库!)

3 安装Apache2


Fedora
默认有Apache2这个包,我们可以用下列命令安装它:

yum install httpd


现在配置下系统使得Apache能够随着系统启动而启动

chkconfig --levels235 httpd on


...
启动Apache:

/etc/init.d/httpdstart


现在打开浏览器,访问http://192.168.0.100,你就应该能看到Apache2的预留页了:



FedoraApache的默认文档路径在/var/www/html,配置文件是/etc/httpd/conf/httpd.conf。其余的配置文件存储在/etc/httpd/conf.d/

安装PHP5

我们用下列命令安装PHP5Apache PHP5模块:

yum install php


然后我们启动下Apache

/etc/init.d/httpdrestart


测试PHP5/获取PHP5安装后的详细信息

网站的默认文档路径是/var/www/html。我们现在在这个文件夹中创建一个小型PHP(info.php)文件,并在;浏览器中访问它。这个文件会显示关于PHP安装的大量的细节,例如PHP的版本。

vi/var/www/html/info.php
 
 <?php
 
 phpinfo();
 
 ?>


现在我们在浏览器中访问这个文件(例如http://192.168.0.100/info.php)



如你所看到的一样,PHP5已经正常工作了,并且在Server API这一行中显示的Apache是以Apache2.0 Handler模式工作的。如果你向下翻页,你将会看到已经安装了PHP5的所有的模块。MySQL没有在这里列出来,也就意味着目前PHP5并不支持 MySQL

6 PHP5支持MySQL


我们安装php-mysql这个包既可以使MySQL支持php了。在这里最好也安装其他的PHP5模块,这些模块也许你会在其他的应用中用到。你可以使用下列明星先搜索一下PHP5的模块:

yum search php


选取你需要的模块,并使用下列命令安装它们:

yum installphp-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpcphp-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstringphp-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy


现在重启Apache2:

/etc/init.d/httpdrestart


现在在浏览器中刷新http://192.168.0.100/info.php,并再次翻到模块部分。你就应该能在这里找到很多新模块,其中就包括了MySQL模块:

7 phpMyAdmin


phpMyAdmin是一款可以web化管理MySQL数据库的工具:

可以使用下列命令安装phpmyadmin(试多几次,有时一次不行)
装后了,莫认只有127.0.0.1的可以,也就是本地才可以仿问,为了安全

yum installphpmyadmin


现在我们配置phpMyAdmin。我们改变Apache的配置文件让其只能通过本地访问(通过注销<Directory /usr/share/phpMyAdmin/参数):
(可以不用去设,莫认设好了只有本地可以仿问)

vi/etc/httpd/conf.d/phpMyAdmin.conf
 
 # phpMyAdmin - Web based MySQL browserwritten in php
 #
 # Allows only localhost by default
 #
 # But allowing phpMyAdmin to anyoneother than localhost should be considered
 # dangerous unless properly secured bySSL
 
 Alias /phpMyAdmin /usr/share/phpMyAdmin
 Alias /phpmyadmin /usr/share/phpMyAdmin
 #
 #   order deny,allow
 #   deny from all
 #   allow from 127.0.0.1
 #   allow from ::1
 #
 
 # This directory does not require accessover HTTP - taken from the original
 # phpMyAdmin upstream tarball
 #
 
     Order Deny,Allow
     Deny from All
     Allow from None
 
 
 # This configuration preventsmod_security at phpMyAdmin directories from
 # filtering SQL etc.  This maybreak your mod_security implementation.
 #
 #
 #   
 #       SecRuleInheritance Off
 #   
 #
 


重启Apache:

/etc/init.d/httpdrestart


然后,你就可以通过http://192.168.0.100/phpmyadmin/:访问phpMyAdmin

8 相关链接

 


   

·        Apache: http://httpd.apache.org/ 
   

·        PHP: http://www.php.net/ 
   

·        MySQL: http://www.mysql.com/ 
   

·        Fedora: http://fedoraproject.org/ 
   

·        phpMyAdmin: http://www.phpmyadmin.net/ 


9
相关声明

源地址:http://www.howtoforge.com/installing-apache2-with-php5-and-mysql-support-on-fedora-12-lamp

0 0
原创粉丝点击