微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

教你玩转linux下部署php项目-Apache、php、mysql关联分享

本篇文章给大家分享教你玩转linux下部署PHP项目-Apache、PHPMysqL关联(分享)有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

  linux下部署PHP项目环境可以分为两种,一种使用Apache,PHPMysqL的压缩包安装,一种用yum命令进行安装。

使用三种软件的压缩包进行安装,需要手动配置三者之间的关系。apache和PHP间的配置没有什么难度,但是和MysqL进行配置的时候就需要对PHP的了解了。

以下是用yum在linux中配置PHP环境:

MysqL

  1.MysqL和apache最好是首先进行安装的,因为在配置PHP的时候需要与MysqL和apache进行关联配置和测试

首先下载MysqL-sever文件,因为博主linux环境是CentOS版本,yum源中貌似没有正常安装MysqL时的MysqL-sever文件,需要去官网上下载

1.下载MysqL-service文件
[root@tele-1 ~]# wget http://dev.MysqL.com/get/MysqL-community-release-el7-5.noarch.rpm
2.安装MysqL-service文件
[root@tele-1 ~]# rpm -ivh MysqL-community-release-el7-5.noarch.rpm

2.安装MysqL

[root@tele-1 ~]# yum install MysqL-community-server

3.安装完毕之后启动MysqL服务

[root@tele-1 ~]# service MysqLd restart

4. 初步安装的MysqL是没有密码的,用户名认是root。所以我们需要修改密码,用MySQL命令行进行修改

 1.进入MySQL命令

[root@tele-1 ~]# MysqL -uroot
Welcome to the MysqL monitor.  Commands end with ; or \g.
Your MysqL connection id is 474801
Server version: 5.6.36 MysqL Community Server (GPL)

copyright (c) 2000, 2017, 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>
2.使用命令进行密码修改
MysqL> set password for 'root'@'localhost' = password('你要修改密码');
Query OK, 0 rows affected (0.06 sec)

 5.因为博主是用本地navicat软件来连接linux下的MysqL的,所以如果要在本地访问的话,就需要改一下MysqL数据库中的user表了

1.操作MysqL数据库
MysqL> use MysqL;
Reading table @R_295_4045@ion for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MysqL>
2.查看user表中的数据(在MySQL命令行中可以直接进行sql语句编写)
MysqL> select * from user;
MysqL>

 3.博主的表中是修改之后的表了,想要远程访问,就需要上边红色标注的数据了,Host指的是可以访问此数据库的ip地址,%代表的是所有的请求都可以连接进来。

大家可以修改一条数据,也可以添加一条数据。但是最好不要修改上边蓝色标注的数据,修改语句就是下边的格式

MysqL> update user set Host = '%' where ???

4.最后推出exit或者\q都是退出MySQL命令行的方法

MysqL> \q
Bye

安装Apache

 1.apache安装方法相对简单

[root@tele-2 ~]# yum install httpd

2.外网访问虚拟机中的地址,我们就需要修改一下apache的配置文件/etc/httpd/conf/httpd.conf

找到 #ServerName www.example.com:80 改为  ServerName localhost:80

如右图所示:

 找到  #Listen 改为  Listen:8080(linux中开放的端口号80XX)

 如右图所示:

3.修改完成之后我们需要再次启动httpd服务,并查看启动状态

[root@tele-2 ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service
[root@tele-2 ~]# service httpd status
Redirecting to /bin/systemctl status  httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-06-05 15:57:34 CST; 5s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 54532 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 39046 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 54573 (httpd)
   Status: Processing requests...
   Memory: 15.8M
   CGroup: /system.slice/httpd.service
           ├─54573 /usr/sbin/httpd -DFOREGROUND
           ├─54576 /usr/sbin/httpd -DFOREGROUND
           ├─54577 /usr/sbin/httpd -DFOREGROUND
           ├─54578 /usr/sbin/httpd -DFOREGROUND
           ├─54579 /usr/sbin/httpd -DFOREGROUND
           └─54580 /usr/sbin/httpd -DFOREGROUND

Jun 05 15:57:34 tele-2 systemd[1]: Starting The Apache HTTP Server...
Jun 05 15:57:34 tele-2 systemd[1]: Started The Apache HTTP Server.

4.此时你就可以访问你的服务器了,输入localhost或者ip地址,出现一个Apache test page powered by centos的测试页面

PHP

 1.PHP安装命令

[root@tele-2 ~]# yum install PHP

 2.直接一路安装,安装完成之后再次重启httpd服务

[root@tele-2 ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service

 3.重启之后我们进行测试PHP相关信息,我们新建一个PHP界面进行测试

在apache页面路径/var/www/html下新建一个test.PHP页面添加代码

<?PHP
 PHPinfo();
?>

 4.访问这个页面,输入localhost/test.PHP,或者ip:端口号/test.PHP就可以看见PHP环境的配置信息了   

关联PHPMysqL

1.搜索模块

[root@tele-2 ~]# yum search PHP

2.安装相关模块

[root@tele-2 ~]# yum install PHP-MysqL PHP-gd PHP-imap PHP-ldap PHP-odbc PHP-pear PHP-xml  PHP-xmlrpc

3.安装完成,重启MysqLd,重启httpd重新访问刚才的info.PHP,我们发现已经多了MysqL的相关信息。如右图:

至此,PHP在linux中的运行环境就已经成功配置完成了。

1.MysqL yum安装文件夹及相关命令

数据库目录:/var/lib/MysqL/

配置文件:/usr/share/MysqLMysqL.server命令及配置文件)

相关命令:/usr/bin(MysqLadmin MysqLdump等命令)

my.cnf: /etc/my.cnf

启动脚本:/etc/rc.d/init.d/(启动脚本文件MysqL的目录)
启动命令:service MysqL start
停止命令:service MysqL stop
运行状态:service MysqL status

 2.apache

配置文件路径:/etc/httpd/conf/httpd.conf
启动命令:service httpd start
停止命令:service httpd stop
运行状态:service httpd status

 3.PHP

PHP页面路径:/var/www/html

推荐学习:《PHP教程

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐