ubuntu手动搭建lnmp开发环境

2 篇文章 0 订阅

安装nginx:

已经安装了Apache2的话,那么使用这些命令先删除再安装nginx:

    service apache2 stop
    update-rc.d -f apache2 remove
    apt-get remove apache2
Ubuntu16.04有Nginx安装包,我们可以安装。
  apt-get -y install nginx
    service nginx start
在Ubuntu16.04的默认nginx的文档根目录为/var/www/html

安装php7:

    apt-get -y install php7.0-fpm

配置nginx:

打开配置文件 /etc/nginx/nginx.conf
首先(这是可选)调整keepalive_timeout到一个合理的值:
    [...]
        keepalive_timeout   2;
    [...]
打开容器定义 /etc/nginx/sites-available/default
更改如下:

“`
server {
listen 80 default_server;
listen [::]:80 default_server;

 # SSL configuration
 #
 # listen 443 ssl default_server;
 # listen [::]:443 ssl default_server;
 #
 # Note: You should disable gzip for SSL traffic.
 # See: https://bugs.debian.org/773332
 #
 # Read up on ssl_ciphers to ensure a secure configuration.
 # See: https://bugs.debian.org/765782
 #
 # Self signed certs generated by the ssl-cert package
 # Don't use them in a production server!
 #
 # include snippets/snakeoil.conf;

 root /var/www/html;

 # Add index.php to the list if you are using PHP
 index index.html index.htm index.nginx-debian.html;

 server_name _;

 location / {
 # First attempt to serve request as file, then
 # as directory, then fall back to displaying a 404.
 try_files $uri $uri/ =404;
 }

 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ \.php$ {
 include snippets/fastcgi-php.conf;

 # With php7.0-cgi alone:
 # fastcgi_pass 127.0.0.1:9000;
 # With php7.0-fpm:
 fastcgi_pass unix:/run/php/php7.0-fpm.sock;
 }

 # deny access to .htaccess files, if Apache's document root
 # concurs with nginx's one
 #
 location ~ /\.ht {
  deny all;
 }
}
    server_name:使这是一个默认捕捉所有虚拟主机(当然,你可以同时喜欢这里www.example.com指定主机名)。

    根目录 /var/www/html;意味着文档根目录/var/www/html.

    PHP的重要组成部分位置 ~ \.php$ {} stanza. 取消注释它来启用它。

    现在保存文件并重新加载nginx:
service nginx reload
    打开配置文件: /etc/php/7.0/fpm/php.ini
  ```
    [...]
    ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
    ; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
    ; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
    ; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
    ; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts
    ; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
    ; http://php.net/cgi.fix-pathinfo
    cgi.fix_pathinfo=0
    [...]
  ```
    重启php7:service php7.0-fpm reload

# 安装mysql:

    安装 MySQL 运行命令:
apt-get -y install mysql-server mysql-client
    你会被要求提供MySQL的root用户密码 :

    设置mysql安全:
    mysql_secure_installation

    让 MySQL 获得 PHP 7支持

    先搜索一下PHP支持的模块:

    apt-cache search php7.0

    使用下面的命令安装:
apt-get -y install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache  php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext
    APCu是随PHP7 PHP Opcache模块的扩展,它增加了一些兼容性功能的支持APC缓存(例如WordPress的插件缓存)软件。

    APCu可以安装如下:

    apt-get -y install php-apcu

    重新加载 PHP-FPM:

    service php7.0-fpm reload


# 卸载mysql

sudo deluser mysql
sudo delgroup mysql

sudo service mysql stop #or mysqld
sudo killall -9 mysql
sudo killall -9 mysqld
sudo apt-get remove –purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo deluser mysql
sudo rm -rf /var/lib/mysql
sudo apt-get purge mysql-server-core-5.5
sudo apt-get purge mysql-client-core-5.5
sudo rm -rf /var/log/mysql
sudo rm -rf /etc/mysql
“`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值