linux下怎样布置php项目?【Linux】,Apache,linux,mysql,php,项目,部署

Linux 搜搜CMS网 11个月前 (11-26) 329次浏览 0个评论 扫描二维码

linux下怎样布置php项目?【Linux】,Apache,linux,mysql,php,项目,部署

linux下布置php项目环境能够分为两种,一种运用Apache,php,mysql的压缩包装置,一种用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
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 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 information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changedmysql>
2.检察user表中的数据(在mysql敕令行中能够直接举行sql语句编写)
mysql> select * from user;+-----------+------+-----------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+
| Host      | User | Password                                  | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_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_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_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 set (0.00 sec)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

linux下怎样布置php项目?【Linux】,Apache,linux,mysql,php,项目,部署

 找到  #ServerName http://www.example.com:80 改成  ServerName localhost:80

如右图所示:

linux下怎样布置php项目?【Linux】,Apache,linux,mysql,php,项目,部署

 找到  #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 -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 startRedirecting to /bin/systemctl start  httpd.service

  3.重启以后我们举行测试PHP相干信息,我们新建一个PHP界面举行测试

在apache默许页面途径/var/www/html下新建一个test.php页面,增加代码

<?php phpinfo();?>

linux下怎样布置php项目?【Linux】,Apache,linux,mysql,php,项目,部署

  4.接见这个页面,输入localhost/test.php,或许

ip:端口号/test.php就能够瞥见php环境的设置信息了。如右图:

关联php和mysql

  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

linux下怎样布置php项目?【Linux】,Apache,linux,mysql,php,项目,部署

  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

以上就是linux下怎样布置php项目?的细致内容,更多请关注ki4网别的相干文章!


版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:linux下怎样布置php项目?【Linux】,Apache,linux,mysql,php,项目,部署
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到