ubuntu下搭建LNMP开发环境
Nginx
先安装以下依赖:
sudo apt-get install build-essential sudo apt-get install libtool sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install zlib1g-dev sudo apt-get install openssl
下载nginx软件包
wget http://nginx.org/download/nginx-1.15.7.tar.gz
安装nginx
./configure --prefix=/usr/local/nginx make make install
添加nginx软链接
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
添加www用户
groupadd www useradd -M -g www -s /sbin/nologin www
添加开机自启动服务
vi /lib/systemd/system/nginx.service
加上以下内容
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
设置开机自启动
systemctl enable nginx.service
Mysql
直接使用apt安装mysql-server
apt-get install mysql-server
安装完成之后可以使用如下命令来检查是否安装成功:
netstat -tap | grep mysql
查看mysql的安装包情况
dpkg -l | grep mysql
mysql初始化
sudo mysql_secure_installation
开放远程登录
vi /etc/mysql/mysql.conf.d/mysqld.cnf
将其中的
bind-address = 127.0.0.1
注释掉,然后重启mysql服务
service mysql restart
PHP
安装依赖
apt-get install gcc make openssl curl libbz2-dev libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev libssl-dev
下载php
wget http://mirrors.sohu.com/php/php-7.3.9.tar.gz
编译安装php
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-ftp --with-gd --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-fileinfo --enable-maintainer-zts make && make install
如果碰到以下报错:
checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
安装libcurl4-openssl-dev即可
apt-get install libcurl4-openssl-dev
Composer
cd /usr/local/src/ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php php -r "unlink('composer-setup.php');" mv composer.phar /usr/local/bin/composer
Node与npm
wget https://nodejs.org/download/release/v4.4.7/node-v4.4.7-linux-x64.tar.gz tar -zxf node-v4.4.7-linux-x64.tar.gz mv ./node-v4.4.7-linux-x64 /usr/local/node ln -s /usr/local/node/bin/node /usr/local/bin/ ln -s /usr/local/node/bin/npm /usr/local/bin/ npm -g install npm@3.9.5 npm install --global gulp ln -s /usr/local/node/bin/gulp /usr/local/bin/
yarn
apt-get update apt-get upgrade curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list apt-get update apt-get install yarn yarn --version
Redis
apt-get install redis-server
查看tcp 连接
netstat -ap | grep 6379
配置远程访问
vi /etc/redis/redis.conf
将protected-mode改为no,将bind 127.0.0.1 ::1注释掉