在CentOS 6.5(LAMP)上安装Apache2,PHP5和MySQL支持
LAMP是L inux, A pache, M ySQL, P HP的缩写。 本教程将介绍如何在具有PHP5支持(mod_php)和MySQL支持的CentOS 6.4服务器上安装Apache2 Web服务器。
我不会保证这将为您工作!
1初步说明
在本教程中,我使用IP地址为192.168.0.100
的hostname server1.example.com
。 这些设置可能会有所不同,因此您必须在适当的情况下更换它们。
2安装MySQL 5
要安装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占位符页面:
Apache的默认文档根目录是CentOS上的/ 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
<?php phpinfo(); ?> |
现在我们在浏览器中调用该文件(例如http://192.168.0.100/info.php
):
如您所见,PHP5正在工作,它正在通过Apache 2.0处理程序
,如Server API
行所示。 如果您进一步向下滚动,您将看到在PHP5中已启用的所有模块。 MySQL没有列出,这意味着我们还没有在PHP5中支持MySQL。
6在PHP5中获取MySQL支持
要在PHP中获得MySQL支持,我们可以安装php-mysql
包。 安装一些其他PHP5模块是一个好主意,您可能需要它们用于应用程序。 您可以搜索可用的PHP5模块,如下所示:
yum search php
选择您需要的并安装它们:
yum -y install php-mysql
在下一步中,我将安装CMS系统所需的一些常见PHP模块,例如Wordpress,Joomla和Drupal:
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操作码cacher,用于缓存和优化PHP中间代码。 它类似于其他PHP操作码cacher,如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允许连接不仅来自localhost(通过注释<Directory“/ usr / share / phpmyadmin”>
节):
vi /etc/httpd/conf.d/phpmyadmin.conf
# # Web application to manage MySQL # #<Directory "/usr/share/phpmyadmin"> # Order Deny,Allow # Deny from all # Allow from 127.0.0.1 #</Directory> 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
之后,您可以访问http://192.168.0.100/phpmyadmin/下的phpMyAdmin
:
8链接
- Apache: http : //httpd.apache.org/
- PHP: http : //www.php.net/
- MySQL: http : //www.mysql.com/
- CentOS: http : //www.centos.org/
- phpMyAdmin: http : //www.phpmyadmin.net/