针狗技术网

针狗技术网、电脑技术资源网

LAMP是Linux、Apache、MySQL、PHP的缩写。本教程展示了如何在支持PHP5(mod_php)和MySQL的CentOS 6.4服务器上安装Apache2 Web服务器。

我不能保证这对你有用!

1初步说明

在本教程中,我使用IP地址为192.168.0.100的主机名server1.example.com。这些设置可能因您而异,因此您必须在适当的情况下进行替换。

2安装MySQL 5.x

要安装MySQL,我们可以这样做:

yum -y install mysql mysql-server

然后,我们为MySQL创建系统启动链接(以便MySQL在系统启动时自动启动)并启动MySQL服务器:

chkconfig –levels 235 mysqld on
/etc/init.d/mysqld start

设置MySQL根帐户的密码:

mysql_secure_installation

[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] <-- ENTER New password: <-- yourrootsqlpassword Re-enter new password: <-- yourrootsqlpassword 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] <-- ENTER ... 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] <-- ENTER ... 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] <-- ENTER - 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] <-- ENTER ... 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!

3安装Apache2

Apache2作为CentOS软件包提供,因此我们可以这样安装它:

yum -y install httpd

现在,将您的系统配置为在启动时启动Apache。。。

chkconfig –levels 235 httpd on

…然后启动Apache:

/etc/init.d/httpd start

现在将浏览器定向到http://192.168.0.100,您应该看到Apache2占位符页面:

在CentOS上,Apache的默认文档根是/var/www/html,配置文件是/etc/httpd/conf/httpd.conf。其他配置存储在/etc/httpd/conf.d/目录中。

4安装PHP5

我们可以按如下方式安装PHP5和Apache PHP5模块:

yum -y install php

之后我们必须重新启动Apache:

/etc/init.d/httpd restart

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

默认网站的文档根是/var/www/html。我们现在将在该目录中创建一个小的PHP文件(info.PHP),并在浏览器中调用它。该文件将显示有关我们的PHP安装的许多有用的详细信息,例如安装的PHP版本。

vi /var/www/html/info.php

现在我们在浏览器中调用该文件(例如。http://192.168.0.100/info.php):

正如您所看到的,PHP5正在工作,它正在通过Apache2.0Handler工作,如Serverneneneba API行所示。如果您进一步向下滚动,您将看到PHP5中已启用的所有模块。MySQL没有列出,这意味着我们在PHP5中还没有MySQL支持。

6在PHP5中获得MySQL支持

要在PHP中获得MySQL支持,我们可以安装PHP-MySQL包。安装一些其他PHP5模块是个好主意,因为你的应用程序可能需要它们。您可以这样搜索可用的PHP5模块:

yum search php

选择你需要的,然后这样安装:

yum -y install php-mysql

下一步,我将安装一些CMS系统(如Wordpress、Joomla和Drupal)所需的常见PHP模块:

yum -y install php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel

APC是一个免费开放的PHP操作码缓存器,用于缓存和优化PHP中间代码。它类似于其他PHP操作码缓存,如eAccelerator和Xcache。强烈建议安装其中一个以加快PHP页面的速度。

APC的安装方式如下:

yum -y install php-pecl-apc

现在重新启动Apache2:

/etc/init.d/httpd restart

现在重新加载http://192.168.0.100/info.php在浏览器中,再次向下滚动到模块部分。现在,您应该可以在那里找到许多新模块,包括APC模块:

7 phpMyAdmin

phpMyAdmin是一个web界面,您可以通过它管理MySQL数据库。

首先,我们在CentOS系统上启用RPMforge存储库,因为phpMyAdmin在CentOS 6.5官方存储库中不可用:

导入RPMforge GPG密钥:

rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

在x86_64系统上:

yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

在i386系统上:

yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm

phpMyAdmin现在可以按如下方式安装:

yum -y install phpmyadmin

现在我们配置phpMyAdmin。我们更改了Apache配置,以便phpMyAdmin不仅允许从本地主机进行连接(通过注释节):

vi /etc/httpd/conf.d/phpmyadmin.conf

#
# Web application to manage MySQL
#

#
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
#

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /mysqladmin /usr/share/phpmyadmin

接下来,我们将phpMyAdmin中的身份验证从cookie更改为http:

vi /usr/share/phpmyadmin/config.inc.php

[…]
/* Authentication type */
$cfg[‘Servers’][$i][‘auth_type’] = ‘http’;
[…]

重新启动Apache:

/etc/init.d/httpd restart

之后,您可以在以下网址访问phpMyAdminhttp://192.168.0.100/phpmyadmin/:

8链接

发表评论