linux下安裝apache和php和mysql


  我的系統環境時ubuntu 18.04.3,為了ROS:

  首先:安裝下面一堆軟件包:

  sudo apt install nginx nginx-doc fcgiwrap

  sudo apt install apache2-doc php-pear apache2-suexec-pristine

  sudo apt install apache2 apache2-ssl-dev php7.2 mysql-server mysql-client

  如果分開安裝,安裝先安裝apache2,php7和mysql的順序安裝,不要錯了。

  接着:安裝測試:

  apache2 -v

  返回信息:
  Server version: Apache/2.4.29 (Ubuntu)
  Server built:   2019-09-16T12:58:48

  php -v

  返回信息:
  PHP 7.2.19-0ubuntu0.18.04.2 (cli) (built: Aug 12 2019 19:34:28) ( NTS )
  Copyright (c) 1997-2018 The PHP Group
  Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies  with Zend OPcache v7.2.19-0ubuntu0.18.04.2, Copyright (c) 1999-2018, by Zend Technologies

  mysql -V

  返回信息:
  mysql  Ver 14.14 Distrib 5.7.27, for Linux (x86_64) using  EditLine wrapper

  有這些表明安裝成功。剩下的就是配置工作了,安裝好了,其實就已經啟動了,什么都可以不做了。
  然后:測試,

  測試apache2

  打開瀏覽器,在地址欄輸入:http://127.0.0.1/,按下回車

  出現了Apache頁面就表示安裝成功啦!

  測試php7

  改變/var/www/html/目錄的權限,sudo cd /var/www/   &&  chmod o+w  html/

  cd  html/

  vim  testp.php文件,內容如下:

  <?php

  echo phpinfo();

  保存,退出

  瀏覽器訪問http://127.0.0.1/testp.php,就應該可以看到php的版本與其他信息,成功了一半。

  測試並配置數據庫:

  修改數據庫,將匿名用戶在mysql中刪除:

  sudo mysql -u root -p

  輸入超級用戶密碼:,檢驗無誤后,就變成mysql的提示符號:mysql> 

  show databases                        #查看數據庫

  use mysql                              #切換到mysql數據庫

  delete from user where User='';                      #刪除匿名用戶

  quit                                 #退出數據庫

  sudo mysqladmin -u root -p reload                   #刷新數據庫

  輸入密碼,沒有任何提示,表明執行成功。

  然后:如果想要將代碼直接應用時,可以將網站代碼直接放到/var/www/html/目錄即可,剛才已經給了權限了,進行簡單配置就可以使用了。

  然后:如果想使用二級域名訪問網站,修改/etc/apache2/sites-available/000-default.conf,添加虛擬主機配置:

  

 1 <VirtualHost *:80>
 2         ServerName www.yourName.top
 3         DocumentRoot /var/www/html/who
 4         <Directory /var/www/html/who/>
 5                 Options Indexes FollowSymLinks MultiViews
 6                 AllowOverride None
 7                 Order allow,deny
 8                 allow from all
 9         </Directory>
10         ErrorLog ${APACHE_LOG_DIR}/error.log
11         CustomLog ${APACHE_LOG_DIR}/access.log combined
12 </VirtualHost>

  建立鏈接文件:sudo ln -s /etc/apache2/sites-available/yuyu /etc/apache2/sites-enabled/yuyu

  檢查配置文件語法sudo apache2ctl configtest 

  重啟Apache2sudo /etc/init.d/apache2 restart 
  通過瀏覽器用二級域名訪問,成功,就萬事大吉了。

  最后:我們來看看php的用處了。

  在/var/www/html/文件價下新建一個文件processorder.php  

  1 <!DOCTYPE html>
  2 <html>
  3     <head>
  4         <title>Bob's Auto Parts - Order Results</titl    e>
  5     </head>
  6     <body>
  7         <h1>Bob's Auto Parts</h1>
  8         <h2>Order Result</h2>
  9         <?php
 10             echo '<p>Order processed.</p>'
 11         ?>                                           
 12     </body>
 13 </html>

  通過瀏覽器訪問http://127.0.0.1/processorder.php

  開始覺得和html看到的內容時一樣的,但是使用瀏覽器的查看源代碼功能,看到的代碼如下:

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <title>Bob's Auto Parts - Order Results</title>
 5     </head>
 6     <body>
 7         <h1>Bob's Auto Parts</h1>
 8         <h2>Order Result</h2>
 9         <p>Order processed.</p>    </body>
10 </html>

  是不是對php的解析有點感覺了。好了,到此為止吧。

  今天發現還是nginx更加輕便點,安裝好了:啟動:

  nginx -s reload

  什么有錯誤:

   2019/10/26 22:26:23 [warn] 2202#2202: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
  2019/10/26 22:26:23 [notice] 2202#2202: signal process started
  2019/10/26 22:26:23 [error] 2202#2202: open() "/run/nginx.pid" failed (2: No such file or directory)

  修改文件:vim /etc/nginx/nginx.conf中的http {}里添加以下兩行:

  types_hash_max_size 2048;
    types_hash_bucket_size 1024;

  再次啟動實施看看吧。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM