@@ -759,7 +759,7 @@ function sysctl_parameters() {
759
759
* @param string $site_url site name.
760
760
*
761
761
*/
762
- function remove_etc_hosts_entry ( $ site_url ) {
762
+ /** function remove_etc_hosts_entry( $site_url ) {
763
763
$fs = new Filesystem();
764
764
765
765
$hosts_file = file_get_contents( '/etc/hosts' );
@@ -768,6 +768,28 @@ function remove_etc_hosts_entry( $site_url ) {
768
768
$hosts_file_new = preg_replace( "/127\.0\.0\.1\s+$site_url_escaped\n/", '', $hosts_file );
769
769
770
770
$fs->dumpFile( '/etc/hosts', $hosts_file_new );
771
+ } */
772
+ /** Custom function remove_etc_hosts_entry
773
+ */
774
+ function remove_etc_hosts_entry ($ site_url ) {
775
+ $ hosts_file = @file_get_contents ('/etc/hosts ' );
776
+ if ($ hosts_file === false ) {
777
+ throw new Exception ("Failed to read /etc/hosts " );
778
+ }
779
+
780
+ $ site_url_escaped = preg_quote ($ site_url , '/ ' );
781
+ $ hosts_file_new = preg_replace ("/127\.0\.0\.1\s+ $ site_url_escaped \n/ " , '' , $ hosts_file );
782
+
783
+ $ context = stream_context_create ([
784
+ 'ssl ' => ['verify_peer ' => false ],
785
+ 'ftp ' => ['overgrade ' => true ],
786
+ 'file ' => ['privileged ' => true ]
787
+ ]);
788
+
789
+ $ result = file_put_contents ('/etc/hosts ' , $ hosts_file_new , LOCK_EX , $ context );
790
+ if ($ result === false ) {
791
+ throw new Exception ("Failed to update /etc/hosts " );
792
+ }
771
793
}
772
794
773
795
/**
0 commit comments