1
0
Fork 0

PHP check lists all PHP modules + linted

This commit is contained in:
Shlee 2022-06-25 12:03:00 +09:30 committed by GitHub
parent 13a86ab2b5
commit e0307babf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 92 additions and 104 deletions

View File

@ -66,10 +66,9 @@ class Installer extends Command
$this->envCreate(); $this->envCreate();
$this->installType(); $this->installType();
if($this->installType === 'Advanced') { if ($this->installType === 'Advanced') {
$this->info('Installer: Advanced...'); $this->info('Installer: Advanced...');
$this->checkPHPRequiredDependencies(); $this->checkPHPRequiredDependencies();
$this->checkPHPOptionalDependencies();
$this->checkFFmpegDependencies(); $this->checkFFmpegDependencies();
$this->checkOptimiseDependencies(); $this->checkOptimiseDependencies();
$this->checkDiskPermissions(); $this->checkDiskPermissions();
@ -101,9 +100,9 @@ class Installer extends Command
protected function envCheck() protected function envCheck()
{ {
if( file_exists(base_path('.env')) && if (file_exists(base_path('.env')) &&
filesize(base_path('.env')) !== 0 && filesize(base_path('.env')) !== 0 &&
!$this->option('dangerously-overwrite-env') !$this->option('dangerously-overwrite-env')
) { ) {
$this->line(''); $this->line('');
$this->error('Existing .env File Found - Installation Aborted'); $this->error('Existing .env File Found - Installation Aborted');
@ -117,7 +116,7 @@ class Installer extends Command
{ {
$this->line(''); $this->line('');
$this->info('Creating .env if required'); $this->info('Creating .env if required');
if(!file_exists(app()->environmentFilePath())) { if (!file_exists(app()->environmentFilePath())) {
exec('cp .env.example .env'); exec('cp .env.example .env');
} }
} }
@ -125,7 +124,7 @@ class Installer extends Command
protected function installType() protected function installType()
{ {
$type = $this->choice('Select installation type', ['Simple', 'Advanced'], 1); $type = $this->choice('Select installation type', ['Simple', 'Advanced'], 1);
$this->installType = $type; $this->installType = $type;
} }
protected function checkPHPRequiredDependencies() protected function checkPHPRequiredDependencies()
@ -140,23 +139,6 @@ class Installer extends Command
'json', 'json',
'mbstring', 'mbstring',
'openssl', 'openssl',
];
foreach($extensions as $ext) {
if(extension_loaded($ext) == false) {
$this->error("- \"{$ext}\" Required PHP Extension not found, aborting installation");
exit;
}
}
$this->info("- Required PHP extensions found!");
}
protected function checkPHPOptionalDependencies()
{
$this->line(' ');
$this->info('Checking For Optional PHP Extensions...');
$extensions = [
'gd', 'gd',
'intl', 'intl',
'xml', 'xml',
@ -164,22 +146,29 @@ class Installer extends Command
'redis', 'redis',
]; ];
foreach($extensions as $ext) { foreach ($extensions as $ext) {
if(extension_loaded($ext) == false) { if (extension_loaded($ext) == false) {
$this->error("- \"{$ext}\" PHP extension not found"); $this->error("- \"{$ext}\" PHP extension not found");
} else { } else {
$this->info ("- \"{$ext}\" PHP extension found"); $this->info("- \"{$ext}\" PHP extension found");
} }
} }
}
$continue = $this->choice('Do you wish to continue?', ['no', 'yes'], 0);
if ($this->continue === 'no') {
$this->info('Exiting Installer.');
exit;
}
}
protected function checkFFmpegDependencies() protected function checkFFmpegDependencies()
{ {
$this->line(' '); $this->line(' ');
$this->info('Checking for Required FFmpeg dependencies...'); $this->info('Checking for Required FFmpeg dependencies...');
$ffmpeg = exec('which ffmpeg'); $ffmpeg = exec('which ffmpeg');
if(empty($ffmpeg)) { if (empty($ffmpeg)) {
$this->error("- \"{$ext}\" FFmpeg not found, aborting installation"); $this->error("- \"{$ext}\" FFmpeg not found, aborting installation");
exit; exit;
} else { } else {
@ -191,7 +180,7 @@ class Installer extends Command
{ {
$this->line(' '); $this->line(' ');
$this->info('Checking for Optional Media Optimisation dependencies...'); $this->info('Checking for Optional Media Optimisation dependencies...');
$dependencies = [ $dependencies = [
'jpegoptim', 'jpegoptim',
'optipng', 'optipng',
@ -199,12 +188,12 @@ class Installer extends Command
'gifsicle', 'gifsicle',
]; ];
foreach($dependencies as $dep) { foreach ($dependencies as $dep) {
$which = exec("which $dep"); $which = exec("which $dep");
if(empty($which)) { if (empty($which)) {
$this->error("- \"{$dep}\" not found"); $this->error("- \"{$dep}\" not found");
} else { } else {
$this->info ("- \"{$dep}\" found"); $this->info("- \"{$dep}\" found");
} }
} }
} }
@ -217,11 +206,11 @@ class Installer extends Command
$paths = [ $paths = [
base_path('bootstrap'), base_path('bootstrap'),
base_path('storage') base_path('storage'),
]; ];
foreach($paths as $path) { foreach ($paths as $path) {
if(is_writeable($path) == false) { if (is_writeable($path) == false) {
$this->error("- Invalid permission found! Aborting installation."); $this->error("- Invalid permission found! Aborting installation.");
$this->error(" Please make the following path writeable by the web server:"); $this->error(" Please make the following path writeable by the web server:");
$this->error(" $path"); $this->error(" $path");
@ -236,12 +225,12 @@ class Installer extends Command
{ {
$this->line(''); $this->line('');
$this->info('Enabling production'); $this->info('Enabling production');
$this->updateEnvFile('APP_ENV', 'production'); $this->updateEnvFile('APP_ENV', 'production');
$this->updateEnvFile('APP_DEBUG', 'false'); $this->updateEnvFile('APP_DEBUG', 'false');
$this->call('key:generate', ['--force' => true]); $this->call('key:generate', ['--force' => true]);
} }
protected function instanceDB() protected function instanceDB()
{ {
$this->line(''); $this->line('');
@ -265,10 +254,10 @@ class Installer extends Command
$this->info('Testing Database...'); $this->info('Testing Database...');
$dsn = "{$database}:dbname={$database_db};host={$database_host};port={$database_port};"; $dsn = "{$database}:dbname={$database_db};host={$database_host};port={$database_port};";
try { try {
$dbh = new PDO($dsn, $database_username, $database_password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $dbh = new PDO($dsn, $database_username, $database_password, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
} catch (\PDOException $e) { } catch (\PDOException $e) {
$this->error('Cannot connect to database, check your details and try again'); $this->error('Cannot connect to database, check your details and try again');
exit; exit;
} }
$this->info('- Connected to DB Successfully'); $this->info('- Connected to DB Successfully');
} }
@ -282,7 +271,6 @@ class Installer extends Command
$redis_password = $this->ask('Set redis password', 'null'); $redis_password = $this->ask('Set redis password', 'null');
$redis_port = $this->ask('Set redis port', 6379); $redis_port = $this->ask('Set redis port', 6379);
$this->updateEnvFile('REDIS_CLIENT', $redis_client); $this->updateEnvFile('REDIS_CLIENT', $redis_client);
$this->updateEnvFile('REDIS_SCHEME', 'tcp'); $this->updateEnvFile('REDIS_SCHEME', 'tcp');
$this->updateEnvFile('REDIS_HOST', $redis_host); $this->updateEnvFile('REDIS_HOST', $redis_host);
@ -291,12 +279,12 @@ class Installer extends Command
$this->info('Testing Redis...'); $this->info('Testing Redis...');
$redis = Redis::connection(); $redis = Redis::connection();
if($redis->ping()) { if ($redis->ping()) {
$this->info('- Connected to Redis Successfully!'); $this->info('- Connected to Redis Successfully!');
} else { } else {
$this->error('Cannot connect to Redis, check your details and try again'); $this->error('Cannot connect to Redis, check your details and try again');
exit; exit;
} }
} }
protected function instanceURL() protected function instanceURL()
@ -307,18 +295,18 @@ class Installer extends Command
$domain = $this->ask('Site Domain [ex: pixelfed.com]'); $domain = $this->ask('Site Domain [ex: pixelfed.com]');
$domain = strtolower($domain); $domain = strtolower($domain);
if(empty($domain)) { if (empty($domain)) {
$this->error('You must set the site domain'); $this->error('You must set the site domain');
exit; exit;
} }
if(starts_with($domain, 'http')) { if (starts_with($domain, 'http')) {
$this->error('The site domain cannot start with https://, you must use the FQDN (eg: example.org)'); $this->error('The site domain cannot start with https://, you must use the FQDN (eg: example.org)');
exit; exit;
} }
if(strpos($domain, '.') == false) { if (strpos($domain, '.') == false) {
$this->error('You must enter a valid site domain'); $this->error('You must enter a valid site domain');
exit; exit;
} }
$this->updateEnvFile('APP_NAME', $name); $this->updateEnvFile('APP_NAME', $name);
$this->updateEnvFile('APP_URL', 'https://' . $domain); $this->updateEnvFile('APP_URL', 'https://' . $domain);
@ -331,7 +319,7 @@ class Installer extends Command
{ {
$this->line(''); $this->line('');
$this->info('Laravel Settings (Defaults are recommended):'); $this->info('Laravel Settings (Defaults are recommended):');
$session = $this->choice('Select session driver', ["database", "file", "cookie", "redis", "memcached", "array"], 0); $session = $this->choice('Select session driver', ["database", "file", "cookie", "redis", "memcached", "array"], 0);
$cache = $this->choice('Select cache driver', ["redis", "apc", "array", "database", "file", "memcached"], 0); $cache = $this->choice('Select cache driver', ["redis", "apc", "array", "database", "file", "memcached"], 0);
$queue = $this->choice('Select queue driver', ["redis", "database", "sync", "beanstalkd", "sqs", "null"], 0); $queue = $this->choice('Select queue driver', ["redis", "database", "sync", "beanstalkd", "sqs", "null"], 0);
$broadcast = $this->choice('Select broadcast driver', ["log", "redis", "pusher", "null"], 0); $broadcast = $this->choice('Select broadcast driver', ["log", "redis", "pusher", "null"], 0);
@ -345,7 +333,7 @@ class Installer extends Command
$this->updateEnvFile('LOG_CHANNEL', $log); $this->updateEnvFile('LOG_CHANNEL', $log);
$this->updateEnvFile('HORIZON_PREFIX', $horizon); $this->updateEnvFile('HORIZON_PREFIX', $horizon);
} }
protected function instanceSettings() protected function instanceSettings()
{ {
$this->line(''); $this->line('');
@ -363,11 +351,11 @@ class Installer extends Command
} }
protected function activityPubSettings() protected function activityPubSettings()
{ {
$this->line(''); $this->line('');
$this->info('Federation Settings:'); $this->info('Federation Settings:');
$activitypub_federation = $this->choice('Enable ActivityPub federation?', ['false', 'true'], 1); $activitypub_federation = $this->choice('Enable ActivityPub federation?', ['false', 'true'], 1);
$this->updateEnvFile('ACTIVITY_PUB', $activitypub_federation); $this->updateEnvFile('ACTIVITY_PUB', $activitypub_federation);
$this->updateEnvFile('AP_REMOTE_FOLLOW', $activitypub_federation); $this->updateEnvFile('AP_REMOTE_FOLLOW', $activitypub_federation);
$this->updateEnvFile('AP_INBOX', $activitypub_federation); $this->updateEnvFile('AP_INBOX', $activitypub_federation);
@ -376,38 +364,38 @@ class Installer extends Command
} }
protected function mediaSettings() protected function mediaSettings()
{ {
$this->line(''); $this->line('');
$this->info('Media Settings:'); $this->info('Media Settings:');
$optimize_media = $this->choice('Optimize media uploads? Requires jpegoptim and other dependencies!', ['false', 'true'], 1); $optimize_media = $this->choice('Optimize media uploads? Requires jpegoptim and other dependencies!', ['false', 'true'], 1);
$image_quality = $this->ask('Set image optimization quality between 1-100. Default is 80%, lower values use less disk space at the expense of image quality.', '80'); $image_quality = $this->ask('Set image optimization quality between 1-100. Default is 80%, lower values use less disk space at the expense of image quality.', '80');
if($image_quality < 1) { if ($image_quality < 1) {
$this->error('Min image quality is 1. You should avoid such a low value, 60 at minimum is recommended.'); $this->error('Min image quality is 1. You should avoid such a low value, 60 at minimum is recommended.');
exit; exit;
} }
if($image_quality > 100) { if ($image_quality > 100) {
$this->error('Max image quality is 100'); $this->error('Max image quality is 100');
exit; exit;
} }
$this->info('Note: Max photo size cannot exceed `post_max_size` in php.ini.'); $this->info('Note: Max photo size cannot exceed `post_max_size` in php.ini.');
$max_photo_size = $this->ask('Max photo upload size in kilobytes. Default 15000 which is equal to 15MB', '15000'); $max_photo_size = $this->ask('Max photo upload size in kilobytes. Default 15000 which is equal to 15MB', '15000');
$max_caption_length = $this->ask('Max caption limit. Default to 500, max 5000.', '500'); $max_caption_length = $this->ask('Max caption limit. Default to 500, max 5000.', '500');
if($max_caption_length > 5000) { if ($max_caption_length > 5000) {
$this->error('Max caption length is 5000 characters.'); $this->error('Max caption length is 5000 characters.');
exit; exit;
} }
$max_album_length = $this->ask('Max photos allowed per album. Choose a value between 1 and 10.', '4'); $max_album_length = $this->ask('Max photos allowed per album. Choose a value between 1 and 10.', '4');
if($max_album_length < 1) { if ($max_album_length < 1) {
$this->error('Min album length is 1 photos per album.'); $this->error('Min album length is 1 photos per album.');
exit; exit;
} }
if($max_album_length > 10) { if ($max_album_length > 10) {
$this->error('Max album length is 10 photos per album.'); $this->error('Max album length is 10 photos per album.');
exit; exit;
} }
$this->updateEnvFile('PF_OPTIMIZE_IMAGES', $optimize_media); $this->updateEnvFile('PF_OPTIMIZE_IMAGES', $optimize_media);
$this->updateEnvFile('IMAGE_QUALITY', $image_quality); $this->updateEnvFile('IMAGE_QUALITY', $image_quality);
$this->updateEnvFile('MAX_PHOTO_SIZE', $max_photo_size); $this->updateEnvFile('MAX_PHOTO_SIZE', $max_photo_size);
@ -421,11 +409,11 @@ class Installer extends Command
$this->info('Note: We recommend running database migrations now!'); $this->info('Note: We recommend running database migrations now!');
$confirm = $this->choice('Do you want to run the database migrations?', ['Yes', 'No'], 0); $confirm = $this->choice('Do you want to run the database migrations?', ['Yes', 'No'], 0);
if($confirm === 'Yes') { if ($confirm === 'Yes') {
sleep(3); sleep(3);
$this->line(''); $this->line('');
$this->info('Migrating DB:'); $this->info('Migrating DB:');
$this->call('migrate', ['--force' => true]); $this->call('migrate', ['--force' => true]);
$this->line(''); $this->line('');
$this->info('Importing Cities:'); $this->info('Importing Cities:');
$this->call('import:cities'); $this->call('import:cities');
@ -437,12 +425,12 @@ class Installer extends Command
$this->call('passport:keys', ['--force' => true]); $this->call('passport:keys', ['--force' => true]);
$confirm = $this->choice('Do you want to create an admin account?', ['Yes', 'No'], 0); $confirm = $this->choice('Do you want to create an admin account?', ['Yes', 'No'], 0);
if($confirm === 'Yes') { if ($confirm === 'Yes') {
$this->call('user:create'); $this->call('user:create');
} }
} }
} }
protected function resetArtisanCache() protected function resetArtisanCache()
{ {
$this->call('config:cache'); $this->call('config:cache');
@ -458,8 +446,8 @@ class Installer extends Command
} }
##### #####
# Installer Functions # Installer Functions
##### #####
protected function checkEnvKeys($key, $error) protected function checkEnvKeys($key, $error)
{ {
@ -467,7 +455,7 @@ class Installer extends Command
$payload = file_get_contents($envPath); $payload = file_get_contents($envPath);
if ($existing = $this->existingEnv($key, $payload)) { if ($existing = $this->existingEnv($key, $payload)) {
} else { } else {
$this->info("$key empty - $error"); $this->info("$key empty - $error");
} }
} }
@ -502,14 +490,14 @@ class Installer extends Command
fclose($file); fclose($file);
} }
protected function parseSize($size) { protected function parseSize($size)
{
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size); $unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
$size = preg_replace('/[^0-9\.]/', '', $size); $size = preg_replace('/[^0-9\.]/', '', $size);
if ($unit) { if ($unit) {
return round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); return round($size * pow(1024, stripos('bkmgtpezy', $unit[0])));
} } else {
else { return round($size);
return round($size);
} }
} }
} }