PHP Composer

Install

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
$ composer global require "fxp/composer-asset-plugin:dev-master"
$ composer update --prefer-dist --optimize-autoloader
$ composer self-update

PHP-FPM

listen = /tmp/php-fpm.socket
listen.owner = nginx
listen.group = nginx
listen.mode = 0666
user = nginx
group = nginx
php_admin_value[display_errors] = on
php_admin_value[log_errors] = off
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
php_value[date.timezone] = UTC
php_value[error_reporting] = E_ALL
php_value[post_max_size] = 64M
php_value[upload_max_filesize] = 64M
php_value[short_open_tag] = on

MySQL

After installation

# for OS X
$ mysql_install_db --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir="/var/mysql" --tmpdir="/tmp"
# for others
$ mysql_install_db --basedir="/usr/local/mysql" --datadir="/var/mysql" --tmpdir="/tmp"
# initialization
$ mysql_secure_installation

Set root password in terminal

$ /usr/local/mysql/bin/mysqladmin -u root password 123456

Import

$ mysql --host=localhost --user=root --password=PASSWORD "DATABASE" < ~/db.sql

Export

$ mysqldump --host=localhost --user=root --password=PASSWORD --add-locks --add-drop-table --lock-tables "DATABASE" > ~/db.sql

MongoDB

Export

$ mongodump -h localhost -p 27017 -u user -p pass -d dbname -o /tmp

nginx

Configuration

user nginx nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {

    include mime.types;
    default_type application/octet-stream;
    client_max_body_size 20M;
    gzip on;
    sendfile on;

    index index.html index.php;

    server {

        listen 80;
        listen 443 ssl;
        server_name ychong.com www.ychong.com;
        root /var/www/html/ychong_com;
        fastcgi_param PHP_VALUE "open_basedir=$document_root:/tmp/";
        autoindex on;

        if ( $ssl_protocol = "" ) {
            return 301 https://$host$request_uri;
        }

        ssl_certificate ssl/self-signed/self-signed.crt;
        ssl_certificate_key ssl/self-signed/self-signed.key;

        location / {
            if ( !-e $request_filename ) {
                rewrite (.*) /index.php;
            }
        }

        location /phpmyadmin {
            root /usr/local/share;
            location ~ ^/phpmyadmin/(.+\.php)$ {
                include fastcgi_params;
                fastcgi_pass unix:/tmp/php-fpm.socket;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
        }

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/tmp/php-fpm.socket;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~ /\.ht {
            deny all;
        }

    }

}

Apache

Virtual Host

<Directory "/home/ychong/public_html/">
    Options -Indexes +FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<VirtualHost *:80>
    ServerName example.com
    ServerAlias *.example.com
    ServerAdmin webmaster@example.com
    DocumentRoot "/home/ychong/public_html/example.com/web/"
    <Directory "/home/ychong/public_html/example.com/web/">
        DirectoryIndex index.html index.php
        Options -Indexes +FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
    php_admin_value open_basedir "/tmp/:/home/ychong/public_html/example.com/"
    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/error_example_com.log
    CustomLog ${APACHE_LOG_DIR}/access_example_com.log combined
</VirtualHost>

<VirtualHost *:443>
    ServerName example.com
    ServerAlias *.example.com
    ServerAdmin webmaster@example.com
    DocumentRoot "/home/ychong/public_html/example.com/web/"
    <Directory "/home/ychong/public_html/example.com/web/">
        DirectoryIndex index.html index.php
        Options -Indexes +FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
    php_admin_value open_basedir "/tmp/:/home/ychong/public_html/example.com/"
    SSLEngine on
    SSLCertificateFile      /etc/apache2/ssl/example_com/example_com.crt
    SSLCertificateKeyFile   /etc/apache2/ssl/example_com/server.key
    SSLCertificateChainFile /etc/apache2/ssl/example_com/example_com.cer
    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/error_example_com_ssl.log
    CustomLog ${APACHE_LOG_DIR}/access_example_com_ssl.log combined
</VirtualHost>

Apache HTTP documents permissions

设置文件权限

1. 将 www 组添加到您的实例。

$ sudo groupadd www

2. 将您的用户(这里指 ubuntu)添加到 www。

$ sudo usermod -a -G www ubuntu

Important 您必须先退出,再重新登录,然后才能接受新组。您可以使用 exit 命令,也可以关闭终端窗口。

3. 先退出,再重新登录,然后验证您是否为 www 组的成员。

a. 退出。

$ exit

b. 重新连接到实例,然后运行以下命令,以验证您是否为 www 组的成员。

$ groups
ubuntu wheel www

4. 将 /home/ubuntu/public_html 及其内容的组所有权更改到 www 组。

$ sudo chown -R root:www /home/ubuntu/public_html

5. 更改 /home/ubuntu/public_html 及其子目录的目录权限,以添加组写入权限及设置未来子目录上的组 ID。

$ sudo chmod 2775 /home/ubuntu/public_html
$ find /home/ubuntu/public_html -type d -exec sudo chmod 2775 {} +

6. 递归地更改 /home/ubuntu/public_html 及其子目录的文件权限,以添加组写入权限。

$ find /home/ubuntu/public_html -type f -exec sudo chmod 0664 {} +

现在,ubuntu(以及 www 组的任何未来成员)可以在 Apache 根目录中添加、删除和编辑文件。现在您已准备好添加内容,例如静态网站或 PHP 应用程序。

phpmyadmin

Manual configuration

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['username'] = 'username';
$cfg['Servers'][$i]['password'] = 'password';