CentOS 系统 LAMP(Apache+MySQL+PHP)的安装
重启MySQL: /etc/init.d/mysqld restart ; 重启Apache: /etc/init.d/httpd start
Apache的配置文件路径:/etc/httpd/conf/httpd.conf ; PHP配置文件路径: /etc/php.ini
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
一般情况下,安装的都是最新的正式版,除非你有特殊需求,要安装指定的版本,本文暂不讨论。从最基础的开始,一点点完成一个可用的 Linux 主机。这里就开始介绍如何在 CentOS 6.0 上安装 LAMP 组件。经过如下语句安装,目前安装到的版本为:PHP:5.3.2
Apache:2.2.15
MySQL:5.1.52一、安装 MySQL
首先来进行 MySQL 的安装。打开超级终端,输入:
安装完毕,让 MySQL 能够随系统自动启动:
设置 MySQL 数据 root 账户的密码:(本人MySQL的密码为:123456)
当出现如下提示时候直接按回车:
Enter current password for root
出现如下再次回车:
Set root password? [Y/n]
出现如下提示输入你需要设置的密码,回车后在输入一次确认:
New password:
接下来还会有四个确认,分别是:
- Remove anonymous users? [Y/n]
- Disallow root login remotely? [Y/n]
- Remove test database and access to it? [Y/n]
- Reload privilege tables now? [Y/n]
直接回车即可。
二、安装 Apache 组件
由于 CentOS 已经封装了 Apache,直接运行安装:
同样配置系统让 Apache 随系统启动:
配置完毕,启动 Apache:
此时已经可以访问你的服务器,不出意外的话,能够看到 “Apache 2 Test Page powered by CentOS” 的测试页面。注意,如果其他机器访问这台服务无法显示这个页面,而直接在这台服务器上可以访问的话,一般情况下是 CentOS 自带的防火墙禁止了。你只需要进入防火墙,将 “WWW” 对应的 “80” 端口打开即可。
注意:在 CentOS 中 Apache 的默认根目录是 /var/www/html,配置文件 /etc/httpd/conf/httpd.conf。其他配置存储在 /etc/httpd/conf.d/ 目录。
三、安装 PHP
输入如下指令安装 PHP:
root@localhost ~]# yum install -y php
需要重新启动 Apache 服务:
[root@localhost ~]# /etc/init.d/httpd restart
四、测试 PHP 相关信息
这步实际上可以省略,但是为了测试是否安装成功,你可以新建一个 PHP 页面进行测试,使用 vim 编辑器新建:
[root@localhost ~]# vi /var/www/html/info.php
按 “i” 键进行编辑,输入:
<?php phpinfo(); ?>
编辑完毕,按 “ESC” 键退出编辑模式,接着输入:
:wq
然后回车,即保存并退出。
此时你可以访问你的站点地址,例如 “http://192.168.1.2/info.php”,查看是否能看到相关的 PHP 信息。
看到这样的图,就说明 PHP 安装成功了。
五、将 PHP 模块和 MySQL 模块关联起来
还需要将 PHP 和 MySQL 关联起来,才能正常工作。搜索模块:
[root@localhost ~]# yum search php
安装相关模块:
[root@localhost ~]# yum install -y php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
需要重启 Apache 模块才能生效:
[root@localhost ~]# /etc/init.d/httpd restart
再次刷新刚才建立的 “info.php” 页面,往下拉找到相关 MySQL 模块,看是否检测到相关信息。
如果看到如上图相关信息,则说明 MySQL 工作正常了。
六、总结
到这里就结束了,本文阐述了在 CentOS 6.0 系统下 LAMP 组件(Apache+MySQL+PHP) 的详细安装步骤,可以让更多新手熟悉服务器配置环境。
但是到这里,还只是将环境配置完毕,很多东西还有欠缺,而且还是一些重要的问题,例如目录的权限配置问题,或者是管理上的问题,像建立 FTP 等。这些内容随后会慢慢谈到。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
安装日志:
[root@localhost ~]# yum install mysql mysql-server
Loadedplugins:fastestmirror,refresh-packagekit
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.163.com
*extras:mirrors.163.com
*updates:mirrors.163.com
SettingupInstallProcess
ResolvingDependencies
-->Runningtransactioncheck
--->Packagemysql.i6860:5.1.61-1.el6_2.1settobeupdated
-->ProcessingDependency:mysql-libs=5.1.61-1.el6_2.1forpackage:mysql-5.1.61-1.el6_2.1.i686
--->Packagemysql-server.i6860:5.1.61-1.el6_2.1settobeupdated
-->ProcessingDependency:perl-DBD-MySQLforpackage:mysql-server-5.1.61-1.el6_2.1.i686
-->ProcessingDependency:perl(DBI)forpackage:mysql-server-5.1.61-1.el6_2.1.i686
-->ProcessingDependency:perl-DBIforpackage:mysql-server-5.1.61-1.el6_2.1.i686
-->Runningtransactioncheck
--->Packagemysql-libs.i6860:5.1.61-1.el6_2.1settobeupdated
--->Packageperl-DBD-MySQL.i6860:4.013-3.el6settobeupdated
--->Packageperl-DBI.i6860:1.609-4.el6settobeupdated
-->FinishedDependencyResolution
DependenciesResolved
================================================================================
PackageArchVersionRepositorySize
================================================================================
Installing:
mysqli6865.1.61-1.el6_2.1updates891k
mysql-serveri6865.1.61-1.el6_2.1updates8.3M
Installingfordependencies:
perl-DBD-MySQLi6864.013-3.el6base134k
perl-DBIi6861.609-4.el6base705k
Updatingfordependencies:
mysql-libsi6865.1.61-1.el6_2.1updates1.2M
TransactionSummary
================================================================================
Install4Package(s)
Upgrade1Package(s)
Totaldownloadsize:11M
Isthisok[y/N]:y
DownloadingPackages:
(1/5):mysql-5.1.61-1.el6_2.1.i686.rpm|891kB00:05
(2/5):mysql-libs-5.1.61-1.el6_2.1.i686.rpm|1.2MB00:08
(3/5):mysql-server-5.1.61-1.el6_2.1.i686.rpm|8.3MB00:55
(4/5):perl-DBD-MySQL-4.013-3.el6.i686.rpm|134kB00:00
(5/5):perl-DBI-1.609-4.el6.i686.rpm|705kB00:04
--------------------------------------------------------------------------------
Total146kB/s|11MB01:18
Runningrpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Warning:RPMDBalteredoutsideofyum.
Updating:mysql-libs-5.1.61-1.el6_2.1.i6861/6
Installing:perl-DBI-1.609-4.el6.i6862/6
Installing:perl-DBD-MySQL-4.013-3.el6.i6863/6
Installing:mysql-5.1.61-1.el6_2.1.i6864/6
Installing:mysql-server-5.1.61-1.el6_2.1.i6865/6
Cleanup:mysql-libs-5.1.47-4.el6.i6866/6
Installed:
mysql.i6860:5.1.61-1.el6_2.1mysql-server.i6860:5.1.61-1.el6_2.1
DependencyInstalled:
perl-DBD-MySQL.i6860:4.013-3.el6perl-DBI.i6860:1.609-4.el6
DependencyUpdated:
mysql-libs.i6860:5.1.61-1.el6_2.1
Complete!
[root@localhost ~]#
[root@localhost ~]# chkconfig --levels 235 mysqld on [root@localhost ~]# /etc/init.d/mysqld start
初始化MySQL数据库:InstallingMySQLsystemtables...
OK
Fillinghelptables...
OK
Tostartmysqldatboottimeyouhavetocopy
support-files/mysql.servertotherightplaceforyoursystem
PLEASEREMEMBERTOSETAPASSWORDFORTHEMySQLrootUSER!
Todoso,starttheserver,thenissuethefollowingcommands:
/usr/bin/mysqladmin-urootpassword'new-password'
/usr/bin/mysqladmin-uroot-hlocalhost.localdomainpassword'new-password'
Alternativelyyoucanrun:
/usr/bin/mysql_secure_installation
whichwillalsogiveyoutheoptionofremovingthetest
databasesandanonymoususercreatedbydefault.Thisis
stronglyrecommendedforproductionservers.
Seethemanualformoreinstructions.
YoucanstarttheMySQLdaemonwith:
cd/usr;/usr/bin/mysqld_safe&
YoucantesttheMySQLdaemonwithmysql-test-run.pl
cd/usr/mysql-test;perlmysql-test-run.pl
Pleasereportanyproblemswiththe/usr/bin/mysqlbugscript!
[确定]
正在启动mysqld:[确定]
[root@localhost ~]#
[root@localhost ~]# mysql_secure_installation
NOTE:RUNNINGALLPARTSOFTHISSCRIPTISRECOMMENDEDFORALLMySQL
SERVERSINPRODUCTIONUSE!PLEASEREADEACHSTEPCAREFULLY!
InordertologintoMySQLtosecureit,we'llneedthecurrent
passwordfortherootuser.Ifyou'vejustinstalledMySQL,and
youhaven'tsettherootpasswordyet,thepasswordwillbeblank,
soyoushouldjustpressenterhere.
Entercurrentpasswordforroot(enterfornone):
ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:YES)
Entercurrentpasswordforroot(enterfornone):
OK,successfullyusedpassword,movingon...
SettingtherootpasswordensuresthatnobodycanlogintotheMySQL
rootuserwithouttheproperauthorisation.
Setrootpassword?[Y/n]
Newpassword:
Re-enternewpassword:
Passwordupdatedsuccessfully!
Reloadingprivilegetables..
...Success!
Bydefault,aMySQLinstallationhasananonymoususer,allowinganyone
tologintoMySQLwithouthavingtohaveauseraccountcreatedfor
them.Thisisintendedonlyfortesting,andtomaketheinstallation
goabitsmoother.Youshouldremovethembeforemovingintoa
productionenvironment.
Removeanonymoususers?[Y/n]
...Success!
Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This
ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.
Disallowrootloginremotely?[Y/n]
...Success!
Bydefault,MySQLcomeswithadatabasenamed'test'thatanyonecan
access.Thisisalsointendedonlyfortesting,andshouldberemoved
beforemovingintoaproductionenvironment.
Removetestdatabaseandaccesstoit?[Y/n]
-Droppingtestdatabase...
...Success!
-Removingprivilegesontestdatabase...
...Success!
Reloadingtheprivilegetableswillensurethatallchangesmadesofar
willtakeeffectimmediately.
Reloadprivilegetablesnow?[Y/n]
...Success!
Cleaningup...
Alldone!Ifyou'vecompletedalloftheabovesteps,yourMySQL
installationshouldnowbesecure.
ThanksforusingMySQL!
[root@localhost ~]#
[root@localhost ~]# yum install -y httpd
Loadedplugins:fastestmirror,refresh-packagekit
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.163.com
*extras:mirrors.163.com
*updates:mirrors.163.com
SettingupInstallProcess
ResolvingDependencies
-->Runningtransactioncheck
--->Packagehttpd.i6860:2.2.15-15.el6.centos.1settobeupdated
-->ProcessingDependency:httpd-tools=2.2.15-15.el6.centos.1forpackage:httpd-2.2.15-15.el6.centos.1.i686
-->Runningtransactioncheck
--->Packagehttpd-tools.i6860:2.2.15-15.el6.centos.1settobeupdated
-->FinishedDependencyResolution
DependenciesResolved
=========================================================================================
PackageArchVersionRepositorySize
=========================================================================================
Updating:
httpdi6862.2.15-15.el6.centos.1updates819k
Updatingfordependencies:
httpd-toolsi6862.2.15-15.el6.centos.1updates70k
TransactionSummary
=========================================================================================
Install0Package(s)
Upgrade2Package(s)
Totaldownloadsize:890k
DownloadingPackages:
(1/2):httpd-2.2.15-15.el6.centos.1.i686.rpm|819kB00:05
(2/2):httpd-tools-2.2.15-15.el6.centos.1.i686.rpm|70kB00:00
-----------------------------------------------------------------------------------------
Total84kB/s|890kB00:10
Runningrpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Updating:httpd-tools-2.2.15-15.el6.centos.1.i6861/4
Updating:httpd-2.2.15-15.el6.centos.1.i6862/4
Cleanup:httpd-2.2.15-5.el6.centos.i6863/4
Cleanup:httpd-tools-2.2.15-5.el6.centos.i6864/4
Updated:
httpd.i6860:2.2.15-15.el6.centos.1
DependencyUpdated:
httpd-tools.i6860:2.2.15-15.el6.centos.1
Complete!
[root@localhost~]#
[root@localhost~]#/etc/init.d/httpdstart
正在启动httpd:[确定]
[root@localhost ~]
[root@localhost ~]# yum install php
Loadedplugins:fastestmirror,refresh-packagekit
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.163.com
*extras:mirrors.163.com
*updates:mirrors.163.com
SettingupInstallProcess
ResolvingDependencies
-->Runningtransactioncheck
--->Packagephp.i6860:5.3.3-3.el6_2.6settobeupdated
-->ProcessingDependency:php-cli=5.3.3-3.el6_2.6forpackage:php-5.3.3-3.el6_2.6.i686
-->ProcessingDependency:php-common=5.3.3-3.el6_2.6forpackage:php-5.3.3-3.el6_2.6.i686
-->Runningtransactioncheck
--->Packagephp-cli.i6860:5.3.3-3.el6_2.6settobeupdated
--->Packagephp-common.i6860:5.3.3-3.el6_2.6settobeupdated
-->FinishedDependencyResolution
DependenciesResolved
=========================================================================================
PackageArchVersionRepositorySize
=========================================================================================
Installing:
phpi6865.3.3-3.el6_2.6updates1.1M
Installingfordependencies:
php-clii6865.3.3-3.el6_2.6updates2.2M
php-commoni6865.3.3-3.el6_2.6updates523k
TransactionSummary
=========================================================================================
Install3Package(s)
Upgrade0Package(s)
Totaldownloadsize:3.8M
Installedsize:12M
Isthisok[y/N]:y
DownloadingPackages:
(1/3):php-5.3.3-3.el6_2.6.i686.rpm|1.1MB00:06
(2/3):php-cli-5.3.3-3.el6_2.6.i686.rpm|2.2MB00:13
(3/3):php-common-5.3.3-3.el6_2.6.i686.rpm|523kB00:03
-----------------------------------------------------------------------------------------
Total73kB/s|3.8MB00:53
Runningrpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Installing:php-common-5.3.3-3.el6_2.6.i6861/3
Installing:php-cli-5.3.3-3.el6_2.6.i6862/3
Installing:php-5.3.3-3.el6_2.6.i6863/3
Installed:
php.i6860:5.3.3-3.el6_2.6
DependencyInstalled:
php-cli.i6860:5.3.3-3.el6_2.6php-common.i6860:5.3.3-3.el6_2.6
Complete!
[root@localhost ~]# /etc/init.d/httpd restart
停止httpd:[确定]
正在启动httpd:[确定]
[root@localhost ~]#
[root@localhost ~]# yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpcLoaded plugins: fastestmirror, refresh-packagekit
Loadingmirrorspeedsfromcachedhostfile
*base:mirrors.sin3.sg.voxel.net
*extras:mirrors.sin3.sg.voxel.net
*updates:mirrors.sin3.sg.voxel.net
SettingupInstallProcess
ResolvingDependencies
-->Runningtransactioncheck
--->Packagephp-gd.i6860:5.3.3-3.el6_2.6settobeupdated
-->ProcessingDependency:libXpm.so.4forpackage:php-gd-5.3.3-3.el6_2.6.i686
--->Packagephp-imap.i6860:5.3.3-3.el6_2.6settobeupdated
-->ProcessingDependency:libc-client.so.2007forpackage:php-imap-5.3.3-3.el6_2.6.i686
--->Packagephp-ldap.i6860:5.3.3-3.el6_2.6settobeupdated
--->Packagephp-mysql.i6860:5.3.3-3.el6_2.6settobeupdated
-->ProcessingDependency:php-pdoforpackage:php-mysql-5.3.3-3.el6_2.6.i686
--->Packagephp-odbc.i6860:5.3.3-3.el6_2.6settobeupdated
-->ProcessingDependency:libodbc.so.2forpackage:php-odbc-5.3.3-3.el6_2.6.i686
--->Packagephp-pear.noarch1:1.9.4-4.el6settobeupdated
--->Packagephp-xml.i6860:5.3.3-3.el6_2.6settobeupdated
--->Packagephp-xmlrpc.i6860:5.3.3-3.el6_2.6settobeupdated
-->Runningtransactioncheck
--->PackagelibXpm.i6860:3.5.8-2.el6settobeupdated
--->Packagelibc-client.i6860:2007e-11.el6settobeupdated
--->Packagephp-pdo.i6860:5.3.3-3.el6_2.6settobeupdated
--->PackageunixODBC.i6860:2.2.14-11.el6settobeupdated
-->FinishedDependencyResolution
DependenciesResolved
================================================================================
PackageArchVersionRepositorySize
================================================================================
Installing:
php-gdi6865.3.3-3.el6_2.6updates102k
php-imapi6865.3.3-3.el6_2.6updates47k
php-ldapi6865.3.3-3.el6_2.6updates35k
php-mysqli6865.3.3-3.el6_2.6updates76k
php-odbci6865.3.3-3.el6_2.6updates48k
php-pearnoarch1:1.9.4-4.el6base393k
php-xmli6865.3.3-3.el6_2.6updates98k
php-xmlrpci6865.3.3-3.el6_2.6updates51k
Installingfordependencies:
libXpmi6863.5.8-2.el6base58k
libc-clienti6862007e-11.el6base524k
php-pdoi6865.3.3-3.el6_2.6updates72k
unixODBCi6862.2.14-11.el6base382k
TransactionSummary
================================================================================
Install12Package(s)
Upgrade0Package(s)
Totaldownloadsize:1.8M
Installedsize:6.0M
Isthisok[y/N]:y
DownloadingPackages:
(1/12):libXpm-3.5.8-2.el6.i686.rpm|58kB00:00
(2/12):libc-client-2007e-11.el6.i686.rpm|524kB00:04
(3/12):php-gd-5.3.3-3.el6_2.6.i686.rpm|102kB00:00
(4/12):php-imap-5.3.3-3.el6_2.6.i686.rpm|47kB00:00
(5/12):php-ldap-5.3.3-3.el6_2.6.i686.rpm|35kB00:00
(6/12):php-mysql-5.3.3-3.el6_2.6.i686.rpm|76kB00:00
(7/12):php-odbc-5.3.3-3.el6_2.6.i686.rpm|48kB00:00
(8/12):php-pdo-5.3.3-3.el6_2.6.i686.rpm|72kB00:00
(9/12):php-pear-1.9.4-4.el6.noarch.rpm|393kB00:03
(10/12):php-xml-5.3.3-3.el6_2.6.i686.rpm|98kB00:00
(11/12):php-xmlrpc-5.3.3-3.el6_2.6.i686.rpm|51kB00:00
(12/12):unixODBC-2.2.14-11.el6.i686.rpm|382kB00:03
--------------------------------------------------------------------------------
Total117kB/s|1.8MB00:16
Runningrpm_check_debug
RunningTransactionTest
TransactionTestSucceeded
RunningTransaction
Installing:1:php-pear-1.9.4-4.el6.noarch1/12
Installing:php-pdo-5.3.3-3.el6_2.6.i6862/12
Installing:unixODBC-2.2.14-11.el6.i6863/12
Installing:libXpm-3.5.8-2.el6.i6864/12
Installing:libc-client-2007e-11.el6.i6865/12
Installing:php-imap-5.3.3-3.el6_2.6.i6866/12
Installing:php-gd-5.3.3-3.el6_2.6.i6867/12
Installing:php-odbc-5.3.3-3.el6_2.6.i6868/12
Installing:php-mysql-5.3.3-3.el6_2.6.i6869/12
Installing:php-ldap-5.3.3-3.el6_2.6.i68610/12
Installing:php-xml-5.3.3-3.el6_2.6.i68611/12
Installing:php-xmlrpc-5.3.3-3.el6_2.6.i68612/12
Installed:
php-gd.i6860:5.3.3-3.el6_2.6php-imap.i6860:5.3.3-3.el6_2.6
php-ldap.i6860:5.3.3-3.el6_2.6php-mysql.i6860:5.3.3-3.el6_2.6
php-odbc.i6860:5.3.3-3.el6_2.6php-pear.noarch1:1.9.4-4.el6
php-xml.i6860:5.3.3-3.el6_2.6php-xmlrpc.i6860:5.3.3-3.el6_2.6
DependencyInstalled:
libXpm.i6860:3.5.8-2.el6libc-client.i6860:2007e-11.el6
php-pdo.i6860:5.3.3-3.el6_2.6unixODBC.i6860:2.2.14-11.el6
Complete!
[root@localhost ~]# /etc/init.d/httpd restart
停止httpd:[确定]
正在启动 httpd: [确定]