设为首页 收藏本站
查看: 681|回复: 0

快速在CentOS下搭建LAMP(Apache、MySQL、PHP)环境

[复制链接]

尚未签到

发表于 2015-8-19 14:03:39 | 显示全部楼层 |阅读模式
  LAMP(Linux、Apache、MySQL、PHP)是一套用于提供php架构网站服务的完美组合的简称,LAMP组合有着极高的性能,完善的支持体系,灵活的配置方法,但是Lamp架构其本身也越来越臃肿,在Lamp安装完成后最好进行针对硬件的优化,以获得更好的性能。
  
  LAMP可以在很多平台(Linux、Windows、Unix、MacOS X)中搭建,本文以CentOS系统安装LAMP套件进行举例。
  搭建需要有一台安装有CentOS的服务器,并且最好是纯净安装:即仅仅安装最少的系统组件。
  
首先安装Apache2
  一条命令即可:



1yum install httpd
  回车后,yum会提示当前已经安装的httpd版本,并自动更新;如果没有安装,则会自动安装。注意在yum安装过程中输入“Y”以确认安装。
  Apache安装完成后,手动启动Apache2:



1/etc/init.d/httpd start
  这时,直接在浏览器中输入服务器的IP地址,即可看到Apache2的默认页面。此时的Apache仅仅能提供HTTP服务,不能执行php、也不能连接MySQL数据库。
  
随后安装MySQL
  由于CentOS中已经包含了MySQL,因此也仅需要yum即可:



1yum install mysql mysql-server
  完成后,使用如下命令启动MySQL服务:



1  /etc/init.d/mysqld start
  [iyunv@srv20 yum.repos.d]# 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] 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  ... 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] y  - 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] y  ... 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!
  mysql> create database magentodb;
  mysql>GRANT ALL PRIVILEGES ON magento.* TO magento@'localhost' identified by '123456';
  
下面继续安装php5
  使用如下命令安装php5:



1yum install php53
  安装完php5后,必须要重新启动Apache以使php生效:



1/etc/init.d/httpd restart
  这时,Apache已经可以解析执行php脚本了。由于Apache的默认网站根目录位于:/var/www/html/,因此在此目录建立一个info.php用来测试Apache+PHP的正确安装与否:



1echo "<?php phpinfo(); ?>" > /var/www/html/info.php
  然后在浏览器中访问IP/info.php,出现了PHPINFO的输出信息:

  表示PHP与Apache已经正确安装。
  接下来安装MySQL数据库与其它模块(如GD图形库、mbstring库等):



1  yum install php53-mysql php53-gd php53-imap php53-ldap php53-odbc php53-pear php53-xml php53-xmlrpc
  或者
  yum install php53-* -y
  安装过程可能比较慢,请耐心等待。完成后再次重启Apache:



1/etc/init.d/httpd restart
  重新在浏览器中打开IP/info.php页面,应该能找到MySQL、GD、mbstring等模块:



  此时LAMP运行环境已经初步安装完毕。最后还需要将LAMP组件设置为自动启动:



1chkconfig --levels 2345 httpd on

2chkconfig --levels 2345 mysqld on
  
最后介绍相关配置与环境
  Apache主配置文件:/etc/httpd/conf/httpd.conf
  Apache主配置目录,可以将不同类型的配置分门别类放入这个目录中:/etc/httpd/conf.d/
  Apache网站根目录:/var/www/html/
  Apache日志文件目录:/var/log/httpd
  MySQL的my.cnf配置文件:/etc/my.cnf
  MySQL数据库文件位置:/usr/lib/mysql
  l
  安装完成后,一是留意防火墙,打开相关端口,而是必须要对MySQL、Apache进行安全设置,避免安全漏洞
  
  http://www.centos.bz/lamp/

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-101206-1-1.html 上篇帖子: 安装Ubuntu并且搭建php开发环境(lamp) 下篇帖子: ubuntu配置LAMP
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表