linux下如何部署php項目?

linux下部署php項目環境能夠分爲兩種,一種使用Apache,php,mysql的壓縮包安裝,一種用yum命令進行安裝。php

使用三種軟件的壓縮包進行安裝,須要手動配置三者之間的關係。apache和php之間的配置沒有什麼難度,可是和mysql進行配置的時候就須要對php的瞭解了。html

個人官方羣點擊此處mysql

如下是用yum在linux中配置php環境:linux

MySql

  1.mysql和apache最好是首先進行安裝的,由於在配置php的時候須要與mysql和apache進行關聯配置和測試laravel

首先下載mysql-sever文件,由於博主linux環境是CentOS版本,yum源中貌似沒有正常安裝mysql時的mysql-sever文件,須要去官網上下載sql

1.下載mysql-service文件
[root@tele-1 ~]# wget
mysql-service
[root@tele-1 ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

2.安裝mysqlshell

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

3.安裝完畢以後啓動mysql服務數據庫

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

4. 初步安裝的mysql是沒有密碼的,用戶名默認是root。因此咱們須要修改密碼,用mysql命令行進行修改apache

 1.進入mysql命令行centos

[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>

表中是修改以後的表了,想要遠程訪問,就須要上邊紅色標註的數據了,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 改成  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 -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();?>

  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

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項目

詳細內容請關注個人知乎專欄

以上內容但願幫助到你們,不少PHPer在進階的時候總會遇到一些問題和瓶頸,業務代碼寫多了沒有方向感,不知道該從那裏入手去提高,對此我整理了一些資料,包括但不限於:分佈式架構、高可擴展、高性能、高併發、服務器性能調優、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql優化、shell腳本、Docker、微服務、Nginx等多個知識點高級進階乾貨須要的能夠免費分享給你們,須要的能夠加入個人官方羣點擊此處

相關文章
相關標籤/搜索