search
HomeBackend DevelopmentPHP Tutorial老司机传授Ubuntu下Apache+PHP+MySQL环境搭建攻略_PHP

一、首先安装MySql:
对于MySql来讲在整个过程中是相对独立的安装,并且我的ubuntu在以前做开发的时候就已经安装了MySql,所以以下只给出安装步骤:
 
1、安装MySql的服务:

sudo apt-get install mysql-server

      要注意的是安装过程中会提示你设置mysql的root账户的密码;其他就没什么需要注意的地方了。

2、安装MySql的客户端:

sudo apt-get install mysql-client 

直接输入安装

3、安装MySql的lib依赖库:

sudo apt-get install libmysqlclient15-dev

进行安装。
        如果不安装的话会在系统中找不到mysql.h
       
4、MySQL的一些简单管理:

       启动MySQL服务:

sudo start mysql

       停止MySQL服务:

sudo stop mysql

       修改 MySQL 的管理员密码:

sudo mysqladmin -u root password newpassword

       设置远程访问(正常情况下,mysql占用的3306端口只是在IP 127.0.0.1上监听,拒绝了其他IP的访问(通过netstat可以查看到)。取消本地监

     听需要修改 my.cnf 文件:):   

    sudo vi /etc/mysql/my.cnf

    bind-address = 127.0.0.1 //找到此内容并且注释

      
5、MySQL安装后的目录结构分析(此结构只针对于使用apt-get install 在线安装情况):

      数据库存放目录:/var/lib/mysql/

      相关配置文件存放目录:/usr/share/mysql

      相关命令存放目录:/usr/bin(mysqladmin mysqldump等命令)

      启动脚步存放目录:/etc/rc.d/init.d/

以上就是MySql的基本安装了。

二、安装apache2:

1、官网下载http://httpd.apache.org/download.cgi,Unix Source: httpd-2.2.24.tar.gz,我下的是2.2.24版本的tar.gz,然后解压tar.gz

   tar zxvf httpd-2.2.24.tar.gz

      把解压出来的文件移动到/usr/src/apache2
 

   sudo mv -r httpd-2.2.24 /usr/src/apache2 

如果没有apache2文件无法移动的话 手动创建一个

sudo mkdri /usr/src/apache2 

由于修改/usr/下的文件需要root权限,所以需要加上sodu命令,加输入密码。

2、进入/usr/src/apache2/httpd-2.2.24,并且编译安装

   cd /usr/src/apache2/httpd-2.2.24
   ./configure -prefix=/usr/local/apache -enable-module=so -enable-rewrite=shared -enable-authn-dbm

                                
      编译完成没错之后
      输入make命令,完成后输入:make install开始安装。

3、安装完成后配置httpd.conf:

   vim /usr/local/apache2/conf/httpd.conf  #用编辑器打开httpd.conf 我用的是vim打开的

      找到#ServerName 将前面的注释符号#去掉  并且将后面的内容改成localhost:80 整句就是:
      ServerName localhost:80
      这样服务启动的时候可以通过localhost来进行访问。
      如果要修改服务器的监听端口的话可以在httpd.conf中查找Listen 80把 后面的80改成你想要的端口,在把ServerName localhost:80 后面的80改成你想要的端口。

4、启动服务:

   cd /usr/local/apache2/bin #进入/usr/local/apache2/bin目录
   sudo ./apachectl start      #启动apache 服务

      然后打开游览器,输入访问地址localhost看看能否显示It Works,如果可以显示就说明已经安装完成。

三、安装配置PHP5

1、首先安装libxml2库,用来解析xml的的lib库输入:sudo apt-get install libxml2-dev 进行安装

2、官网下载php http://www.php.net/downloads.php 然后解压下载来的tar.gz包

   tar zxvf php-5.4.15.tar.gz           #解压
    sudo mv -r php-5.4.15 /usr/src/php5 #移动到/usr/src/php5目录下

3、编译安装php

   cd /usr/src/php/php-5.4.15  #进入php所在目录
    ./configure  
    -prefix=/usr/local/php5   #php安装目录
    -with-apxs2=/usr/local/apache2/bin/apxs  #apxs所在的目录,如果没有就sudo find / -name apxs 查询一下所在的目录
    -with-mysql=/usr/   #这个是查找mysql.h的目录,不知道为什么我的mysql.h在/usr/include/中 但是 写这个路径没用必须写/usr/ 如果不知道mysql.h在哪就 sudo find / -name mysql.h查找一下
    -with-mysqli=/usr/bin/mysql_config #mysql_config所在的目录,如果不再这个目录就find一下。
    -with-gd  #打开对gd库的支持,如果应为这个报错,就安装一下gd库
    -with-pear #打开pear命令的支持
    -with-libxml-dir  #打开对刚刚安装的libxml2的支持

       整条编译语句是:

代码如下:

./configure -prefix=/usr/local/php5 -with-apxs2=/usr/local/apache2/bin/apxs -with-mysql=/usr/  -with-mysqli=/usr/bin/mysql_config -with-gd  -with-pear -with-libxml-dir


      如果编译时出现error的话 一般都是 依赖库lib 出问题,看提示缺少什么依赖库,然后安装一下就行。
      完成后make一下 然后再输入make install进行安装。
 
4、手动指定php.ini文件:
      打开/usr/local/apache2/conf/httpd.conf,在LoadModule php_module     modules/libphp5.so这行下面加入PHPIniDir /etc/php.ini 指定php.ini的路径,然后进入你解压的php-5.4.15.tar.gz的目录将php.ini-development复制到你指定的路劲/etc里并且重命名为php.ini:

   cd /usr/src/php/php-5.4.15 #进入php目录
   sudo cp php.ini-development /etc #复制到/etc
   sudo mv php.ini-development php.ini #重命名为php.ini

5、修改httpd.conf中的php支持和默认访问index.php:
      打开/usr/local/apache2/conf/httpd.conf,把中的内容改成:

   <Directory  />
   Options FollowSymLinks
   DirectoryIndex index.php index.html  #指定默认先查找index.php 如果没有就查找index.html
   AllowOverride None
   Order deny,allow
   Deny from all
   </Directory>

     接着在AddType application/x-gzip .gz .tgz下面一行中加入:

   AddType application/x-httpd-php .php
   AddType application/x-httpd-php-source .phps

     完成后保存文件,如果提示文件是只读模式无法保存的话,那么肯定是权限不够在用打开httpd.conf的命令时 要加上sudo
 
6、启动\重启apache服务,在服务器根目录下编写php文件

   sudo /usr/local/apache2/bin/apachectl stop #停止服务
   sudo /usr/local/apache2/bin/apachectl start #启动服务
   sudo /usr/local/apache2/bin/apachectl rstart #重启服务
     

   cd /usr/lcoal/apache2/htdocs #进入apache2默认根目录

      创建一个index.php文件 在里面编写然后打开游览器输入localhost看看能否显示php的信息,如果可以则配置成功。


四、其他配置:
    
1、手动配置apache的默认的根目录
      用编辑器打开/usr/local/apache2/conf/httpd.conf目录然后找到DocumentRoot /usr/lcoal/apache2/htdocs把这个路径改成你要的路径 然后在往下一点找到把里面的路径也改成你想要指定的路径就可以了。

2、查看php.ini所在的路径:
      很多时候不知道指定php.ini的路径在哪看,只要编写文件 然后用游览器访问,看到php所有信息之后 找到:Loaded Configuration File这一行的 右边的路径信息 就是指定的php.ini路径的地址了。
      
     

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何在 Ubuntu 和其他 Linux 下安装 IDLE Python IDE如何在 Ubuntu 和其他 Linux 下安装 IDLE Python IDEApr 08, 2023 pm 10:21 PM

IDLE(集成开发学习环境Integrated Development and Learning Environment)是一个 ​​Python IDE​​​,由 Python 语言本身编写,在 Windows 中通常作为 ​​Python 安装​​ 的一部分而安装。它是初学者的理想选择,使用起来很简单。对于那些正在学习 Python 的人,比如学生,它可以作为一个很好的 IDE 来开始使用。语法高亮、智能识别和自动补全等基本功能是这个 IDE 的一些特点。你可以随时在官方 ​​文档​​ 中了

聊聊Ubuntu中怎么切换多个 PHP 版本聊聊Ubuntu中怎么切换多个 PHP 版本Aug 30, 2022 pm 07:37 PM

如何在 Ubuntu 中切换多个 PHP 版本?下面本篇文章给大家介绍一下Ubuntu中切换多个 PHP 版本的方,希望对大家有所帮助!

ubuntu怎么重启nginx服务ubuntu怎么重启nginx服务May 23, 2023 pm 12:22 PM

1.使用快捷键【Ctrl+Alt+T】打开终端命令模式。2.可以通过以下方式重启nginx服务。方法一,在nginx可执行目录sbin下,输入以下命令重启/nginx-sreload#重启方法二,查找当前nginx进程号,然后输入命令:kill-HUP进程号,实现重启nginx服务#ps-ef|grepnginx#查找当前nginx进程号]#kill-TERM132#杀死nginx进程,132为nginx进程号

docker内ubuntu乱码怎么办docker内ubuntu乱码怎么办Nov 04, 2022 pm 12:04 PM

docker内ubuntu乱码的解决办法:1、通过“locale”查看本地使用的语言环境;2、通过“locale -a”命令查看本地支持的语言环境;3、在“/etc/profile”文件的结尾处添加“export LANG=C.UTF-8”;4、重新加载“source /etc/profile”即可。

ubuntu php无法启动服务怎么办ubuntu php无法启动服务怎么办Dec 19, 2022 am 09:46 AM

ubuntu php无法启动服务的解决办法:1、在php-fpm.conf里面设置错误日志;2、执行“/usr/sbin/php-fpm7.4 --fpm-config /etc/php/fpm/php-fpm.conf”命令;3、修改php的配置文件注释即可。

Ubuntu如何删除无用的Linux内核Ubuntu如何删除无用的Linux内核May 14, 2023 pm 09:13 PM

查找无用的镜像首先,您可以检查当前使用的内核,您可以通过命令获得信息:uname-aa.例如,它在我的桌面上显示为:复制代码代码如下:magc@magc-desktop:~$uname-aLinuxmagc-desktop2.6.24-19-RT#1SMPpremptRTThu8月21日02:08336003UTC2008i686GNU/Linux然后通过查看这台机器上所有内核的列表来决定哪些需要删除:运行命令:复制代码代码如下:dpkg-get-selections|greplinux例如,我

ubuntu没有php-fpm怎么办ubuntu没有php-fpm怎么办Feb 03, 2023 am 10:51 AM

ubuntu没有php-fpm的解决办法:1、通过执行“sudo apt-get”命令添加php的源地址;2、查看有没有php7的包;3、通过“sudo apt-get install”命令安装PHP;4、修改配置监听9000端口来处理nginx的请求;5、通过“sudo service php7.2-fpm start”启动“php7.2-fpm”即可。

Ubuntu下Nginx如何安装与配置Ubuntu下Nginx如何安装与配置May 17, 2023 am 11:01 AM

1.nginx介绍nginx是一个非常轻量级的http服务器,nginx,它的发音为“enginex”,是一个高性能的http和反向代理服务器,同时也是一个imap/pop3/smtp代理服务器。2.对php支持目前各种web服务器对php的支持一共有三种:(1)通过web服务器内置的模块来实现,例如apache的mod_php5,类似的apache内置的mod_perl可以对perl支持。(2)通过cgi来实现,这个就好比之前perl的cgi,该种方式的缺点是性能差,因为每次服务器遇到这些脚本

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),