This repository was archived by the owner on Mar 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Enhancements for php5-fpm, mysql, etc #3
Open
intel352
wants to merge
5
commits into
StanAngeloff:master
Choose a base branch
from
intel352:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5748e39
Added apt upgrade, modified php-fpm config and fixed issue with php5-…
intel352 c7e3ce2
Fixing issue with package not being found due to update not having ru…
intel352 b9b6e03
Updating to support php-fpm with apache
intel352 0b6dcbb
Update LICENSE.md
480b2d5
Update LICENSE.md
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,10 +74,8 @@ apt-packages-repository() { | |
|
|
||
| # Add a Launchpad PPA as a software source. | ||
| apt-packages-ppa() { | ||
| apt-packages-repository \ | ||
| "deb http://ppa.launchpad.net/$1/ubuntu lucid main" \ | ||
| "deb-src http://ppa.launchpad.net/$1/ubuntu lucid main" \ | ||
| "$2" "$3" | ||
| which 'add-apt-repository' >/dev/null || (apt-packages-update; apt-packages-install 'python-software-properties') | ||
| add-apt-repository "$1" | ||
| } | ||
|
|
||
| # Perform a non-interactive `apt-get` command. | ||
|
|
@@ -98,6 +96,11 @@ apt-packages-update() { | |
| apt-non-interactive update | ||
| } | ||
|
|
||
| # Upgrade `aptitude` packages without any prompts. | ||
| apt-packages-upgrade() { | ||
| apt-non-interactive upgrade | ||
| } | ||
|
|
||
| # Perform an unattended installation of package(s). | ||
| apt-packages-install() { | ||
| apt-non-interactive install "$@" | ||
|
|
@@ -217,37 +220,21 @@ apache-sites-create() { | |
| local apache_site_user | ||
| local apache_site_group | ||
| local apache_site_config | ||
| local cgi_action | ||
| local cgi_apache_path | ||
| local cgi_system_path | ||
| local code_block | ||
| apache_site_name="$1" | ||
| apache_site_path="${2:-/$apache_site_name}" | ||
| apache_site_user="${3:-$apache_site_name}" | ||
| apache_site_group="${4:-$apache_site_user}" | ||
| apache_site_config="/etc/apache2/sites-available/$apache_site_name" | ||
| cgi_apache_path="/cgi-bin/" | ||
| cgi_system_path="$apache_site_path/.cgi-bin/" | ||
| # Create the /.cgi-bin/ directory and set permissions for SuExec. | ||
| $SUDO mkdir -p "$cgi_system_path" | ||
| $SUDO chmod 0755 "$cgi_system_path" | ||
| # Define a new virtual host with mod_fastcgi configured to use SuExec. | ||
| # Define a new virtual host | ||
| code_block=$( cat <<-EOD | ||
| <IfModule mod_fastcgi.c> | ||
| FastCgiWrapper /usr/lib/apache2/suexec | ||
| FastCgiConfig -pass-header HTTP_AUTHORIZATION -autoUpdate -killInterval 120 -idle-timeout 30 | ||
| </IfModule> | ||
|
|
||
| <VirtualHost *:80> | ||
| DocumentRoot ${apache_site_path} | ||
|
|
||
| LogLevel debug | ||
| ErrorLog /var/log/apache2/error.${apache_site_name}.log | ||
| CustomLog /var/log/apache2/access.${apache_site_name}.log combined | ||
|
|
||
| SuexecUserGroup ${apache_site_user} ${apache_site_group} | ||
| ScriptAlias ${cgi_apache_path} ${cgi_system_path} | ||
|
|
||
| # Do not use kernel sendfile to deliver files to the client. | ||
| EnableSendfile Off | ||
|
|
||
|
|
@@ -262,30 +249,29 @@ EOD | |
| cgi_action="php-fcgi" | ||
| code_block=$( cat <<-EOD | ||
| ${code_block} | ||
|
|
||
| <IfModule mod_fastcgi.c> | ||
| <Location ${cgi_apache_path}${cgi_action}> | ||
| SetHandler fastcgi-script | ||
| Options +ExecCGI +FollowSymLinks | ||
| Order Allow,Deny | ||
| Allow from all | ||
| <FilesMatch \.php$> | ||
| SetHandler php5-fcgi | ||
| </FilesMatch> | ||
| <Location "/fastcgiphp"> | ||
| Order Deny,Allow | ||
| Deny from All | ||
| # Prevent accessing this path directly | ||
| Allow from env=REDIRECT_STATUS | ||
| </Location> | ||
| AddHandler ${cgi_action} .php | ||
| Action ${cgi_action} ${cgi_apache_path}${cgi_action} | ||
| Action php5-fcgi /fastcgiphp | ||
| Alias /fastcgiphp /usr/local/bin/${apache_site_name}.fpm_external | ||
| FastCgiExternalServer /usr/local/bin/${apache_site_name}.fpm_external -socket /var/run/php5-fpm-${apache_site_name}.sock -pass-header Authorization | ||
| </IfModule> | ||
| EOD | ||
| ) | ||
| $SUDO cat > "$cgi_system_path$cgi_action" <<-EOD | ||
| #!/bin/bash | ||
|
|
||
| export PHP_FCGI_CHILDREN=4 | ||
| export PHP_FCGI_MAX_REQUESTS=200 | ||
|
|
||
| export PHPRC="${cgi_system_path}php.ini" | ||
|
|
||
| exec ${PHP} | ||
| EOD | ||
| $SUDO chmod 0755 "$cgi_system_path$cgi_action" | ||
| # Run PHP-FPM as the selected user and group. | ||
| $SUDO sed \ | ||
| -e 's#^\(\[[A-Za-z0-9-]\+\]\)$#['"$apache_site_name"']#g' \ | ||
| -e 's#^\(user\)\s*=\s*[A-Za-z0-9-]\+#\1 = '"$apache_site_user"'#g' \ | ||
| -e 's#^\(group\)\s*=\s*[A-Za-z0-9-]\+#\1 = '"$apache_site_group"'#g' \ | ||
| -e 's#^\(listen\)\s*=\s*.\+$#\1 = '/var/run/php5-fpm-"$apache_site_name"'.sock#g' \ | ||
| <'/etc/php5/fpm/pool.d/www.conf' >'/etc/php5/fpm/pool.d/'"$apache_site_name"'.conf' | ||
| fi | ||
| code_block=$( cat <<-EOD | ||
| ${code_block} | ||
|
|
@@ -295,11 +281,6 @@ EOD | |
| ) | ||
| # Write site configuration to Apache. | ||
| echo "$code_block" | $SUDO tee "$apache_site_config" > /dev/null | ||
| # Configure permissions for /.cgi-bin/ and SuExec. | ||
| $SUDO chown -R "$apache_site_user":"$apache_site_group" "$cgi_system_path" | ||
| # Update SuExec to accept the new document root for this website. | ||
| grep "$apache_site_path" '/etc/apache2/suexec/www-data' > /dev/null || \ | ||
| ( $SUDO sed -e '1s#^#'"$apache_site_path""\n"'#' -i '/etc/apache2/suexec/www-data' > /dev/null ) | ||
| } | ||
|
|
||
| # Restart the Apache server and reload with new configuration. | ||
|
|
@@ -396,18 +377,23 @@ ${code_block} | |
|
|
||
| # Pass PHP scripts to PHP-FPM. | ||
| location ~ \.php\$ { | ||
| fastcgi_pass unix:/var/run/php5-fpm.sock; | ||
| fastcgi_index index.php; | ||
| include fastcgi_params; | ||
| fastcgi_index index.php; | ||
| fastcgi_split_path_info ^(.+\.php)(/.+)\$; | ||
| fastcgi_param PATH_INFO \$fastcgi_path_info; | ||
| fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info; | ||
| fastcgi_param HTTP_AUTHORIZATION \$http_authorization; | ||
| fastcgi_pass unix:/var/run/php5-fpm-${nginx_site_name}.sock; | ||
| } | ||
| EOD | ||
| ) | ||
| # Run PHP-FPM as the selected user and group. | ||
| $SUDO sed \ | ||
| -e 's#^\(\[[A-Za-z0-9-]\+\]\)$#['"$nginx_site_name"']#g' \ | ||
| -e 's#^\(user\)\s*=\s*[A-Za-z0-9-]\+#\1 = '"$nginx_site_user"'#g' \ | ||
| -e 's#^\(group\)\s*=\s*[A-Za-z0-9-]\+#\1 = '"$nginx_site_group"'#g' \ | ||
| -i '/etc/php5/fpm/pool.d/www.conf' | ||
| -e 's#^\(listen\)\s*=\s*.\+$#\1 = '/var/run/php5-fpm-"$nginx_site_name"'.sock#g' \ | ||
| <'/etc/php5/fpm/pool.d/www.conf' >'/etc/php5/fpm/pool.d/'"$nginx_site_name"'.conf' | ||
| fi | ||
| code_block=$( cat <<-EOD | ||
| ${code_block} | ||
|
|
@@ -460,6 +446,11 @@ php-pecl-install() { | |
| done | ||
| } | ||
|
|
||
| # Restart the php5-fpm server and reload with new configuration. | ||
| php5-fpm-restart() { | ||
| system-service php5-fpm restart | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 3458e89 as |
||
|
|
||
| # }}} | ||
|
|
||
| # {{{ MySQL | ||
|
|
@@ -470,6 +461,20 @@ mysql-database-create() { | |
| mysql -u root -e "CREATE DATABASE IF NOT EXISTS \`$1\` CHARACTER SET ${2:-utf8} COLLATE '${3:-utf8_general_ci}'" | ||
| } | ||
|
|
||
| # Grant access to database (creates user if not exist) | ||
| # mysql-database-add-user databasename username password fromhost | ||
| mysql-database-add-user() { | ||
| log-operation "$FUNCNAME" "$@" | ||
| mysql -u root -e "GRANT ALL PRIVILEGES ON \`$1\`.* TO '$2'@'${4:-localhost}' IDENTIFIED BY '$3' WITH GRANT OPTION; FLUSH PRIVILEGES;" | ||
| } | ||
|
|
||
| # Load data from SQL file | ||
| # mysql-load-data databasename sqlfile | ||
| mysql-load-data() { | ||
| log-operation "$FUNCNAME" "$@" | ||
| mysql -u root "$1" < "$2" | ||
| } | ||
|
|
||
| # Restore a MySQL database from an archived backup. | ||
| mysql-database-restore() { | ||
| log-operation "$FUNCNAME" "$@" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already available as
system-upgradewhich I've tweaked in e879932. Be careful as it's known to break VirtualBox Guest Additions when a new kernel is installed and the DKMS module is not re-compiled. dotless-de/vagrant-vbguest is good at handling this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually like having both, since you may want to perform a system upgrade, but not a dist upgrade, or maybe indeed a full dist upgrade. Not necessarily as relevant to vagrant (since you could just change your VagrantFile to reference a newer dist image), but relevant within the scope of general server administration if this script were used while managing non-vagrant boxes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, however I don't intend for this script to be used for server administration. A full distribution upgrade would also likely involve prompts/dialogs so running non-interactive is going to break the system.