markdown Ubuntu 16.04:LAMP w / NodeJS和WP-CLI

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Ubuntu 16.04:LAMP w / NodeJS和WP-CLI相关的知识,希望对你有一定的参考价值。

# Ubuntu 16.04 LAMP w/ NodeJS & WP-CLI

## Setup LAMP stack

### Apache

```txt
apt-get update
apt-get install apache2
```

`nano /etc/apache2/mods-enabled/dir.conf`

-   Add `index.php` to beginning of `DirectoryIndex` list (remove from place in
  list further down)

`a2enmod rewrite headers expires`

`nano /etc/apache2/apache2.conf`

-   Change ` AllowOverride None` to ` AllowOverride All` within `<Directory
/var/www/>` block

`service apache2 restart`

### PHP

```txt
apt-get install php libapache2-mod-php php-mcrypt php-mysql -y
apt-get install php-cgi php-cli php-common php-curl php-gd -y
```

### MySQL

`apt-get install mysql-server`

`mysql_secure_installation`

-   n
-   n
-   y
-   y
-   y
-   y

#### Accessing remote MySQL databases

`ssh www-data@SERVER_IP_ADDRESS -L 42001:localhost:3306`

-   3306 is default mysql port

-   42001 is a free (unless you are running something else on this port, highly
unlikely!)

-   allows local access to remote mysql server for easier creation of db's and
users

### NodeJS

```txt
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
apt-get install -y nodejs
```

### Install Yarn

Follow the instructions on the [Yarn website](https://yarnpkg.com/en/docs/install#linux-tab)
to install yarn onto the server.

### Git

`apt-get install git`

## Adding sites to Apache

Note: `tld` means `Top-Level Domain` i.e. `.com, .co.uk, .io` etc, make sure to replace `.tld` with your 
domain's TLD extension

`cd /etc/apache2/sites-available/`

-   if creating one site on box:

```txt
cp 000-default.conf my-site.domain.tld.conf
nano my-site.domain.tld.conf
```

```txt
ServerName my-site.domain.tld
ServerAdmin harry@harryfinn.co.uk
DocumentRoot /var/www/html/
```

```txt
a2dissite 000-default.conf
a2ensite my-site.domain.tld.conf
```

-   if creating multiple (i.e. staging and qa):

```txt
cp 000-default.conf my-site-staging.domain.tld.conf
nano my-site-staging.domain.tld.conf
```

```txt
ServerName my-site-staging.domain.tld
ServerAdmin harry@harryfinn.co.uk
DocumentRoot /var/www/html/staging
```

```txt
cp 000-default.conf my-site-qa.domain.tld.conf
nano my-site-qa.domain.tld.conf
```

```txt
ServerName my-site-qa.domain.tld
ServerAdmin harry@harryfinn.co.uk
DocumentRoot /var/www/html/qa
```

```txt
a2dissite 000-default.conf
a2ensite my-site-staging.domain.tld.conf my-site-qa.domain.tld.conf
```

-   Ensure directories specified above (each `DocumentRoot` path) are created by www-data user, 
once this user is setup using the instructions below.

## Setting up www-data user

`nano /etc/passwd`

-   `www-data:x:33:33:www-data:/var/www:/bin/bash`

`passwd www-data`

-   Enter www-data user password

`chown -R www-data:www-data /var/www`

## Preventing root user from ssh'ing onto server

(As root user)

`nano /etc/ssh/sshd_config`

-   Change `PermitRootLogin yes` to `PermitRootLogin no`

`service ssh restart`

Disconnect from server and try `root` user ssh, will be given `permission denied` message. 
Use `www-data` user the `su` to swap to the `root` user when required.

## Installing WP-CLI

```txt
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
```

`su`

-   swap to root in order to move wp-cli

`mv wp-cli.phar /usr/local/bin/wp`

`exit`

-   swap back to www-data

## Update server hostname to FQDN

-   Run `hostname` to see what the currently set hostname is set to
-   Run `hostnamectl set-hostname mysite.com` to change the hostname (permanently, otherwise will reset on reboot)
-   Note: Important that this step is performed before setting you your mail server!

## Setting up mail-out only (loopback) emails from server

`apt-get install mailutils`

-   Set mail configuration type to `Internet Site`
-   Set system mail name to FQDN i.e. `mysite.com`, ensure you *DO NOT* add any subdomains in front i.e. `www.` as this will invalidate the mail record
-   As root:
-  `nano /etc/postfix/main.cf` and change `inet_interfaces` to:

```txt
inet_interfaces = loopback-only
```

-   Then change `mydestination` to:

```txt
mydestination = localhost.$mydomain, $mydomain
```

-   Finally, restart postfix (mail sending service) `service postfix restart`
-   To check that the server is sending out emails correctly you can run the following command:

```txt
echo "This is the body of the email" | mail -s "This is the subject line" my_email@emailaddress.com
```

以上是关于markdown Ubuntu 16.04:LAMP w / NodeJS和WP-CLI的主要内容,如果未能解决你的问题,请参考以下文章

markdown Ubuntu 16.04配置

markdown Ubuntu 16.04安装Java8

markdown Ubuntu16.04 + 1080下配置Tensorflow

markdown 如何在ubuntu 16.04上安装虚拟环境

markdown Ubuntu 16.04安装x11vnc

markdown ubuntu16.04修改配置文件禁止系统自动更新