您好,欢迎访问一九零五行业门户网

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

本篇文章给大家分享教你玩转linux下部署php项目-apache、php、mysql关联(分享)有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
linux下部署php项目环境可以分为两种,一种使用apache,php,mysql的压缩包安装,一种用yum命令进行安装。
使用三种软件的压缩包进行安装,需要手动配置三者之间的关系。apache和php之间的配置没有什么难度,但是和mysql进行配置的时候就需要对php的了解了。
以下是用yum在linux中配置php环境:
mysql1.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 -urootwelcome to the mysql monitor. commands end with ; or \g.your mysql connection id is 474801server 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 itsaffiliates. other names may be trademarks of their respectiveowners.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 information for completion of table and column namesyou can turn off this feature to get a quicker startup with -adatabase changedmysql>
2.查看user表中的数据(在mysql命令行中可以直接进行sql语句编写)
mysql> select * from user;mysql>
3.博主的表中是修改之后的表了,想要远程访问,就需要上边红色标注的数据了,host指的是可以访问此数据库的ip地址,%代表的是所有的请求都可以连接进来。
大家可以修改一条数据,也可以添加一条数据。但是最好不要修改上边蓝色标注的数据,修改语句就是下边的格式
mysql> update user set host = '%' where ?
4.最后推出exit或者\q都是退出mysql命令行的方法
mysql> \qbye
安装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 startredirecting to /bin/systemctl start httpd.service[root@tele-2 ~]# service httpd statusredirecting 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 -dforegroundjun 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 startredirecting 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环境的配置信息了
关联php和mysql1.搜索模块
[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/mysql(mysql.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视频教程》
以上就是教你玩转linux下部署php项目-apache、php、mysql关联(分享)的详细内容。
其它类似信息

推荐信息