zoukankan      html  css  js  c++  java
  • 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;

      再次启动实施看看吧。

  • 相关阅读:
    Cron表达式,springboot定时任务
    go 语言中windows Linux 交叉编译
    SSM框架处理跨域问题
    golang gin解决跨域访问
    关于Integer类的值使用==比较
    IoC注解
    spring基础知识
    SQL SERVER大话存储结构(3)_数据行的行结构
    SQL SERVER
    MySQL-记一次备份失败的排查过程
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/11737854.html
Copyright © 2011-2022 走看看