Skip to content

Instantly share code, notes, and snippets.

@lex111
Last active October 11, 2016 10:27
Show Gist options
  • Save lex111/51b192bc40c8b5ca7896101cbe41d005 to your computer and use it in GitHub Desktop.
Save lex111/51b192bc40c8b5ca7896101cbe41d005 to your computer and use it in GitHub Desktop.
Setup LAMP on Ubuntu 16 with dynamic virtual hosts (PHP 5.6)
#!/bin/bash
sudo apt-get install curl wget vim unzip tasksel
sudo tasksel install lamp-server
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt install php5.6 libapache2-mod-php5.6 \
php5.6-intl php5.6-mysql php5.6-sqlite3 php5.6-xsl \
php5.6-curl php5.6-gd php5.6-json php5.6-readline php5.6-zip \
php5.6-bz2 php5.6-ldap php5.6-opcache php5.6-mbstring \
php5.6-xml php5.6-cli php5.6-mcrypt php5.6-soap \
php5.6-xmlrpc php-xdebug
sudo apt-get install libapache2-mpm-itk
sudo a2enmod vhost_alias
sudo a2enmod rewrite
a2dismod php7.0
a2enmod php5.6
sudo service apache2 restart
mkdir ~/workspace/vhosts/{utf8,cp1251,logs}
sudo tee -a /etc/apache2/sites-available/workspace.conf << EOF
<VirtualHost *:80>
ServerName workspace
ServerAlias *.dev
AssignUserID programmer programmer
VirtualDocumentRoot /home/programmer/workspace/vhosts/%2/%1/www
LogFormat "%v %l %u %t \"%r\" %>s %b" comonvhost
CustomLog /home/programmer/workspace/vhosts/logs/access_log comonvhost
ErrorLog /home/programmer/workspace/vhosts/logs/error_log
<Directory /home/programmer/workspace/vhosts/>
AllowOverride all
Require all granted
</Directory>
<Directory /home/programmer/workspace/vhosts/utf8>
php_admin_value mbstring.func_overload 2
php_admin_value mbstring.internal_encoding utf-8
</Directory>
<Directory /home/programmer/workspace/vhosts/cp1251>
php_admin_value mbstring.func_overload 0
</Directory>
</VirtualHost>
EOF
sudo a2ensite workspace
sudo apt-get install dnsmasq
mv /etc/dnsmasq.conf /etc/dnsmasq.conf.origin
cat << EOF | sudo tee -a /etc/dnsmasq.conf
address=/.dev/127.0.0.1
listen-address=127.0.0.1
EOF
sudo /etc/init.d/dnsmasq restart
cat << EOF | sudo tee -a /etc/php/5.6/mods-available/bitrix.ini
[PHP]
realpath_cache_size=4096K
magic_quotes_gpc=0
max_input_vars=10000
memory_limit=512M
upload_max_filesize=64M
post_max_size=64M
short_open_tag=On
opcache.revalidate_freq=0
display_errors=On
pcre.recursion_limit = 1000
[Date]
date.timezone = 'Europe/Moscow'
EOF
sudo ln -s /etc/php/5.6/mods-available/bitrix.ini /etc/php/5.6/apache2/conf.d/20-bitrix.ini
cat << EOF | sudo tee -a /etc/php/5.6/mods-available/xdebug.ini
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=0
xdebug.remote_host=localhost
xdebug.remote_handler=dbgp
EOF
cat << EOF | sudo tee -a /etc/mysql/conf.d/bitrix.cnf
[mysqld]
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
transaction-isolation = READ-COMMITTED
query_cache_size = 128M
query_cache_limit = 2M
sort_buffer_size = 10M
read_rnd_buffer_size = 10M
table_open_cache = 512
innodb_buffer_pool_size = 512M
innodb_buffer_pool_instances = 2
tmp_table_size = 1024M
max_heap_table_size = 1024M
max-connect-errors = 10000
table_definition_cache = 2048
thread_cache_size = 4
sql_mode=
EOF
sudo service mysql restart
sudo apt-get install postfix
# Check vhost (optional, for Bitrix CMS)
mkdir -p ~/workspace/vhosts/utf8/bitrix_test/www/ && cd "$_"
wget http://dev.1c-bitrix.ru/download/scripts/bitrix_server_test.php
wget http://www.1c-bitrix.ru/download/scripts/bitrixsetup.php
echo "Check the settings http://bitrix_test.utf8.dev/bitrix_server_test.php";
echo "And try to install Bitrix http://bitrix_test.utf8.dev/bitrixsetup.php"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment