CentOS 6.5系统安装配置LAMP(Apache+PHP5+MySQL)
服务器环境
一、安装Apache
[root@cet6 ~]# yum install -y httpd
启动服务:
[root@cet6 ~]# service httpd start
正在启动httpd:[确定]
[root@cet6 ~]#
设置开机启动:
[root@cet6 ~]# chkconfig | grep httpd
httpd 0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
[root@cet6 ~]# chkconfig httpd on
[root@cet6 ~]# chkconfig | grep httpd
httpd 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[root@cet6 ~]#
查看80端口:
[root@cet6 ~]# netstat -lntp | grep httpd
tcp 0 0 :::80 :::* LISTEN 3294/httpd
[root@cet6 ~]#
查看httpd进程:
[root@cet6 ~]# ps -aux | grep httpd
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 3294 0.0 0.1 186228 3932 ? Ss 15:57 0:00 /usr/sbin/httpd apache 3297 0.0 0.1 186364 3092 ? S 15:57 0:00 /usr/sbin/httpd apache 3298 0.0 0.1 186364 3184 ? S 15:57 0:00 /usr/sbin/httpd apache 3299 0.0 0.1 186364 3092 ? S 15:57 0:00 /usr/sbin/httpd apache 3300 0.0 0.1 186364 3116 ? S 15:57 0:00 /usr/sbin/httpd apache 3301 0.0 0.1 186228 2456 ? S 15:57 0:00 /usr/sbin/httpd apache 3302 0.0 0.1 186228 2456 ? S 15:57 0:00 /usr/sbin/httpd apache 3303 0.0 0.1 186228 2456 ? S 15:57 0:00 /usr/sbin/httpd apache 3304 0.0 0.1 186228 2456 ? S 15:57 0:00 /usr/sbin/httpd root 3445 0.0 0.0 103240 876 pts/1 S+ 16:03 0:00 grep httpd
[root@cet6 ~]#
浏览器访问:
192.168.1.233/
二、安装MySQL
[root@cet6 ~]# yum list | grep mysql
[root@cet6 ~]# yum install -y mysql mysql-server
安装完成后,第一次启动mysql服务进行初始化:
[root@cet6 ~]# service mysqld start
初始化MySQL 数据库:Installing MySQL
OK
Filling
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 cet6 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@cet6 ~]#
查看mysql端口:
[root@cet6 ~]# netstat -lntp | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 3673/mysqld [root@cet6 ~]#
连接mysql测试:
[root@cet6 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
说明:
mysql客户端选项:
-u 用户名:指定以哪个用户进行连接。
-p :直接回车输入密码。
-h mysql服务器:指定连接服务器ip。
-u不指定默认是以root登陆。
-
p不指定默认为空密码。
-h不指定默认为localhost。
设置开机启动:
[root@cet6 ~]# chkconfig | grep mysqld
mysqld 0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
[root@cet6 ~]# chkconfig mysqld on
[root@cet6 ~]# chkconfig | grep mysqld
mysqld 0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
[root@cet6 ~]#
复制mysql主配置文件到/etc下:
[root@cet6 mysql]# pwd
/
usr/share/mysql
[root@cet6 mysql]# cp my-mediumf /etc/myf
cp:是否覆盖"/etc/myf"?y
[root@cet6 mysql]#
为mysql的root账户设置密码:
可以使用:mysqladmin -u root password "123456设置密码。
也可以使用mysql_secure_installation命令:
安装完mysql-server 会提示可以运行mysql_secure_installation。运行mysql_secure_installation会执行几个设置:
a)为root用户设置密码
b)删除匿名账号
c)取消root用户远程登录
d)删除test库和对test库的访问权限
e)刷新授权表使修改生效
通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation
[root@cet6 ~]# 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,
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y <–是否设置root用户密码,输入y并回车或直接回车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] y <–是否删除匿名用户,生产环境建议删除... 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] n <–是否禁止root远程登录
... skipping.
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] n <–是否删除test数据库
.
.. skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y <–是否重新加载权限表
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@cet6 ~]#
三、安装PHP5
[root@cet6 ~]# yum install -y php
安装PHP组件,使PHP5 支持MySQL:
yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt
或者都装上:
[root@cet6 ~]# yum list | grep php
[root@cet6 ~]# yum install -y php*
重新启动httpd服务和mysql服务:
[root@cet6 ~]# service httpd restart
停止httpd:[确定]
正在启动httpd:[确定]
[root@cet6 ~]# service mysqld restart
停止mysqld:[确定]
正在启动mysqld:[确定]
[root@cet6 ~]#
提供php脚本测试:
mysql下载后的初次使用
[root@cet6 html]# pwd
/var/www/html
[root@cet6 html]# vim index.php
<?php
phpinfo();
>
"index.php" [新] 3L, 20C 已写入
[root@cet6 html]#
可在httpd配置文件中DirectoryIndex项增加index.php。
提供php脚本连接mysql数据库:
查看是否能够连接mysql:
[root@cet6 html]# pwd
/var/www/html
[root@cet6 html]# vim index.php
<?php
$conn=mysql_connect('localhost','root','123456');
if ($conn)
echo "OK...";
else
echo "NO...";
>
[root@cet6 html]#
连接mysql成功网页会显示OK!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。