Skip to content

Instantly share code, notes, and snippets.

@valumar
Created March 17, 2016 12:17
Show Gist options
  • Save valumar/c041ef02500e82f5eee2 to your computer and use it in GitHub Desktop.
Save valumar/c041ef02500e82f5eee2 to your computer and use it in GitHub Desktop.

Revisions

  1. @bezumkin bezumkin revised this gist Apr 28, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -99,7 +99,7 @@ php_admin_value[soap.wsdl_cache_dir] = /var/www/$USERNAME/tmp
    php_admin_value[upload_max_filesize] = 100M
    php_admin_value[post_max_size] = 100M
    php_admin_value[open_basedir] = /var/www/$USERNAME/
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client,stream_set_write_buffer,stream_socket_sendto,highlight_file,com_load_typelib
    #php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client,stream_set_write_buffer,stream_socket_sendto,highlight_file,com_load_typelib
    php_admin_value[cgi.fix_pathinfo] = 0
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[session.gc_probability] = 1
  2. @bezumkin bezumkin revised this gist Jan 5, 2014. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -37,8 +37,8 @@ chown -R $USERNAME:$USERNAME /var/www/$USERNAME/
    chown root:root /var/www/$USERNAME

    echo "Creating vhost file"
    echo "
    upstream backend-$USERNAME {server unix:/var/run/php5-$USERNAME.sock;}
    echo "upstream backend-$USERNAME {server unix:/var/run/php5-$USERNAME.sock;}
    server {
    listen 80;
    server_name $DOMAIN www.$DOMAIN;
    @@ -102,7 +102,8 @@ php_admin_value[open_basedir] = /var/www/$USERNAME/
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client,stream_set_write_buffer,stream_socket_sendto,highlight_file,com_load_typelib
    php_admin_value[cgi.fix_pathinfo] = 0
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[apc.cache_by_default] = 0
    php_admin_value[session.gc_probability] = 1
    php_admin_value[session.gc_divisor] = 100
    pm = dynamic
  3. @bezumkin bezumkin revised this gist Jul 22, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #!/bin/bash

    # MySQL root password
    ROOTPASS="password"
    TIMEZONE="Europe/Moscow"
    ROOTPASS='password'
    TIMEZONE='Europe/Moscow'

    MYSQLPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
    SFTPPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
  4. @bezumkin bezumkin revised this gist Mar 3, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -60,7 +60,7 @@ server {
    rewrite / / permanent;
    }
    location ~ ^/(.*?)/index.(html|php)$ {
    location ~ ^/(.*?)/index\.html$ {
    rewrite ^/(.*?)/ /$1/ permanent;
    }
    location @rewrite {
  5. @bezumkin bezumkin revised this gist Mar 3, 2013. 1 changed file with 12 additions and 12 deletions.
    24 changes: 12 additions & 12 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -40,18 +40,18 @@ echo "Creating vhost file"
    echo "
    upstream backend-$USERNAME {server unix:/var/run/php5-$USERNAME.sock;}
    server {
    listen 80;
    server_name $DOMAIN www.$DOMAIN;
    root /var/www/$USERNAME/www;
    access_log /var/log/nginx/$USERNAME-access.log;
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    listen 80;
    server_name $DOMAIN www.$DOMAIN;
    root /var/www/$USERNAME/www;
    access_log /var/log/nginx/$USERNAME-access.log;
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    if (\$host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    }
    location ~* ^/core/ {
    deny all;
    deny all;
    }
    location / {
    try_files \$uri \$uri/ @rewrite;
    @@ -67,9 +67,9 @@ server {
    rewrite ^/(.*)$ /index.php?q=\$1;
    }
    location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
    fastcgi_pass backend-$USERNAME;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
    fastcgi_pass backend-$USERNAME;
    }
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp)$ {
    access_log off;
  6. @bezumkin bezumkin revised this gist Mar 3, 2013. 1 changed file with 87 additions and 80 deletions.
    167 changes: 87 additions & 80 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -40,38 +40,45 @@ echo "Creating vhost file"
    echo "
    upstream backend-$USERNAME {server unix:/var/run/php5-$USERNAME.sock;}
    server {
    listen 80;
    server_name $DOMAIN www.$DOMAIN;
    root /var/www/$USERNAME/www;
    access_log /var/log/nginx/$USERNAME-access.log;
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    if (\$host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    }
    location ~* ^/core/ {
    deny all;
    }
    location / {
    try_files \$uri \$uri/ @rewrite;
    }
    location @rewrite {
    rewrite ^/(.*)$ /index.php?q=\$1;
    }
    location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
    fastcgi_pass backend-$USERNAME;
    }
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp)$ {
    access_log off;
    expires 10d;
    break;
    }
    location ~ /\.ht {
    deny all;
    }
    listen 80;
    server_name $DOMAIN www.$DOMAIN;
    root /var/www/$USERNAME/www;
    access_log /var/log/nginx/$USERNAME-access.log;
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    if (\$host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    }
    location ~* ^/core/ {
    deny all;
    }
    location / {
    try_files \$uri \$uri/ @rewrite;
    }
    location /index.html {
    rewrite / / permanent;
    }
    location ~ ^/(.*?)/index.(html|php)$ {
    rewrite ^/(.*?)/ /$1/ permanent;
    }
    location @rewrite {
    rewrite ^/(.*)$ /index.php?q=\$1;
    }
    location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
    fastcgi_pass backend-$USERNAME;
    }
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp)$ {
    access_log off;
    expires 10d;
    break;
    }
    location ~ /\.ht {
    deny all;
    }
    }
    " > /etc/nginx/sites-available/$USERNAME.conf
    ln -s /etc/nginx/sites-available/$USERNAME.conf /etc/nginx/sites-enabled/$USERNAME.conf
    @@ -92,7 +99,7 @@ php_admin_value[soap.wsdl_cache_dir] = /var/www/$USERNAME/tmp
    php_admin_value[upload_max_filesize] = 100M
    php_admin_value[post_max_size] = 100M
    php_admin_value[open_basedir] = /var/www/$USERNAME/
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client,stream_set_write_buffer,stream_socket_sendto
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client,stream_set_write_buffer,stream_socket_sendto,highlight_file,com_load_typelib
    php_admin_value[cgi.fix_pathinfo] = 0
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[apc.cache_by_default] = 0
    @@ -109,39 +116,39 @@ pm.max_spare_servers = 4

    echo "Creating config.xml"
    echo "<modx>
    <database_type>mysql</database_type>
    <database_server>localhost</database_server>
    <database>$USERNAME</database>
    <database_user>$USERNAME</database_user>
    <database_password>$MYSQLPASS</database_password>
    <database_connection_charset>utf8</database_connection_charset>
    <database_charset>utf8</database_charset>
    <database_collation>utf8_unicode_ci</database_collation>
    <table_prefix>modx_</table_prefix>
    <https_port>443</https_port>
    <http_host>$DOMAIN</http_host>
    <cache_disabled>0</cache_disabled>
    <inplace>1</inplace>
    <unpacked>0</unpacked>
    <language>ru</language>
    <cmsadmin>$USERNAME</cmsadmin>
    <cmspassword>$PASSWORD</cmspassword>
    <cmsadminemail>admin@$DOMAIN</cmsadminemail>
    <core_path>/var/www/$USERNAME/www/core/</core_path>
    <context_mgr_path>/var/www/$USERNAME/www/manager/</context_mgr_path>
    <context_mgr_url>/manager/</context_mgr_url>
    <context_connectors_path>/var/www/$USERNAME/www/connectors/</context_connectors_path>
    <context_connectors_url>/connectors/</context_connectors_url>
    <context_web_path>/var/www/$USERNAME/www/</context_web_path>
    <context_web_url>/</context_web_url>
    <remove_setup_directory>1</remove_setup_directory>
    <database_type>mysql</database_type>
    <database_server>localhost</database_server>
    <database>$USERNAME</database>
    <database_user>$USERNAME</database_user>
    <database_password>$MYSQLPASS</database_password>
    <database_connection_charset>utf8</database_connection_charset>
    <database_charset>utf8</database_charset>
    <database_collation>utf8_unicode_ci</database_collation>
    <table_prefix>modx_</table_prefix>
    <https_port>443</https_port>
    <http_host>$DOMAIN</http_host>
    <cache_disabled>0</cache_disabled>
    <inplace>1</inplace>
    <unpacked>0</unpacked>
    <language>ru</language>
    <cmsadmin>$USERNAME</cmsadmin>
    <cmspassword>$PASSWORD</cmspassword>
    <cmsadminemail>admin@$DOMAIN</cmsadminemail>
    <core_path>/var/www/$USERNAME/www/core/</core_path>
    <context_mgr_path>/var/www/$USERNAME/www/manager/</context_mgr_path>
    <context_mgr_url>/manager/</context_mgr_url>
    <context_connectors_path>/var/www/$USERNAME/www/connectors/</context_connectors_path>
    <context_connectors_url>/connectors/</context_connectors_url>
    <context_web_path>/var/www/$USERNAME/www/</context_web_path>
    <context_web_url>/</context_web_url>
    <remove_setup_directory>1</remove_setup_directory>
    </modx>" > /var/www/$USERNAME/config.xml

    #############
    @@ -175,27 +182,27 @@ sudo -u $USERNAME unzip "./modx.zip" -d ./ > /dev/null

    ZDIR=`ls -F | grep "\/" | head -1`
    if [ "${ZDIR}" = "/" ]; then
    echo "Failed to find directory..."; exit
    echo "Failed to find directory..."; exit
    fi

    if [ -d "${ZDIR}" ]; then
    cd ${ZDIR}
    echo "Moving out of temp dir..."
    sudo -u $USERNAME mv ./* ../
    cd ../
    rm -r "./${ZDIR}"
    cd ${ZDIR}
    echo "Moving out of temp dir..."
    sudo -u $USERNAME mv ./* ../
    cd ../
    rm -r "./${ZDIR}"

    echo "Removing zip file..."
    rm "./modx.zip"
    echo "Removing zip file..."
    rm "./modx.zip"

    cd "setup"
    echo "Running setup..."
    sudo -u $USERNAME php ./index.php --installmode=new --config=/var/www/$USERNAME/config.xml
    cd "setup"
    echo "Running setup..."
    sudo -u $USERNAME php ./index.php --installmode=new --config=/var/www/$USERNAME/config.xml

    echo "Done!"
    echo "Done!"
    else
    echo "Failed to find directory: ${ZDIR}"
    exit
    echo "Failed to find directory: ${ZDIR}"
    exit
    fi

    echo "#!/bin/bash
  7. @bezumkin bezumkin revised this gist Mar 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -92,7 +92,7 @@ php_admin_value[soap.wsdl_cache_dir] = /var/www/$USERNAME/tmp
    php_admin_value[upload_max_filesize] = 100M
    php_admin_value[post_max_size] = 100M
    php_admin_value[open_basedir] = /var/www/$USERNAME/
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client, stream_set_write_buffer, stream_socket_sendto
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client,stream_set_write_buffer,stream_socket_sendto
    php_admin_value[cgi.fix_pathinfo] = 0
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[apc.cache_by_default] = 0
  8. @bezumkin bezumkin revised this gist Mar 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -92,7 +92,7 @@ php_admin_value[soap.wsdl_cache_dir] = /var/www/$USERNAME/tmp
    php_admin_value[upload_max_filesize] = 100M
    php_admin_value[post_max_size] = 100M
    php_admin_value[open_basedir] = /var/www/$USERNAME/
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source,stream_socket_client, stream_set_write_buffer, stream_socket_sendto
    php_admin_value[cgi.fix_pathinfo] = 0
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[apc.cache_by_default] = 0
  9. @bezumkin bezumkin revised this gist Dec 4, 2012. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,12 @@ TIMEZONE="Europe/Moscow"

    MYSQLPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
    SFTPPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
    PASSWORD=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
    ##############

    echo "Enter username for site and database:"
    read USERNAME

    echo "Enter password"
    read PASSWORD

    echo "Enter domain"
    read DOMAIN

  10. @bezumkin bezumkin revised this gist Oct 14, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -97,6 +97,8 @@ php_admin_value[open_basedir] = /var/www/$USERNAME/
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
    php_admin_value[cgi.fix_pathinfo] = 0
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[apc.cache_by_default] = 0
    pm = dynamic
    pm.max_children = 10
  11. @bezumkin bezumkin revised this gist Oct 7, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ server {
    if (\$host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    }
    location ~* ^/(core|connectors)/ {
    location ~* ^/core/ {
    deny all;
    }
    location / {
  12. @bezumkin bezumkin revised this gist Oct 7, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ server {
    if (\$host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    }
    location /core/ {
    location ~* ^/(core|connectors)/ {
    deny all;
    }
    location / {
  13. @bezumkin bezumkin revised this gist Oct 3, 2012. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -90,6 +90,7 @@ group = $USERNAME
    chdir = /var/www/$USERNAME
    php_admin_value[upload_tmp_dir] = /var/www/$USERNAME/tmp
    php_admin_value[soap.wsdl_cache_dir] = /var/www/$USERNAME/tmp
    php_admin_value[upload_max_filesize] = 100M
    php_admin_value[post_max_size] = 100M
    php_admin_value[open_basedir] = /var/www/$USERNAME/
  14. @bezumkin bezumkin revised this gist May 13, 2012. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -209,8 +209,10 @@ find \"/var/www/$USERNAME/www\" -type f -exec chmod 0644 '{}' \;
    " > /var/www/$USERNAME/chmod
    chmod +x /var/www/$USERNAME/chmod

    echo "Done. Please visit http://$DOMAIN/manager/ to login."
    echo "Manager user: $USERNAME"
    echo "Manager password: $PASSWORD"
    echo "SFTP password: $SFTPPASS"
    echo "Mysql password: $MYSQLPASS"
    echo "Done. Please visit http://$DOMAIN/manager/ to login.
    Manager user: $USERNAME
    Manager password: $PASSWORD
    SFTP password: $SFTPPASS
    Mysql password: $MYSQLPASS" > /var/www/$USERNAME/pass.txt

    cat /var/www/$USERNAME/pass.txt
  15. @bezumkin bezumkin revised this gist May 11, 2012. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -88,10 +88,15 @@ listen.mode = 0666
    user = $USERNAME
    group = $USERNAME
    chdir = /var/www/$USERNAME
    php_admin_value[upload_tmp_dir] = /var/www/$USERNAME/tmp
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
    php_admin_value[upload_max_filesize] = 100M
    php_admin_value[post_max_size] = 100M
    php_admin_value[open_basedir] = /var/www/$USERNAME/
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
    php_admin_value[cgi.fix_pathinfo] = 0
    php_admin_value[date.timezone] = $TIMEZONE
    pm = dynamic
    pm.max_children = 10
    pm.start_servers = 2
  16. @bezumkin bezumkin revised this gist Apr 17, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -90,6 +90,8 @@ group = $USERNAME
    chdir = /var/www/$USERNAME
    php_admin_value[upload_tmp_dir] = /var/www/$USERNAME/tmp
    php_admin_value[date.timezone] = $TIMEZONE
    php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source
    php_admin_value[open_basedir] = /var/www/$USERNAME/
    pm = dynamic
    pm.max_children = 10
    pm.start_servers = 2
  17. @bezumkin bezumkin revised this gist Apr 17, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -52,8 +52,8 @@ server {
    if (\$host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    }
    location /core/ {
    deny all;
    location /core/ {
    deny all;
    }
    location / {
    try_files \$uri \$uri/ @rewrite;
  18. @bezumkin bezumkin revised this gist Apr 17, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -49,8 +49,8 @@ server {
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    if ($host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/$1 permanent;
    if (\$host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/\$1 permanent;
    }
    location /core/ {
    deny all;
  19. @bezumkin bezumkin revised this gist Apr 14, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,9 @@ server {
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    if ($host != '$DOMAIN' ) {
    rewrite ^/(.*)$ http://$DOMAIN/$1 permanent;
    }
    location /core/ {
    deny all;
    }
  20. @bezumkin bezumkin revised this gist Mar 26, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ server {
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    location ~* ^/core/(?!components) {
    location /core/ {
    deny all;
    }
    location / {
    @@ -160,7 +160,7 @@ cd /var/www/$USERNAME/www/
    echo "Getting file from modx.com..."
    sudo -u $USERNAME wget -O modx.zip http://modx.com/download/latest/
    echo "Unzipping file..."
    sudo -u $USERNAME unzip "./modx.zip" -d ./
    sudo -u $USERNAME unzip "./modx.zip" -d ./ > /dev/null

    ZDIR=`ls -F | grep "\/" | head -1`
    if [ "${ZDIR}" = "/" ]; then
  21. @bezumkin bezumkin revised this gist Mar 26, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -49,7 +49,7 @@ server {
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    location ~* /core/(?!components) {
    location ~* ^/core/(?!components) {
    deny all;
    }
    location / {
  22. @bezumkin bezumkin revised this gist Mar 26, 2012. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -49,6 +49,9 @@ server {
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    location ~* /core/(?!components) {
    deny all;
    }
    location / {
    try_files \$uri \$uri/ @rewrite;
    }
    @@ -200,4 +203,4 @@ echo "Done. Please visit http://$DOMAIN/manager/ to login."
    echo "Manager user: $USERNAME"
    echo "Manager password: $PASSWORD"
    echo "SFTP password: $SFTPPASS"
    echo "Mysql password: $MYSQLPASS"
    echo "Mysql password: $MYSQLPASS"
  23. @bezumkin bezumkin revised this gist Mar 24, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion addsite.sh
    Original file line number Diff line number Diff line change
    @@ -198,6 +198,6 @@ chmod +x /var/www/$USERNAME/chmod

    echo "Done. Please visit http://$DOMAIN/manager/ to login."
    echo "Manager user: $USERNAME"
    echo "Manger password: $PASSWORD"
    echo "Manager password: $PASSWORD"
    echo "SFTP password: $SFTPPASS"
    echo "Mysql password: $MYSQLPASS"
  24. @bezumkin bezumkin revised this gist Mar 24, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -40,7 +40,7 @@ chown root:root /var/www/$USERNAME

    echo "Creating vhost file"
    echo "
    upstream backend-$USERNAME {server unix:/var/run/php5-fpm/$USERNAME.sock;}
    upstream backend-$USERNAME {server unix:/var/run/php5-$USERNAME.sock;}
    server {
    listen 80;
    server_name $DOMAIN www.$DOMAIN;
    @@ -77,7 +77,7 @@ echo "Creating php5-fpm config"

    echo "[$USERNAME]
    listen = /var/run/php5-fpm/$USERNAME.sock
    listen = /var/run/php5-$USERNAME.sock
    listen.mode = 0666
    user = $USERNAME
    group = $USERNAME
  25. @bezumkin bezumkin revised this gist Mar 24, 2012. 1 changed file with 99 additions and 40 deletions.
    139 changes: 99 additions & 40 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,11 @@
    #!/bin/bash

    # MySQL root password
    MYSQLPASS="your-root-pass"
    ROOTPASS="password"
    TIMEZONE="Europe/Moscow"

    MYSQLPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
    SFTPPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
    ##############

    echo "Enter username for site and database:"
    @@ -17,36 +20,76 @@ read DOMAIN
    ##############

    echo "Creating user and home directory..."
    useradd -m $USERNAME
    useradd $USERNAME -m -G sftp -s "/bin/false" -d "/var/www/$USERNAME"
    if [ "$?" -ne 0 ]; then
    echo "Can't add user"
    exit 1
    fi
    echo $SFTPPASS > ./tmp
    echo $SFTPPASS >> ./tmp
    cat ./tmp | passwd $USERNAME
    rm ./tmp

    ##############

    mkdir /home/$USERNAME/htdocs
    mkdir /home/$USERNAME/logs
    chmod -R 750 /home/$USERNAME/
    chown -R $USERNAME:$USERNAME /home/$USERNAME/htdocs/
    mkdir /var/www/$USERNAME/www
    mkdir /var/www/$USERNAME/tmp
    chmod -R 755 /var/www/$USERNAME/
    chown -R $USERNAME:$USERNAME /var/www/$USERNAME/
    chown root:root /var/www/$USERNAME

    echo "Creating vhost file"
    echo "
    <VirtualHost *:80>
    ServerName $DOMAIN
    ServerAlias www.$DOMAIN
    ServerAdmin webmaster@$DOMAIN
    DirectoryIndex index.html index.php
    DocumentRoot /home/$USERNAME/htdocs/
    <Directory /home/$USERNAME/htdocs/>
    Options Indexes FollowSymLinks -MultiViews
    AllowOverride All
    </Directory>
    ErrorLog /home/$USERNAME/logs/error.log
    CustomLog /home/$USERNAME/logs/access.log combined
    AssignUserId $USERNAME $USERNAME
    </VirtualHost>
    " > /etc/apache2/sites-enabled/$USERNAME.conf
    upstream backend-$USERNAME {server unix:/var/run/php5-fpm/$USERNAME.sock;}
    server {
    listen 80;
    server_name $DOMAIN www.$DOMAIN;
    root /var/www/$USERNAME/www;
    access_log /var/log/nginx/$USERNAME-access.log;
    error_log /var/log/nginx/$USERNAME-error.log;
    index index.php index.html;
    rewrite_log on;
    location / {
    try_files \$uri \$uri/ @rewrite;
    }
    location @rewrite {
    rewrite ^/(.*)$ /index.php?q=\$1;
    }
    location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
    fastcgi_pass backend-$USERNAME;
    }
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp)$ {
    access_log off;
    expires 10d;
    break;
    }
    location ~ /\.ht {
    deny all;
    }
    }
    " > /etc/nginx/sites-available/$USERNAME.conf
    ln -s /etc/nginx/sites-available/$USERNAME.conf /etc/nginx/sites-enabled/$USERNAME.conf

    ##############
    echo "Creating php5-fpm config"

    echo "[$USERNAME]
    listen = /var/run/php5-fpm/$USERNAME.sock
    listen.mode = 0666
    user = $USERNAME
    group = $USERNAME
    chdir = /var/www/$USERNAME
    php_admin_value[upload_tmp_dir] = /var/www/$USERNAME/tmp
    php_admin_value[date.timezone] = $TIMEZONE
    pm = dynamic
    pm.max_children = 10
    pm.start_servers = 2
    pm.min_spare_servers = 2
    pm.max_spare_servers = 4
    " > /etc/php5/fpm/pool.d/$USERNAME.conf

    ##############

    @@ -56,10 +99,10 @@ echo "<modx>
    <database_server>localhost</database_server>
    <database>$USERNAME</database>
    <database_user>$USERNAME</database_user>
    <database_password>$PASSWORD</database_password>
    <database_password>$MYSQLPASS</database_password>
    <database_connection_charset>utf8</database_connection_charset>
    <database_charset>utf8</database_charset>
    <database_collation>utf8_general_ci</database_collation>
    <database_collation>utf8_unicode_ci</database_collation>
    <table_prefix>modx_</table_prefix>
    <https_port>443</https_port>
    <http_host>$DOMAIN</http_host>
    @@ -69,45 +112,47 @@ echo "<modx>
    <unpacked>0</unpacked>
    <language>en</language>
    <language>ru</language>
    <cmsadmin>$USERNAME</cmsadmin>
    <cmspassword>$PASSWORD</cmspassword>
    <cmsadminemail>webmaster@$DOMAIN</cmsadminemail>
    <cmsadminemail>admin@$DOMAIN</cmsadminemail>
    <core_path>/home/$USERNAME/htdocs/core/</core_path>
    <core_path>/var/www/$USERNAME/www/core/</core_path>
    <context_mgr_path>/home/$USERNAME/htdocs/manager/</context_mgr_path>
    <context_mgr_path>/var/www/$USERNAME/www/manager/</context_mgr_path>
    <context_mgr_url>/manager/</context_mgr_url>
    <context_connectors_path>/home/$USERNAME/htdocs/connectors/</context_connectors_path>
    <context_connectors_path>/var/www/$USERNAME/www/connectors/</context_connectors_path>
    <context_connectors_url>/connectors/</context_connectors_url>
    <context_web_path>/home/$USERNAME/htdocs/</context_web_path>
    <context_web_path>/var/www/$USERNAME/www/</context_web_path>
    <context_web_url>/</context_web_url>
    <remove_setup_directory>1</remove_setup_directory>
    </modx>" > /home/$USERNAME/config.xml
    </modx>" > /var/www/$USERNAME/config.xml

    #############

    echo "Reloading apache"
    /etc/init.d/apache2 reload
    echo "Reloading nginx"
    service nginx reload
    echo "Reloading php5-fpm"
    service php5-fpm reload

    ##############

    echo "Creating database"

    Q1="CREATE DATABASE IF NOT EXISTS $USERNAME;"
    Q2="GRANT ALTER,DELETE,DROP,CREATE,INDEX,INSERT,SELECT,UPDATE,CREATE TEMPORARY TABLES,LOCK TABLES ON $USERNAME.* TO '$USERNAME'@'localhost' IDENTIFIED BY '$PASSWORD';"
    Q1="CREATE DATABASE IF NOT EXISTS $USERNAME DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;;"
    Q2="GRANT ALTER,DELETE,DROP,CREATE,INDEX,INSERT,SELECT,UPDATE,CREATE TEMPORARY TABLES,LOCK TABLES ON $USERNAME.* TO '$USERNAME'@'localhost' IDENTIFIED BY '$MYSQLPASS';"
    Q3="FLUSH PRIVILEGES;"
    SQL="${Q1}${Q2}${Q3}"

    mysql -uroot --password=$MYSQLPASS -e "$SQL"
    mysql -uroot --password=$ROOTPASS -e "$SQL"

    ##############

    echo "Installing MODx"

    cd /home/$USERNAME/htdocs/
    cd /var/www/$USERNAME/www/

    echo "Getting file from modx.com..."
    sudo -u $USERNAME wget -O modx.zip http://modx.com/download/latest/
    @@ -131,14 +176,28 @@ if [ -d "${ZDIR}" ]; then

    cd "setup"
    echo "Running setup..."
    sudo -u $USERNAME php ./index.php --installmode=new --config=/home/$USERNAME/config.xml
    sudo -u $USERNAME php ./index.php --installmode=new --config=/var/www/$USERNAME/config.xml

    echo "Done!"
    else
    echo "Failed to find directory: ${ZDIR}"
    exit
    fi

    echo "Done. Please visit http://$DOMAIN/manager to login."
    echo "User: $USERNAME"
    echo "Password: $PASSWORD"
    echo "#!/bin/bash
    echo \"Set permissions for /var/www/$USERNAME/www...\";
    echo \"CHOWN files...\";
    chown -R $USERNAME:$USERNAME \"/var/www/$USERNAME/www\";
    echo \"CHMOD directories...\";
    find \"/var/www/$USERNAME/www\" -type d -exec chmod 0755 '{}' \;
    echo \"CHMOD files...\";
    find \"/var/www/$USERNAME/www\" -type f -exec chmod 0644 '{}' \;
    " > /var/www/$USERNAME/chmod
    chmod +x /var/www/$USERNAME/chmod

    echo "Done. Please visit http://$DOMAIN/manager/ to login."
    echo "Manager user: $USERNAME"
    echo "Manger password: $PASSWORD"
    echo "SFTP password: $SFTPPASS"
    echo "Mysql password: $MYSQLPASS"
  26. @invalid-email-address Anonymous created this gist Feb 7, 2012.
    144 changes: 144 additions & 0 deletions addsite.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,144 @@
    #!/bin/bash

    # MySQL root password
    MYSQLPASS="your-root-pass"

    ##############

    echo "Enter username for site and database:"
    read USERNAME

    echo "Enter password"
    read PASSWORD

    echo "Enter domain"
    read DOMAIN

    ##############

    echo "Creating user and home directory..."
    useradd -m $USERNAME
    if [ "$?" -ne 0 ]; then
    echo "Can't add user"
    exit 1
    fi

    ##############

    mkdir /home/$USERNAME/htdocs
    mkdir /home/$USERNAME/logs
    chmod -R 750 /home/$USERNAME/
    chown -R $USERNAME:$USERNAME /home/$USERNAME/htdocs/

    echo "Creating vhost file"
    echo "
    <VirtualHost *:80>
    ServerName $DOMAIN
    ServerAlias www.$DOMAIN
    ServerAdmin webmaster@$DOMAIN
    DirectoryIndex index.html index.php
    DocumentRoot /home/$USERNAME/htdocs/
    <Directory /home/$USERNAME/htdocs/>
    Options Indexes FollowSymLinks -MultiViews
    AllowOverride All
    </Directory>
    ErrorLog /home/$USERNAME/logs/error.log
    CustomLog /home/$USERNAME/logs/access.log combined
    AssignUserId $USERNAME $USERNAME
    </VirtualHost>
    " > /etc/apache2/sites-enabled/$USERNAME.conf

    ##############

    echo "Creating config.xml"
    echo "<modx>
    <database_type>mysql</database_type>
    <database_server>localhost</database_server>
    <database>$USERNAME</database>
    <database_user>$USERNAME</database_user>
    <database_password>$PASSWORD</database_password>
    <database_connection_charset>utf8</database_connection_charset>
    <database_charset>utf8</database_charset>
    <database_collation>utf8_general_ci</database_collation>
    <table_prefix>modx_</table_prefix>
    <https_port>443</https_port>
    <http_host>$DOMAIN</http_host>
    <cache_disabled>0</cache_disabled>
    <inplace>1</inplace>
    <unpacked>0</unpacked>
    <language>en</language>
    <cmsadmin>$USERNAME</cmsadmin>
    <cmspassword>$PASSWORD</cmspassword>
    <cmsadminemail>webmaster@$DOMAIN</cmsadminemail>
    <core_path>/home/$USERNAME/htdocs/core/</core_path>
    <context_mgr_path>/home/$USERNAME/htdocs/manager/</context_mgr_path>
    <context_mgr_url>/manager/</context_mgr_url>
    <context_connectors_path>/home/$USERNAME/htdocs/connectors/</context_connectors_path>
    <context_connectors_url>/connectors/</context_connectors_url>
    <context_web_path>/home/$USERNAME/htdocs/</context_web_path>
    <context_web_url>/</context_web_url>
    <remove_setup_directory>1</remove_setup_directory>
    </modx>" > /home/$USERNAME/config.xml

    #############

    echo "Reloading apache"
    /etc/init.d/apache2 reload

    ##############

    echo "Creating database"

    Q1="CREATE DATABASE IF NOT EXISTS $USERNAME;"
    Q2="GRANT ALTER,DELETE,DROP,CREATE,INDEX,INSERT,SELECT,UPDATE,CREATE TEMPORARY TABLES,LOCK TABLES ON $USERNAME.* TO '$USERNAME'@'localhost' IDENTIFIED BY '$PASSWORD';"
    Q3="FLUSH PRIVILEGES;"
    SQL="${Q1}${Q2}${Q3}"

    mysql -uroot --password=$MYSQLPASS -e "$SQL"

    ##############

    echo "Installing MODx"

    cd /home/$USERNAME/htdocs/

    echo "Getting file from modx.com..."
    sudo -u $USERNAME wget -O modx.zip http://modx.com/download/latest/
    echo "Unzipping file..."
    sudo -u $USERNAME unzip "./modx.zip" -d ./

    ZDIR=`ls -F | grep "\/" | head -1`
    if [ "${ZDIR}" = "/" ]; then
    echo "Failed to find directory..."; exit
    fi

    if [ -d "${ZDIR}" ]; then
    cd ${ZDIR}
    echo "Moving out of temp dir..."
    sudo -u $USERNAME mv ./* ../
    cd ../
    rm -r "./${ZDIR}"

    echo "Removing zip file..."
    rm "./modx.zip"

    cd "setup"
    echo "Running setup..."
    sudo -u $USERNAME php ./index.php --installmode=new --config=/home/$USERNAME/config.xml

    echo "Done!"
    else
    echo "Failed to find directory: ${ZDIR}"
    exit
    fi

    echo "Done. Please visit http://$DOMAIN/manager to login."
    echo "User: $USERNAME"
    echo "Password: $PASSWORD"