http://www.unixbar.net/linux/fedora/1366.html


在Fedora 16服务器上搭建Apache2+PHP5+MySQL+phpMyAdmin(LAMP)

在Fedora 16服务器上搭建Apache2+PHP5+MySQL+phpMyAdmin(LAMP)
———————————————————————————————————–
版本1.0
作者: Falko Timme
翻译者:尚欣力
原文地址:http://www.howtoforge.com/installing-apache2-with-php5-and-mysql-support-on-fedora-16-lamp


写作日期: 11/13/2011
翻译日期: 06/07/2012
————————————————————————————————————————-
LAMP是 Linux, Apache, MySQL, PHP.首字母的缩写,这篇教程将会教会你如何在一台CentOS6.2服务器上安装Apache2 web服务器,并支持php5,和mysql。


1.前言

在这篇教程中,我是用的主机名是server1.example.com ,IP地址是 192.168.0.100这些设置可能会与你的有些不通,因此你需要在适当的地方修改你自己的配置。


2.安装MySQL5

通过下列命令安装MySQL


yum install mysql mysql-server


然后我们为MySQL创建系统启动链接(这样得话,MySQL就会在系统启动的时候自动启动),并启动你的MySQL服务器:


systemctl enable mysqld.service
systemctl start mysqld.service


 


运行


mysql_secure_installation


为MySQL root用户创建一个密码(否则任何用户都能够访问你的MySQL数据库!):


[root@server1 ~]# mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.


Enter current password for root (enter for none):OK, successfully used password, moving on…


Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.


Set root password? [Y/n]New password:


Re-enter new password: Password updated successfully!
Reloading privilege tables..
… Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.


Remove anonymous users? [Y/n]… Success!


Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n]… Success!


By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.


Remove test database and access to it? [Y/n] – Dropping test database…
… Success!
- Removing privileges on test database…
… Success!


Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.


Reload privilege tables now? [Y/n]… Success!


Cleaning up…


All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.


Thanks for using MySQL!


[root@server1 ~]#


3.安装Apache2

Apache2在Fedora的源中,我们可以通过下列命令安装它:


yum install httpd


现在配置Apache,让它随系统而启动。


systemctl enable httpd.service


启动Apache


systemctl start httpd.service


现在你就可以访问http://192.168.0.100,,你会看到Apache的预留页面了:



在Fedora上,Apache的默认文档路径在 /var/www/html 。配置文件是 /etc/httpd/conf/httpd.conf,其他的配置文件在/etc/httpd/conf.d/文件夹中。


4.安装PHP5

我们可以通过下列命令安装PHP5和PHP5兼容Apache模块:


yum install php


安装完成后,必须重启Apache


systemctl restart httpd.service


5 测试你安装的PHP5和获得PHP5参数

默认站点的文档路径在/var/www/html。我们首先在这个目录里面创建一个小的探针文件(info.php),并在浏览器中访问。这个文件会显示你的PHP5安装的参数和版本等信息,


vi /var/www/html/info.php


现在我们在浏览器中访问(本文的路径为. http://192.168.0.100/info.php)



正如你所看到的,PHP5在Server API这一行中显示的已经以Apache 2.0 Handler模式正常工作了,如果你继续往下翻动页面,你会看到PHP5支持的模块,MySQL
并不在此列,这说明我们还没有整合PHP5和MySQL。


6,整合MySQL和PHP5

要整合PHP和MySQL,我们需要安装php-mysql这个包,在这里最好一起安装其他的PHP5模块。你可以通过下列命令查找可以使用的PHP5模块。


yum search php


挑选你需要的,并通过下列命令安装他们:


yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy


现在重启Apache2:


systemctl restart httpd.service


现在,在你的浏览器中刷新http://192.168.0.100/info.php页面,并找到modules这里,你就会找到一些新的安装的模块,其中就有MySQL模块。



7 phpMyAdmin

phpMyAdmin是一款可以通过网页管理你MySQL数据库的软件。
phpMyAdmin可以通过下列命令安装:


yum install phpmyadmin


现在配置phpMyAdmin,我们修改Apache的配置让phpMyadmin可以不只是在本机访问(注销掉参数即可)


vi /etc/httpd/conf.d/phpMyAdmin.conf


# phpMyAdmin – Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL


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
#
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1


# These directories do not require access over HTTP – taken from the original
# phpMyAdmin upstream tarball
#


Order Deny,Allow
Deny from All
Allow from None
Order Deny,Allow
Deny from All
Allow from None
Order Deny,Allow
Deny from All
Allow from None


# This configuration prevents mod_security at phpMyAdmin directories from
# filtering SQL etc. This may break your mod_security implementation.
#
#
#
# SecRuleInheritance Off
#
#


重启Apache:


systemctl restart httpd.service


最后,你可以通过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/ (50)

    全站熱搜

    立你斯 發表在 痞客邦 留言(0) 人氣()