linux下部署php项目环境可以分为两种,一种使用apache,php,mysql的压缩包安装,一种用yum命令进行安装。
使用三种软件的压缩包进行安装,需要手动配置三者之间的关系。apache和php之间的配置没有什么难度,但是和mysql进行配置的时候就需要对php的了解了。
我的官方群点击此处。
以下是用yum在linux中配置php环境:
1.mysql和apache最好是首先进行安装的,因为在配置php的时候需要与mysql和apache进行关联配置和测试
首先下载mysql-ver文件,因为博主linux环境是centos版本,yum源中貌似没有正常安装mysql时的mysql-ver文件,需要去官网上下载
1.下载mysql-rvice文件[root@tele-1 ~]# wgetmysql-rvice[root@tele-1 ~]# rpm -ivh mysql-community-relea-el7-5.noarch.rpm
2.安装mysql
[root@tele-1 ~]# yum install mysql-community-rver
3.安装完毕之后启动mysql服务
[root@tele-1 ~]# rvice 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 474801rver version: 5.6.36 mysql community rver (gpl) copyright (c) 2000, 2017, oracle and/or its affiliates. all rights rerved.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> t password for 'root'@'localhost' = password('你要修改的密码');query ok, 0 rows affected (0.06 c)
5.因为博主是用本地navicat软件来连接linux下的mysql的,所以如果要在本地访问的话,就需要改一下mysql数据库中的ur表了
1.操作mysql数据库表
mysql> u mysql;reading table information for completion of table and column namesyou can turn off this feature to get a quicker startu瞿秋白简介p with -a databa changedmysql>
2.查看ur表中的数据(在mysql命令行中可以直接进行sql语句编写)
mysql> lect * from ur;+-----------+------+-----------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+---------什么游戏赚钱----+-----------------+----------------------+-----------------------+-----------------------+------------------+| host | ur | password | lect_priv | inrt_priv | update_priv | delete_priv | create_priv | drop_priv | reload_priv | shutdown_priv | process_priv | fi巴西龟饲养le_priv | grant_priv | references_priv | index_priv | alter_priv | show_db_priv | super_priv | create_tmp_table_priv | lock_tables_priv | execute_priv | repl_slave_priv | repl_client_priv | create_view_priv | show_view_priv | create_routine_priv | alter_routine_priv | create_ur_priv | event_priv | trigger_priv | create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_ur_connections | plugin | authentication_string | password_expired |+-----------+------+-----------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+| % | root | *3ce8dad2446975d8b0c771bd7e48d15b | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | n || localhost | root | *3ce8dad2446975d8b0c771bd7e48d15b | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | | | | |排骨汤怎么炖好吃 0 | 0 | 0 | 0 | mysql_native_password | | n || 127.0.0.1 | root | *3ce8dad2446975d8b0c771bd7e48d15b | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | n || ::1 | root | *3ce8dad2446975d8b0c771bd7e48d15b | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | n || tele-1 | | | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | n | | | | 口袋天空 | 0 | 0 | 0 | 0 | mysql_native_password | null | n |+-----------+------+-----------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+5 rows in t (0.00 c)mysql>
表中是修改之后的表了,想要远程访问,就需要上边红色标注的数据了,host指的是可以访问此数据库的ip地址,%代表的是所有的请求都可以连接进来。
大家可以修改一条数据,也可以添加一条数据。但是最好不要修改上边蓝色标注的数据,修改语句就是下边的格式
mysql> update ur t host = '%' where ???
4.最后推出exit或者\q都是退出mysql命令行的方法
mysql> \qbye
1.apache安装方法相对简单
[root@tele-2 ~]# yum install httpd
2.外网访问虚拟机中的地址,我们就需要修改一下apache的配置文件/etc/httpd/conf/httpd.conf
找到 #rvernamehttp://www.example.com:80改为 rvername localhost:80
如图所示:
找到 #listen 改为 listen:8080(linux中开放的端口号80xx)
3.修改完成之后我们需要再次启动httpd服务,并查看启动状态
[root@tele-2 ~]# rvice httpd startredirecting to /bin/systemctl start httpd.rvice[root@tele-2 ~]# rvice httpd statusredirecting to /bin/systemctl status httpd.rvice● httpd.rvice - the apache http rver loaded: loaded (/usr/lib/systemd/system/httpd.rvice; enabled; vendor pret: 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.rvice ├─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 rver...jun 05 15:57:34 tele-2 systemd[1]: started the apache http rver.
4.此时你就可以访问你的服务器了,输入localhost或者ip地址,出现一个apache test page powered by centos的测试页面
1.php安装命令
[root@tele-2 ~]# yum install php
2.直接一路安装,安装完成之后再次重启httpd服务
[root@tele-2 ~]# rvice httpd startredirecting to /bin/systemctl start httpd.rvice
3.重启之后我们进行测试php相关信息,我们新建一个php界面进行测试
在apache默认页面路径/var/www/html
下新建一个test.php页面,添加代码
<?php phpinfo();?>
4.访问这个页面,输入localhost/test.php,或者
ip:端口号/test.php就可以看见php环境的配置信息了。如图:
1.搜索模块
[root@tele-2 ~]# yum arch 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.rver) /usr/bin(mysqladmin mysqldump) my.cnf: /etc/my.cnf :/etc/rc.d/init.d/mysql:rvice mysql start停止命令:rvice mysql stop运行状态:rvice mysql status
2.apache
配置文件路径:/etc/httpd/conf/httpd.confrvice httpd startrvice httpd stop运行状态:rvice httpd status
3.php
php默认页面路径:/var/www/html
以上就是linux下如何部署php项目
详细内容请关注我的知乎专栏
以上内容希望帮助到大家,很多phper在进阶的时候总会遇到一些问题和瓶颈,业务代码写多了没有方向感,不知道该从那里入手去提升,对此我整理了一些资料,包括但不限于:分布式架构、高可扩展、高性能、高并发、服务器性能调优、tp6,laravel,yii2,redis,swoole、swoft、kafka、mysql优化、shell脚本、docker、微服务、nginx等多个知识点高级进阶干货需要的可以免费分享给大家,需要的可以加入我的官方群点击此处。
本文发布于:2023-04-08 00:19:33,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/dfb57a06a4fcf02414a7d3c177504a52.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:linux下如何部署php项目?.doc
本文 PDF 下载地址:linux下如何部署php项目?.pdf
留言与评论(共有 0 条评论) |