搜索
首页后端开发php教程Ubuntu14.04下搭建LANMP环境(Apache+Nginx+MySQL+PHP)

每回安装环境都要去百度几文章,今天索性自己写一篇,以后省去百度的麻烦了,本文介绍的是在Ubuntu14.04下搭建LANMP环境(Apache+Nginx+MySQL+PHP),如果你只想安装lamp或者lnmp都通用,直接拿去。
首先分两步走:
每一、先更新系统然后安装必要的依赖(这一步为以后的扩展提供铺垫)
第二、安装mysql apache2 php

sudo apt-get updatesudo apt-get install build-essential gcc g++ autoconf libiconv-hook-dev libmcrypt-dev libxml2-dev libmysqlclient-dev libcurl4-openssl-dev libjpeg8-dev libpng12-dev libfreetype6-dev snmp mcrypt sudo apt-get install mysql-server mysql-clientsudo apt-get install apache2sudo apt-get install php5 php5-common php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-xcache php5-mcrypt

  重启apache2

sudo service apache2 restart

  ubuntu下apache2虚拟主机配置

cd /etc/apache2/sites-availablels000-default.conf  default-ssl.confsudo cp 000-default.conf 000-default.conf.baksudo vim 000-default.conf

  文件修改为以下内容

<VirtualHost *:80>     ServerAdmin webmaster@localhost    DocumentRoot /data/www     ErrorLog ${APACHE_LOG_DIR}/error.log    CustomLog ${APACHE_LOG_DIR}/access.log combined     <Directory />        Options Indexes FollowSymLinks        AllowOverride None        Require all granted    </Directory> </VirtualHost>

  重启apache2测试效果

sudo service apache2 restart

  

cd chmod 777 /data/www vim info.php <?phpphpinfo();

  在浏览器上http://localhost/info.php

ps aux | grep apache2root      3749  0.0  0.7 568604 28152 ?        Ss   10:05   0:00 /usr/sbin/apache2 -k startwww-data  3753  0.0  0.6 797128 24504 ?        S    10:05   0:00 /usr/sbin/apache2 -k startwww-data  3754  0.0  0.7 574664 30756 ?        S    10:05   0:00 /usr/sbin/apache2 -k startwww-data  3755  0.0  0.5 571040 22676 ?        S    10:05   0:00 /usr/sbin/apache2 -k startwww-data  3756  0.0  0.4 569892 18596 ?        S    10:05   0:00 /usr/sbin/apache2 -k startwww-data  3757  0.0  0.4 569884 18660 ?        S    10:05   0:00 /usr/sbin/apache2 -k startwww-data  3808  0.0  0.5 570500 21040 ?        S    10:05   0:00 /usr/sbin/apache2 -k startzzs       4187  0.0  0.0  15960   924 pts/0    S+   10:53   0:00 grep --color=auto apache2

  第三步、安装Nginx

sudo apt-get install nginxsudo apt-get install php5-fpmcd /etc/nginx/sites-availablesudo cp default default.bak

  配置Nginx使其支持PHP

cd /etc/nginx/sites-available sudo vim default

  Nginx主机配置(端口改为8080,根目录和刚才的apache2要目录一样/data/www)

server {    listen 8080 default_server; #修改端口    listen [::]:8080 default_server ipv6only=on; #修改端口     root /data/www; #修改网站根目录    index index.php index.html index.htm; #添加index.php索引文件     # Make site accessible from http://localhost/    server_name localhost;     location / {        # First attempt to serve request as file, then        # as directory, then fall back to displaying a 404.        try_files $uri $uri/ =404;        # Uncomment to enable naxsi on this location        # include /etc/nginx/naxsi.rules    }     location ~ \.php$ {        fastcgi_split_path_info ^(.+\.php)(/.+)$;        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini         # With php5-cgi alone:        #fastcgi_pass 127.0.0.1:9000;        # With php5-fpm:        fastcgi_pass unix:/var/run/php5-fpm.sock; #使用套接字方式启动        fastcgi_index index.php;        include fastcgi_params;    } }

  重启服务,查看进程

sudo service nginx restartsudo service php5-fpm restartps aux | grep php-fpmroot      3803  0.0  0.6 522716 26760 ?        Ss   10:05   0:00 php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                    www-data  3806  0.0  0.4 751104 16396 ?        S    10:05   0:00 php-fpm: pool www                                                       www-data  3807  0.0  0.2 522716  8432 ?        S    10:05   0:00 php-fpm: pool www                                                       zzs       4234  0.0  0.0  15956   924 pts/0    S+   11:06   0:00 grep --color=auto php-fpmps aux | grep nginxroot      3782  0.0  0.0  85868  1360 ?        Ss   10:05   0:00 nginx: master process /usr/sbin/nginxwww-data  3783  0.0  0.0  86164  2032 ?        S    10:05   0:00 nginx: worker processwww-data  3784  0.0  0.0  86164  2520 ?        S    10:05   0:00 nginx: worker processwww-data  3785  0.0  0.0  86164  2032 ?        S    10:05   0:00 nginx: worker processwww-data  3786  0.0  0.0  86164  1776 ?        S    10:05   0:00 nginx: worker processzzs       4236  0.0  0.0  15956   916 pts/0    S+   11:06   0:00 grep --color=auto

  

附apache2虚拟主机配置方法:

在Apache2中,有效的站点信息都存放在/etc/apache2/sites-available/文件 里面。 我们可以添加格式如下的信息来增加一个有效的虚拟空间,将default文件复制一份改一下里面的路径就可以了,要启用配置则则将此文件做一个软链接到 /etc/apache2/sites-enabled/ 目录下
下面具个例子说明:

$ cd /etc/apache2/sites-available/$ sudo cp 000-default.conf test.conf$ mkdir /data/www/logs<VirtualHost *:80>     #ServerAdmin webmaster@localhost    ServerName test.com    ServerAlias www.test.com    DocumentRoot /data/www/test     ErrorLog /data/www/logs/test-error.log    CustomLog /data/www/logs/test-access.log combined     <Directory />        Options Indexes FollowSymLinks        AllowOverride None        Require all granted    </Directory> </VirtualHost>

  添加软链接到/etc/apache2/sites-enabled目录

$ sudo ln -s /etc/apache2/sites-available/test.conf /etc/apache2/sites-enabled/test.conf

  

$ cd /etc/apache2/sites-enabled $ ls -aldrwxr-xr-x 2 root root 4096 12月 14 11:48 ./drwxr-xr-x 8 root root 4096 12月 14 00:13 ../lrwxrwxrwx 1 root root   35 12月 14 00:00 000-default.conf -> ../sites-available/000-default.conflrwxrwxrwx 1 root root   38 12月 14 11:48 test.conf -> /etc/apache2/sites-available/test.conf

  

注意:

查看fpm进程是

ps aux | grep php-fpm

  重启服务是

sudo service php5-fpm restart

  不知道为何两者名称不统一,最好用ps aux| grep fpm来查看

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
PHP电子邮件:分步发送指南PHP电子邮件:分步发送指南May 09, 2025 am 12:14 AM

phpisusedforsendendemailsduetoitsignegrationwithservermailservicesand andexternalsmtpproviders,自动化notifications andMarketingCampaigns.1)设置设置yourphpenvironcormentswironmentswithaweberswithawebserverserverserverandphp,确保themailfunctionisenabled.2)useabasicscruct

如何通过PHP发送电子邮件:示例和代码如何通过PHP发送电子邮件:示例和代码May 09, 2025 am 12:13 AM

发送电子邮件的最佳方法是使用PHPMailer库。1)使用mail()函数简单但不可靠,可能导致邮件进入垃圾邮件或无法送达。2)PHPMailer提供更好的控制和可靠性,支持HTML邮件、附件和SMTP认证。3)确保正确配置SMTP设置并使用加密(如STARTTLS或SSL/TLS)以增强安全性。4)对于大量邮件,考虑使用邮件队列系统来优化性能。

高级PHP电子邮件:自定义标题和功能高级PHP电子邮件:自定义标题和功能May 09, 2025 am 12:13 AM

CustomHeadersheadersandAdvancedFeaturesInphpeMailenHanceFunctionalityAndreliability.1)CustomHeadersheadersheadersaddmetadatatatatataatafortrackingandCategorization.2)htmlemailsallowformattingandttinganditive.3)attachmentscanmentscanmentscanbesmentscanbestmentscanbesentscanbesentingslibrarieslibrarieslibrariesliblarikelikephpmailer.4)smtppapapairatienticationaltication enterticationallimpr

使用PHP和SMTP发送电子邮件的指南使用PHP和SMTP发送电子邮件的指南May 09, 2025 am 12:06 AM

使用PHP和SMTP发送邮件可以通过PHPMailer库实现。1)安装并配置PHPMailer,2)设置SMTP服务器细节,3)定义邮件内容,4)发送邮件并处理错误。使用此方法可以确保邮件的可靠性和安全性。

使用PHP发送电子邮件的最佳方法是什么?使用PHP发送电子邮件的最佳方法是什么?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

PHP中依赖注入的最佳实践PHP中依赖注入的最佳实践May 08, 2025 am 12:21 AM

使用依赖注入(DI)的原因是它促进了代码的松耦合、可测试性和可维护性。1)使用构造函数注入依赖,2)避免使用服务定位器,3)利用依赖注入容器管理依赖,4)通过注入依赖提高测试性,5)避免过度注入依赖,6)考虑DI对性能的影响。

PHP性能调整技巧和技巧PHP性能调整技巧和技巧May 08, 2025 am 12:20 AM

phperformancetuningiscialbecapeitenhancesspeedandeffice,whatevitalforwebapplications.1)cachingwithapcureduccureducesdatabaseloadprovesrovesponsemetimes.2)优化

PHP电子邮件安全性:发送电子邮件的最佳实践PHP电子邮件安全性:发送电子邮件的最佳实践May 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。