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 能够随系统自动启动:
[root@localhost ~]# /etc/init.d/mysqld start
设置 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:
需要重新启动 Apache 服务:
四、测试 PHP 相关信息
这步实际上可以省略,但是为了测试是否安装成功,你可以新建一个 PHP 页面进行测试,使用 vim 编辑器新建:
按 “i” 键进行编辑,输入:
phpinfo();
?>
编辑完毕,按 “ESC” 键退出编辑模式,接着输入:
然后回车,即保存并退出。
此时你可以访问你的站点地址,例如 “http://192.168.1.2/info.php”,查看是否能看到相关的 PHP 信息。
看到这样的图,就说明 PHP 安装成功了。
五、将 PHP 模块和 MySQL 模块关联起来
还需要将 PHP 和 MySQL 关联起来,才能正常工作。搜索模块:
安装相关模块:
需要重启 Apache 模块才能生效:
再次刷新刚才建立的 “info.php” 页面,往下拉找到相关 MySQL 模块,看是否检测到相关信息。
如果看到如上图相关信息,则说明 MySQL 工作正常了。
六、总结
到这里就结束了,本文阐述了在 CentOS 6.0 系统下 LAMP 组件(Apache+MySQL+PHP) 的详细安装步骤,可以让更多新手熟悉服务器配置环境。
但是到这里,还只是将环境配置完毕,很多东西还有欠缺,而且还是一些重要的问题,例如目录的权限配置问题,或者是管理上的问题,像建立 FTP 等。这些内容随后会慢慢谈到。
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
安装日志:
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.i686 0:5.1.61-1.el6_2.1 set to be updated
--> Processing Dependency: mysql-libs = 5.1.61-1.el6_2.1 for package: mysql-5.1.61-1.el6_2.1.i686
---> Package mysql-server.i686 0:5.1.61-1.el6_2.1 set to be updated
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.61-1.el6_2.1.i686
--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.61-1.el6_2.1.i686
--> Processing Dependency: perl-DBI for package: mysql-server-5.1.61-1.el6_2.1.i686
--> Running transaction check
---> Package mysql-libs.i686 0:5.1.61-1.el6_2.1 set to be updated
---> Package perl-DBD-MySQL.i686 0:4.013-3.el6 set to be updated
---> Package perl-DBI.i686 0:1.609-4.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mysql i686 5.1.61-1.el6_2.1 updates 891 k
mysql-server i686 5.1.61-1.el6_2.1 updates 8.3 M
Installing for dependencies:
perl-DBD-MySQL i686 4.013-3.el6 base 134 k
perl-DBI i686 1.609-4.el6 base 705 k
Updating for dependencies:
mysql-libs i686 5.1.61-1.el6_2.1 updates 1.2 M
Transaction Summary
================================================================================
Install 4 Package(s)
Upgrade 1 Package(s)
Total download size: 11 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): mysql-5.1.61-1.el6_2.1.i686.rpm | 891 kB 00:05
(2/5): mysql-libs-5.1.61-1.el6_2.1.i686.rpm | 1.2 MB 00:08
(3/5): mysql-server-5.1.61-1.el6_2.1.i686.rpm | 8.3 MB 00:55
(4/5): perl-DBD-MySQL-4.013-3.el6.i686.rpm | 134 kB 00:00
(5/5): perl-DBI-1.609-4.el6.i686.rpm | 705 kB 00:04
--------------------------------------------------------------------------------
Total 146 kB/s | 11 MB 01:18
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Updating : mysql-libs-5.1.61-1.el6_2.1.i686 1/6
Installing : perl-DBI-1.609-4.el6.i686 2/6
Installing : perl-DBD-MySQL-4.013-3.el6.i686 3/6
Installing : mysql-5.1.61-1.el6_2.1.i686 4/6
Installing : mysql-server-5.1.61-1.el6_2.1.i686 5/6
Cleanup : mysql-libs-5.1.47-4.el6.i686 6/6
Installed:
mysql.i686 0:5.1.61-1.el6_2.1 mysql-server.i686 0:5.1.61-1.el6_2.1
Dependency Installed:
perl-DBD-MySQL.i686 0:4.013-3.el6 perl-DBI.i686 0:1.609-4.el6
Dependency Updated:
mysql-libs.i686 0:5.1.61-1.el6_2.1
Complete!
[root@localhost ~]#
[root@localhost ~]# /etc/init.d/mysqld start
初始化 MySQL 数据库: Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[确定]
正在启动 mysqld: [确定]
[root@localhost ~]#
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):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
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@localhost ~]#
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.i686 0:2.2.15-15.el6.centos.1 set to be updated
--> Processing Dependency: httpd-tools = 2.2.15-15.el6.centos.1 for package: httpd-2.2.15-15.el6.centos.1.i686
--> Running transaction check
---> Package httpd-tools.i686 0:2.2.15-15.el6.centos.1 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================
Package Arch Version Repository Size
=========================================================================================
Updating:
httpd i686 2.2.15-15.el6.centos.1 updates 819 k
Updating for dependencies:
httpd-tools i686 2.2.15-15.el6.centos.1 updates 70 k
Transaction Summary
=========================================================================================
Install 0 Package(s)
Upgrade 2 Package(s)
Total download size: 890 k
Downloading Packages:
(1/2): httpd-2.2.15-15.el6.centos.1.i686.rpm | 819 kB 00:05
(2/2): httpd-tools-2.2.15-15.el6.centos.1.i686.rpm | 70 kB 00:00
-----------------------------------------------------------------------------------------
Total 84 kB/s | 890 kB 00:10
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : httpd-tools-2.2.15-15.el6.centos.1.i686 1/4
Updating : httpd-2.2.15-15.el6.centos.1.i686 2/4
Cleanup : httpd-2.2.15-5.el6.centos.i686 3/4
Cleanup : httpd-tools-2.2.15-5.el6.centos.i686 4/4
Updated:
httpd.i686 0:2.2.15-15.el6.centos.1
Dependency Updated:
httpd-tools.i686 0:2.2.15-15.el6.centos.1
Complete!
[root@localhost ~]#
[root@localhost ~]# /etc/init.d/httpd start
正在启动 httpd: [确定]
[root@localhost ~]
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php.i686 0:5.3.3-3.el6_2.6 set to be updated
--> Processing Dependency: php-cli = 5.3.3-3.el6_2.6 for package: php-5.3.3-3.el6_2.6.i686
--> Processing Dependency: php-common = 5.3.3-3.el6_2.6 for package: php-5.3.3-3.el6_2.6.i686
--> Running transaction check
---> Package php-cli.i686 0:5.3.3-3.el6_2.6 set to be updated
---> Package php-common.i686 0:5.3.3-3.el6_2.6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=========================================================================================
Package Arch Version Repository Size
=========================================================================================
Installing:
php i686 5.3.3-3.el6_2.6 updates 1.1 M
Installing for dependencies:
php-cli i686 5.3.3-3.el6_2.6 updates 2.2 M
php-common i686 5.3.3-3.el6_2.6 updates 523 k
Transaction Summary
=========================================================================================
Install 3 Package(s)
Upgrade 0 Package(s)
Total download size: 3.8 M
Installed size: 12 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): php-5.3.3-3.el6_2.6.i686.rpm | 1.1 MB 00:06
(2/3): php-cli-5.3.3-3.el6_2.6.i686.rpm | 2.2 MB 00:13
(3/3): php-common-5.3.3-3.el6_2.6.i686.rpm | 523 kB 00:03
-----------------------------------------------------------------------------------------
Total 73 kB/s | 3.8 MB 00:53
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : php-common-5.3.3-3.el6_2.6.i686 1/3
Installing : php-cli-5.3.3-3.el6_2.6.i686 2/3
Installing : php-5.3.3-3.el6_2.6.i686 3/3
Installed:
php.i686 0:5.3.3-3.el6_2.6
Dependency Installed:
php-cli.i686 0:5.3.3-3.el6_2.6 php-common.i686 0:5.3.3-3.el6_2.6
Complete!
[root@localhost ~]# /etc/init.d/httpd restart
停止 httpd: [确定]
正在启动 httpd: [确定]
[root@localhost ~]#
Loaded plugins: fastestmirror, refresh-packagekit
Loading mirror speeds from cached hostfile
* base: mirrors.sin3.sg.voxel.net
* extras: mirrors.sin3.sg.voxel.net
* updates: mirrors.sin3.sg.voxel.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package php-gd.i686 0:5.3.3-3.el6_2.6 set to be updated
--> Processing Dependency: libXpm.so.4 for package: php-gd-5.3.3-3.el6_2.6.i686
---> Package php-imap.i686 0:5.3.3-3.el6_2.6 set to be updated
--> Processing Dependency: libc-client.so.2007 for package: php-imap-5.3.3-3.el6_2.6.i686
---> Package php-ldap.i686 0:5.3.3-3.el6_2.6 set to be updated
---> Package php-mysql.i686 0:5.3.3-3.el6_2.6 set to be updated
--> Processing Dependency: php-pdo for package: php-mysql-5.3.3-3.el6_2.6.i686
---> Package php-odbc.i686 0:5.3.3-3.el6_2.6 set to be updated
--> Processing Dependency: libodbc.so.2 for package: php-odbc-5.3.3-3.el6_2.6.i686
---> Package php-pear.noarch 1:1.9.4-4.el6 set to be updated
---> Package php-xml.i686 0:5.3.3-3.el6_2.6 set to be updated
---> Package php-xmlrpc.i686 0:5.3.3-3.el6_2.6 set to be updated
--> Running transaction check
---> Package libXpm.i686 0:3.5.8-2.el6 set to be updated
---> Package libc-client.i686 0:2007e-11.el6 set to be updated
---> Package php-pdo.i686 0:5.3.3-3.el6_2.6 set to be updated
---> Package unixODBC.i686 0:2.2.14-11.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
php-gd i686 5.3.3-3.el6_2.6 updates 102 k
php-imap i686 5.3.3-3.el6_2.6 updates 47 k
php-ldap i686 5.3.3-3.el6_2.6 updates 35 k
php-mysql i686 5.3.3-3.el6_2.6 updates 76 k
php-odbc i686 5.3.3-3.el6_2.6 updates 48 k
php-pear noarch 1:1.9.4-4.el6 base 393 k
php-xml i686 5.3.3-3.el6_2.6 updates 98 k
php-xmlrpc i686 5.3.3-3.el6_2.6 updates 51 k
Installing for dependencies:
libXpm i686 3.5.8-2.el6 base 58 k
libc-client i686 2007e-11.el6 base 524 k
php-pdo i686 5.3.3-3.el6_2.6 updates 72 k
unixODBC i686 2.2.14-11.el6 base 382 k
Transaction Summary
================================================================================
Install 12 Package(s)
Upgrade 0 Package(s)
Total download size: 1.8 M
Installed size: 6.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/12): libXpm-3.5.8-2.el6.i686.rpm | 58 kB 00:00
(2/12): libc-client-2007e-11.el6.i686.rpm | 524 kB 00:04
(3/12): php-gd-5.3.3-3.el6_2.6.i686.rpm | 102 kB 00:00
(4/12): php-imap-5.3.3-3.el6_2.6.i686.rpm | 47 kB 00:00
(5/12): php-ldap-5.3.3-3.el6_2.6.i686.rpm | 35 kB 00:00
(6/12): php-mysql-5.3.3-3.el6_2.6.i686.rpm | 76 kB 00:00
(7/12): php-odbc-5.3.3-3.el6_2.6.i686.rpm | 48 kB 00:00
(8/12): php-pdo-5.3.3-3.el6_2.6.i686.rpm | 72 kB 00:00
(9/12): php-pear-1.9.4-4.el6.noarch.rpm | 393 kB 00:03
(10/12): php-xml-5.3.3-3.el6_2.6.i686.rpm | 98 kB 00:00
(11/12): php-xmlrpc-5.3.3-3.el6_2.6.i686.rpm | 51 kB 00:00
(12/12): unixODBC-2.2.14-11.el6.i686.rpm | 382 kB 00:03
--------------------------------------------------------------------------------
Total 117 kB/s | 1.8 MB 00:16
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : 1:php-pear-1.9.4-4.el6.noarch 1/12
Installing : php-pdo-5.3.3-3.el6_2.6.i686 2/12
Installing : unixODBC-2.2.14-11.el6.i686 3/12
Installing : libXpm-3.5.8-2.el6.i686 4/12
Installing : libc-client-2007e-11.el6.i686 5/12
Installing : php-imap-5.3.3-3.el6_2.6.i686 6/12
Installing : php-gd-5.3.3-3.el6_2.6.i686 7/12
Installing : php-odbc-5.3.3-3.el6_2.6.i686 8/12
Installing : php-mysql-5.3.3-3.el6_2.6.i686 9/12
Installing : php-ldap-5.3.3-3.el6_2.6.i686 10/12
Installing : php-xml-5.3.3-3.el6_2.6.i686 11/12
Installing : php-xmlrpc-5.3.3-3.el6_2.6.i686 12/12
Installed:
php-gd.i686 0:5.3.3-3.el6_2.6 php-imap.i686 0:5.3.3-3.el6_2.6
php-ldap.i686 0:5.3.3-3.el6_2.6 php-mysql.i686 0:5.3.3-3.el6_2.6
php-odbc.i686 0:5.3.3-3.el6_2.6 php-pear.noarch 1:1.9.4-4.el6
php-xml.i686 0:5.3.3-3.el6_2.6 php-xmlrpc.i686 0:5.3.3-3.el6_2.6
Dependency Installed:
libXpm.i686 0:3.5.8-2.el6 libc-client.i686 0:2007e-11.el6
php-pdo.i686 0:5.3.3-3.el6_2.6 unixODBC.i686 0:2.2.14-11.el6
Complete!
[root@localhost ~]# /etc/init.d/httpd restart
停止 httpd: [确定]
正在启动 httpd: [确定]