当前位置: 首页 > 后端技术 > PHP

在Ubuntu14.04下安装LAMP环境,从源码安装PHP5.6和Apache2.4

时间:2023-03-29 16:59:20 PHP

安装阿帕奇。Ubuntu14.04中的很多功能都在apache2包中,没有区分mpm-work、mpm-prefork、mpm-event等软件包,所以我们可以直接安装apache2###sudoapt-getinstallapache2-y注意:这里的-y是为了安装方便,加上不需要确认安装,简单粗暴KeytofinishinstallingApache'sPHPmodule在Ubuntu14.04中Apache的PHP模块有两个包,分别是:libapache2-mod-php5和libapache2-mod-php5filter。在大多数情况下,应该使用第一个。###sudoapt-getinstalllibapache2-mod-php5-ywww默认文件在/var/www/html###sudoserviceapache2restart可以重启apache安装PHP5的mysql模块安装后才能和mysql通信php###sudoapt-getinstallphp5-mysql-y将mysql客户端和服务一起安装,安装过程中系统会提示输入密码。这个时候需要输入密码###sudoapt-getmysql-servermysql-clien###sudoservicemysqlrestart可以重启mysql。实际上,您可以在此处浏览测试网页。如果PHP页面无法正常显示,首先要确保测试代码正确。###sudoa2enmodphp5###sudoserviceapache2restart同时清理浏览器缓存LAMP卸载如果要卸载LAMP相关软件包,需要如下代码实现###sudoapt-getpurgeapache*mysql*php*删除相关软件包。为了方便管理,我们这里又列出了另外一种安装方法,PHP5.6和Apache2.4的源码安装,因为Ubuntu14.04下的PHP版本是5.5.9,apt-get对一些PHP要求比较高版本不能做,所以源码安装方式对于来说不是一个好方法,灵活性和易用性都非常高。在安装Apache之前,需要先安装3个依赖**Apr(apacheportableruntime)****Apr-Util****pcre**(languagecompatibleregularexpression)cd/usr/local/src会统一安装包在一个目录下wgethttp://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gzwgethttp://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gzwgethttp://downloads.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz(需要能上网的电脑)wgethttp://mirrors.cnnic.cn/apache/下载/httpd/httpd-2.4.23.tar.bz2,解压apr源码包,编译安装tar-zxvfapr-1.5.2.tar.gzcd/apr-1.5.2./configure--prefix=/usr/local/apr&&make&&makeinstall第一步解压源码包,然后进入源码包,输入./configure.....--prefix表示指定安装文件路径,路径我们上面指定/usr/local/apr,apr文件夹一开始是不存在的,我们不需要创建。命令执行后会自动生成。make是编译makeinstall是安装下载,解压apr-util源码包,编译安装tar-zxvfapr-util-1.5.4cdapr-util-1.5.4./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr&&make&&makeinstall相对于上面的installapr只是多了--with-apr=/usr/local/apr因为apr-util的安装依赖apr编译安装pcre,这里pcre的安装不指定安装路径,默认安装在/usr/local/bin下。但是当你开始安装之前我们需要安装一些基本的编译环境###sudoapt-getinstallbuild-essential由于ubuntu自带c/c++编译,所以只需要安装上面那个即可。tar-zxvfpcre-8.39.tar.gzcdpcre-8.39./configure&&make&&makeinstall现在我们可以正式安装apache了tar-zxvfhttpd-2.4.23.tar.bz2cdhttpd-2.4.23./configure--prefix=/usr/local/apache--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util&&make&&makeinstall安装apache时需要依赖我们之前安装的apr和apr-util在/usr/下可以看到apache目录,网页存放在htdocs文件夹下。如果需要使用servicehttpdstart来启动apache服务,需要执行以下命令:cp/usr/local/apache/bin/apachectl/etc/如果init.d/apache有错误,可能有加载共享库时出现类似错误的错误:libpcre.so.1:无法打开共享对象文件:没有这样的文件或目录。解决办法是:###ln-s/usr/local/lib/libpcre.so.1/lib重启后可以拉到这里,执行serviceapachestart启动服务,访问127.0.0.1(如果服务器是搭建好的在本机上),可以看到页面输出工作了。安装PHP5.6可以到官网http://php.net/get/php-5.6.31.tar.gz/from/a/mirror/php-5.6.31下载我们需要的安装包。tar如果.gz链接失败,需要到官网下载对应的安装包来./configure\--prefix=/usr/local/php/\--with-config-file-path=/usr/local/php/etc\--with-config-file-scan-dir=/usr/local/php/etc/conf.d\--enable-soap\--with-openssl\--with-mcrypt\--with-pcre-regex\--with-sqlite3\--with-zlib\--enable-bcmath\--with-iconv\--with-bz2\--enable-calendar\--with-curl\--with-cdb\--enable-dom\--enable-exif\--enable-fileinf\--enable-filter\--with-pcre-dir\--enable-ftp\--with-gd\--with-openssl-dir\--with-jpeg-dir\--with-png-dir\--with-freetype-dir\--with-gettext\--with-gmp\--with-mhash\--enable-json\--enable-mbstring\--disable-mbregex\--disable-mbregex-backtrack\--with-libmbfl\--with-onig\--enable-pdo\--with-pdo-mysql\--with-zlib-dir\--with-pdo-sqlite\--with-readline\--enable-session\--enable-shmop\--enable-simplexml\--enable-sockets\--enable-sysvmsg\--enable-sysvsem\--enable-sysvshm\--enable-wddx\--with-libxml-dir\--with-xsl\--enable-zip\--enable-mysqlnd-compression-support\--with-pear\--with-mysqli\--with-apxs2=/usr/local/apache/bin/apxs我们可以看到上面的./configure有很多参数可以选择性安装--with-config-file-path和--with-config-file-scan-dir指定配置文件的放置路径。当然,问题来了。可能会出现很多错误,但没关系。有政策有对策,有普遍性的错误,所有的问题都可以在度娘身上找到。这里我简单罗列几个错误:configure:error:xml2-confignotfound。请检查您的libxml2安装。我已经安装了libxml2,但是还是提示:solution:#sudoapt-getinstalllibxml2-devError2:configure:error:PleasereinstalltheBZip2distribution而我已经安装了bzip2,网上找的解决办法都是需要安装bzip2-dev,但是11.10没有这个库解决方法:在网上找到bzip2-1.0.5.tar.gz,解压,直接make,sudomakeinstall。(我使用的源码来自http://ishare.iask.sina.com.cn/f/9769001.html)错误三:configure:error:Pleasereinstallthelibcurldistribution-easy.hshouldbein/include/curl/解决方法:#sudoapt-getinstalllibcurl4-gnutls-dev错误四:configure:error:jpeglib.h没有找到。解决方法:#sudoapt-getinstalllibjpeg-dev错误五:configure:error:png.hnotfound。解决方法:#sudoapt-getinstalllibpng-dev错误六:configure:error:libXpm.(a|so)未找到。解决方法:#sudoapt-getinstalllibxpm-dev错误七:configure:error:freetype.hnotfound。解决方法:#sudoapt-getinstalllibfreetype6-dev错误八:configure:error:yourt1libdistributionisnotinstalledcorrectly.请重新安装。解决方法:#sudoapt-getinstalllibt1-dev错误九:configure:error:mcrypt.hnotfound。请重新安装libmcrypt。解决方法:#sudoapt-getinstalllibmcrypt-dev错误十:configure:error:CannotfindMySQLheaderfilesunderyes。请注意,不再捆绑MySQL客户端库!解决方案:#sudoapt-getinstalllibmysql++-dev错误十一:configure:error:xslt-confignotfound。请重新安装libxslt>=1.1.0distribution解决方法:#sudoapt-getinstalllibxslt1-dev可见安装前需要PHP源码先安装这些依赖,见http://forum.ubuntu.org.cn/viewtopic.php?f=88&t=231159了解详情。以上错误全部解决后,再次./config....没有报错,#make#makeinstallif安装对应的安装包后还不行,那就继续找apt-get。如果安装安装包后没有反应,可能需要安装源码包。两种方法都可以试试,centos下的安装包和Ubuntu下的安装包名称略有不同,但是功能是一样的,将源码包中的php.ini复制到php配置文件中,这是因为php.ini配置文件我们编译安装的时候是不会生成的,需要自己复制一份。你可能会注意到在php源码包中有两个文件php.ini-production和php.ini.development。这两个文件分别代表了生产环境和开发环境使用的配置文件。在这里不用担心这些。CopyAny.cp/usr/local/src/php-5.6.28/php.ini-production/usr/local/php/etc/php.ini但是此时apache没有办法执行以PHP。为了让apache能够执行以php结尾的文件,还需要做一件事:找到apache的主配置文件/usr/local/apache/conf/httpd.conf,在AddTypeapplication/x-compress后添加两个.Z行:AddTypeapplication/x-httpd-php.phpAddTypeapplication/x-httpd-php-source.phps然后找到DirectoryIndexindex.html这一行,在index.html之前添加index.php,其中index.html和index.html酸碱度从序列可以看出,如果index.html和inde.php同时存在,则访问首页时优先选择index.php。执行serviceapacherestart,然后执行echo">/usr/local/apache/htdocs/index.php生成index.php文件,访问首页,应该可以看到php的相关信息。至此PHP和apache安装完毕,供参考https://segmentfault.com/a/11...相关书籍《Ubuntu最佳方案》同时也推荐给大家。冷刚华先生写的一本很好的书