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

[经验分享] CentOS LAMP环境搭建和测试php与mysql的连接

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2018-12-22 10:54:12 | 显示全部楼层 |阅读模式
  
  CentOS LAMP作为服务器,不安装不需要的组件,所以在选择组件的时候,不要选web服务器,因为我们后面要手动编译安装。CentOS LAMP系统约定RPM包和源码包存放位置:


  • RPM包和源码包存放位置 /usr/local/src  
  • 源码包编译安装位置(prefix) /usr/local/XXX  
  • MySQL 数据库位置 /usr/local/mysql/var  
  • 网站根目录 /usr/local/apache/htdocs

  CentOS LAMP环境搭建
  搭建的工作包括APACHE、MYSQL、PHP。可以按照这个顺序来搭建环境。
  1、获取软件包


  • Httpd:  http://www.apache.org/dist/httpd/httpd-2.2.11.tar.gz  
  • mysql: http://mirror.provenscaling.com/mysql/enterprise/source/5.0/mysql-5.0.70.tar.gz  
  • php: http://museum.php.net/php5/php-5.2.2.tar.gz

  把它们全部放到 /usr/local/src 下面.>cd /usr/local/src    (定位到安装包目录)
  2、安装 mysql


  • >tar -zxvf mysql-5.0.70.tar.gz  
  • >cd mysql-5.0.70  
  • >./configure --prefix=/usr/local/mysql  
  • >make  
  • >make install   
  • >useradd mysql //添加 mysql 用户  
  • >cd /usr/local/mysql  
  • >bin/mysql_install_db --user=mysql
  • >chown -R mysql .  //设置权限,注意后面有一个点 "."  
  • >chgrp -R mysql .  
  • >chown -R mysql var  
  • >cp share/mysql/my-medium.cnf /etc/my.cnf  
  • >cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //开机启动  
  • >chmod 755 /etc/rc.d/init.d/mysqld  
  • >chkconfig --add mysqld

  运行了上面第8步后:
  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/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h centos5 password 'new-password'
Alternatively you can run:
/usr/local/mysql/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/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
  运行以下命令即可启动 MySQL 服务器:>/etc/rc.d/init.d/mysqld start //启动 MySQL(mysql安装完毕)
  3、安装Apache


  • >tar -zxvf httpd-2.2.11.tar.gz  
  • >cd httpd-2.2.11  
  • >./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max
  • >make  
  • >make install

  运行上面第3步时,出现下面的问题:
  [root@centos5 httpd-2.3.8]# ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking target system type... i686-pc-linux-gnu
Configuring Apache Portable Runtime library ...
checking for APR... no
configure: error: APR not found.  Please read the documentation.
  到http://apr.apache.org/download.cgi下载 apr-1.4.2.tar.gz。
  解压后进入解压目录,进行如下操作:
  ./configure --prefix=/desired/path/of/apr
   make
   make test
   make install

  启动apache服务 >/usr/local/apache/bin/apachectl -k start用浏览器打开 http://127.0.0.1/  如果可以访问则说明apache安装成功。
  4、安装PHP
  >tar -zxvf php-5.2.2.tar.gz
>cd php-5.2.2
>./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs
>make
>make install
>cp php.ini-dist /usr/local/php/lib/php.ini
>vi /usr/local/php/lib/php.ini

  5、CentOS LAMP配置httpd
  .conf >vi /usr/local/apache/conf/httpd.conf找到"AddType application/x-gzip .tgz"在它的下面添加AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps找到"DirectoryIndex index.html在index.html 前添加 index.php
  启动apache服务>/usr/local/apache/bin/apachectl -k start将apache设置成开机自启动:在/etc/rc.d/rc.local文件中加入一行并保存: /usr/local/apache /bin/apachectl start (apache+php配置完毕)
  6、查看确认 L.A.M.P 环境信息:>vi /usr/local/apache/htdocs/phpinfo.php新增加下面一行,并保存。 >chmod 755 /usr/local/apache/htdocs/phpinfo.php用浏览器打开 http://127.0.0.1/phpinfo.php检查 phpinfo中的各项信息是否正确。如果可以访问则环境搭建成功
  测试php与mysql的连接


  • >vi /usr/local/apache/htdocs/testdb.php增加下面几行,并保存。  

  • >chmod 755 /usr/local/apache/htdocs/testdb.php  
  • >service mysqld start

  用浏览器打开 http://127.0.0.1/testdb.php如果输出success表明php与mysql连接成功CentOS 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-654328-1-1.html 上篇帖子: 安装php ssh2扩展 下篇帖子: PHP(11) 图像型的验证码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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