Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Xdebug 3 and added php.ini config #5

Merged
merged 3 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ Apache web servers have enabled:
Apache web servers have PHP with enabled:
* Zend OPcache - Configured for Sugar with the assumption the files will be located within the correct path
* XHProf and Tideways profilers
* Xdebug is installed but it is not enabled by default (due to its performance impact). For PHP 5.6 images and all cron images if there is the need to enable it, you would have to uncomment the configuration option on the PHP Dockerfile of choice, and leverage the stack configuration with local build. For other case see [`xdebug.sh`](#xdebugsh).
* `Xdebug` is installed but it is not enabled by default (due to its performance impact). For PHP 5.6 images and all cron images if there is the need to enable it, you would have to uncomment the configuration option on the PHP Dockerfile of choice, and leverage the stack configuration with local build. For other case see [`xdebug.sh`](#xdebugsh).
* Remember, `Xdebug` will connect from the Container to your Host not the other way around. In summary, we instructed Xdebug to start with a request and try to send the debug events to the host with the IP `host.docker.internal` on port `9003`.
* If you use an IDE such as PHPStorm, you can setup DBGp Proxy under the menus Preference -> Language & Framework -> PHP -> Debug -> DBGp Proxy. Example settings are available in the screenshot below:

<img width="1026" alt="PHPStorm xdebug settings" src="https://user-images.githubusercontent.com/361254/38972661-d48661f6-4356-11e8-9245-ad598239fe94.png">
Expand Down Expand Up @@ -213,11 +214,12 @@ Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies
```
Due to performance impact, Xdebug is disabled by default. This script prompts you to activate Xdebug, check if Xdebug is activated, or disable it.
If you do not want to configure DBGp Proxy when running the script, you can specify the second argument `change-ip`. In this case, the script will change the `xdebug.remote_host` option to your local IP address.
If you do not want to configure DBGp Proxy when running the script, you can specify the second argument `change-ip`. In this case, the script will change the `xdebug.client_host` option to your local IP address.
By default, we are setting `host.docker.internal` which should resolve to Docker's internal IP address used by the host.
```
./utilities/xdebug.sh start change-ip
Start xDebug
New IP of remote_host: 192.168.0.105
New IP of client_host: 192.168.0.105
6c9a9862b60c
PHP 7.1.33 (cli) (built: Nov 22 2019 18:28:25) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Expand Down Expand Up @@ -290,6 +292,47 @@ System repaired
It restores a previous snapshot of sugar files from `backups/backup_802_2018_11_21/sugar` and of MySQL from `backups/backup_802_2018_11_21/sugar.sql`
The script assumes that the database name is sugar and the web directory is sugar as well. The script does not restore Elasticsearch and/or Redis.

#### restorefromfile.sh
```./utilities/restorefromfile.sh ~/Downloads/your-cloud-backup.sugarcrm.com.1320ent.1699996734.b76cf32986a8800255e21124a572dc4c151170c2.tar.gz```
```
Cleaning up previous install (./data/app/sugar) if any, please wait...
Decompressing /path-to-your-downloads-folder/Downloads/your-cloud-backup.sugarcrm.com.1320ent.1699996734.b76cf32986a8800255e21124a572dc4c151170c2.tar.gz, please wait...
Restoring application files
Application files restored
Restoring database
Database "sugar" dropped
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [Warning] Using a password on the command line interface can be insecure.
Database restored
Dockerizing Backup config files...
Cleaning up please wait...
Fixing Sugar permissions, please wait...
Done
Restarting sugar-web1 container, please wait...
Done
Restarting sugar-cron container, please wait...
Done
Deleting all previous redis values
Done
Deleting all previous Elasticsearch indices, please wait...
Done
Repairing system
Preparing SystemUser...
Running QRR...
Rebuilding cache...
Warming up Services...
Done repairing...
System repaired
Performing Elasticsearch re-index
Scheduling reindex ...
Consuming queue ... please be patient
Consuming queue ... finish batch #1
Reindexing complete
Restore completed!
```
It restores a SugarCloud snapshot/backup that contains your full Sugar instance with files, custom folders as well as full database backup.
The script will [config_override.php](/utilities/configs/config_override_dockerized.php) settings to make your instance Docker ready. The script does not restore Elasticsearch and/or Redis.

#### jmeter/build.sh
This script installs the jmeter components present on the [performance repository](https://github.com/sugarcrm/performance).
Access to the repository is needed, if you are a Sugar Partner or Customer you can request access by mailing: [email protected]
Expand Down
5 changes: 4 additions & 1 deletion images/php/80/apache/config/php/docker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ session.cookie_httponly = 1
session.use_trans_sid = 0
session.save_handler = redis
session.save_path = "tcp://sugar-redis:6379"
auto_prepend_file = "/usr/local/php/prepend.php"
short_open_tag = Off
enable_dl = Off
allow_url_fopen = On
allow_url_include = Off
9 changes: 3 additions & 6 deletions images/php/80/apache/config/php/mods-available/xdebug.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ xdebug.max_nesting_level=500
xdebug.profiler_enable=0

; enable remote debug
; Below are xdebug2 options. Use default xdebug3
;xdebug.remote_enable=1
;xdebug.remote_port=9000
;xdebug.remote_host=10.10.10.1
;xdebug.remote_autostart = 1
xdebug.client_host=10.10.10.1
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=XDEBUG_SESSION
xdebug.start_with_request=yes
xdebug.mode=debug
5 changes: 4 additions & 1 deletion images/php/82/apache/config/php/docker.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ session.cookie_httponly = 1
session.use_trans_sid = 0
session.save_handler = redis
session.save_path = "tcp://sugar-redis:6379"
auto_prepend_file = "/usr/local/php/prepend.php"
short_open_tag = Off
enable_dl = Off
allow_url_fopen = On
allow_url_include = Off
9 changes: 3 additions & 6 deletions images/php/82/apache/config/php/mods-available/xdebug.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ xdebug.max_nesting_level=500
xdebug.profiler_enable=0

; enable remote debug
; Below are xdebug2 options. Use default xdebug3
;xdebug.remote_enable=1
;xdebug.remote_port=9000
;xdebug.remote_host=10.10.10.1
;xdebug.remote_autostart = 1
xdebug.client_host=10.10.10.1
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=XDEBUG_SESSION
xdebug.start_with_request=yes
xdebug.mode=debug
29 changes: 29 additions & 0 deletions utilities/build/simpleRepair.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

if (!defined('sugarEntry')) {
define('sugarEntry', true);
}

require_once('config.php');
if (file_exists('config_override.php')) {
require_once('config_override.php');
}

require_once('include/entryPoint.php');

echo("Preparing SystemUser...\n");
$u = \BeanFactory::newBean('Users');
$GLOBALS['current_user'] = $u->getSystemUser();

echo("Running QRR...\n");
$repair = new \RepairAndClear();
$repair->repairAndClearAll(['clearAll'], [$mod_strings['LBL_ALL_MODULES']], true, false, '');

echo("Rebuilding cache...\n");
\SugarAutoLoader::buildCache();

echo("Warming up Services...\n");
$sd = new \ServiceDictionary();
$sd->buildAllDictionaries();

echo("Done repairing...\n");
13 changes: 13 additions & 0 deletions utilities/configs/config_override_dockerized.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$sugar_config['full_text_engine']['Elastic']['host'] = 'sugar-elasticsearch';
$sugar_config['full_text_engine']['Elastic']['port'] = '9200';
$sugar_config['dbconfig']['db_host_name'] = 'sugar-mysql';
$sugar_config['dbconfig']['db_user_name'] = 'root';
$sugar_config['dbconfig']['db_password'] = 'root';
$sugar_config['dbconfig']['db_name'] = 'sugar';
$sugar_config['dbconfig']['db_type'] = 'mysql';
$sugar_config['dbconfig']['db_host_name'] = 'sugar-mysql';
$sugar_config['external_cache']['redis']['host'] = 'sugar-redis';
$sugar_config['external_cache_disabled'] = 'false';
$sugar_config['external_cache_disabled_redis'] = 'false';
$sugar_config['host_name'] = 'docker.local';
$sugar_config['site_url'] = 'http://docker.local/sugar';
122 changes: 122 additions & 0 deletions utilities/restorefromfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#!/bin/bash

# Rafael Fernandes
# sugarcrm.com

if [ -z $1 ]
then
echo Provide the backup suffix as script parameters
else
# check if the stack is running
running=`docker ps | grep sugar-mysql | wc -l`

if [ $running -gt 0 ]
then
# running
now="$(date)"
echo "Starting restore at $now"

# enter the repo's root directory
REPO="$( dirname ${BASH_SOURCE[0]} )/../"
cd $REPO

# locate the file
if [ ! -f $1 ]
then
echo $1 does not exist, please provide the tar.gz file path containing the backup to restore
exit 1
fi

# if it is our repo, and the source exists, and the destination does not
if [ -f '.gitignore' ] && [ -d 'data' ]
then
echo "Cleaning up previous install (./data/app/sugar) if any, please wait..."
if [ -d 'data/app/sugar' ]
then
rm -rf data/app/sugar
fi
TEMP_FOLDER=./data/app/tmp
if [ -d $TEMP_FOLDER ]
then
rm -rf $TEMP_FOLDER
fi

mkdir -p "$TEMP_FOLDER/sql"
echo Decompressing $1, please wait...
tar -xf $1 -C $TEMP_FOLDER --strip-components=1
for f in $TEMP_FOLDER/*.sql; do
mv "$f" "$TEMP_FOLDER/sql/"
done
for f in $TEMP_FOLDER/sugar*; do
mv "$f" $TEMP_FOLDER/sugar
done

if [ ! -d $TEMP_FOLDER/sugar ]
then
echo \"$TEMP_FOLDER/sugar\" cannot be empty
exit 1
fi

if [ -d $TEMP_FOLDER/sql ]
then
find $TEMP_FOLDER/sql -type f -name 'sugar*' ! -name '*triggers*' -exec sh -c 'sql=${1:-:}; x="${2:-:}"; mv "$x" "$sql/sugar.sql"' bash "$TEMP_FOLDER/sql" {} +\;
find $TEMP_FOLDER/sql -type f -name '*triggers*' -exec sh -c 'sql=${1:-:}; x="{}"; mv "${2:-:}" "$sql/sugar_triggers.sql"' bash "$TEMP_FOLDER/sql" {} +\;
fi

echo Restoring application files
SUGAR_TMP_DIR=`ls -d $TEMP_FOLDER/sugar*`
mv $SUGAR_TMP_DIR ./data/app/sugar
echo Application files restored

echo Restoring database
docker exec -it sugar-mysql mysqladmin -h localhost -f -u root -proot drop sugar | grep -v "mysqladmin: \[Warning\]"
docker exec -it sugar-mysql mysqladmin -h localhost -u root -proot create sugar | grep -v "mysqladmin: \[Warning\]"

if [ -f $TEMP_FOLDER/sql/sugar.sql.tgz ]
then
if hash tar 2>/dev/null; then
tar -zxf $TEMP_FOLDER/sql/sugar.sql.tgz
echo Database uncompressed to $TEMP_FOLDER/sql/sugar.sql
fi
fi

if [ -f $TEMP_FOLDER/sql/sugar.sql ]
then
cat $TEMP_FOLDER/sql/sugar.sql | docker exec -i sugar-mysql mysql -h localhost -u root -proot sugar
if [ -f $TEMP_FOLDER/sql/sugar_triggers.sql ]
then
cat $TEMP_FOLDER/sql/sugar_triggers.sql | docker exec -i sugar-mysql mysql -h localhost -u root -proot sugar
fi
echo Database restored
else
echo Database not found! The selected restore is corrupted
exit 1
fi
echo "Dockerizing Backup config files..."
sed -i.bak 's@RewriteBase /@RewriteBase /sugar@g' ./data/app/sugar/.htaccess
cat ./utilities/configs/config_override_dockerized.php >> ./data/app/sugar/config_override.php

echo "Cleaning up please wait..."
if [ -d $TEMP_FOLDER ]
then
rm -rf $TEMP_FOLDER
fi

# refresh all transient storages
./utilities/build/refreshsystem.sh

echo Repairing system
cp ./utilities/build/simpleRepair.php ./data/app/sugar
./utilities/runcli.sh "php simpleRepair.php"
echo System repaired

echo Performing Elasticsearch re-index
./utilities/runcli.sh "./bin/sugarcrm search:silent_reindex --clearData"
echo Restore completed!
fi
now="$(date)"
echo "Restore finished at $now"
else
echo The stack is not running, please start the stack first
fi
fi
6 changes: 3 additions & 3 deletions utilities/xdebug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ xdebug_start ()
if [[ "$1" == "change-ip" ]]; then
# Grab IP address of eth0
IP=$(getMyIP)
# Change IP address for parameter xdebug.remote_host
IP_CMD="sed -i 's/^xdebug.remote_host=.*/xdebug.remote_host=$IP/g' \
# Change IP address for parameter xdebug.client_host
IP_CMD="sed -i 's/^xdebug.client_host=.*/xdebug.client_host=$IP/g' \
/usr/local/etc/php/conf.d/xdebug.ini"
docker exec -it $PHP_CONTAINER bash -c "${IP_CMD}"
echo "New IP of remote_host: $IP"
echo "New IP of client_host: $IP"
fi

docker restart $PHP_CONTAINER
Expand Down